11da177e4SLinus Torvalds #ifndef _LAPB_H 21da177e4SLinus Torvalds #define _LAPB_H 31da177e4SLinus Torvalds #include <linux/lapb.h> 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds #define LAPB_HEADER_LEN 20 /* LAPB over Ethernet + a bit more */ 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds #define LAPB_ACK_PENDING_CONDITION 0x01 81da177e4SLinus Torvalds #define LAPB_REJECT_CONDITION 0x02 91da177e4SLinus Torvalds #define LAPB_PEER_RX_BUSY_CONDITION 0x04 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds /* Control field templates */ 121da177e4SLinus Torvalds #define LAPB_I 0x00 /* Information frames */ 131da177e4SLinus Torvalds #define LAPB_S 0x01 /* Supervisory frames */ 141da177e4SLinus Torvalds #define LAPB_U 0x03 /* Unnumbered frames */ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #define LAPB_RR 0x01 /* Receiver ready */ 171da177e4SLinus Torvalds #define LAPB_RNR 0x05 /* Receiver not ready */ 181da177e4SLinus Torvalds #define LAPB_REJ 0x09 /* Reject */ 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds #define LAPB_SABM 0x2F /* Set Asynchronous Balanced Mode */ 211da177e4SLinus Torvalds #define LAPB_SABME 0x6F /* Set Asynchronous Balanced Mode Extended */ 221da177e4SLinus Torvalds #define LAPB_DISC 0x43 /* Disconnect */ 231da177e4SLinus Torvalds #define LAPB_DM 0x0F /* Disconnected mode */ 241da177e4SLinus Torvalds #define LAPB_UA 0x63 /* Unnumbered acknowledge */ 251da177e4SLinus Torvalds #define LAPB_FRMR 0x87 /* Frame reject */ 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds #define LAPB_ILLEGAL 0x100 /* Impossible to be a real frame type */ 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds #define LAPB_SPF 0x10 /* Poll/final bit for standard LAPB */ 301da177e4SLinus Torvalds #define LAPB_EPF 0x01 /* Poll/final bit for extended LAPB */ 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds #define LAPB_FRMR_W 0x01 /* Control field invalid */ 331da177e4SLinus Torvalds #define LAPB_FRMR_X 0x02 /* I field invalid */ 341da177e4SLinus Torvalds #define LAPB_FRMR_Y 0x04 /* I field too long */ 351da177e4SLinus Torvalds #define LAPB_FRMR_Z 0x08 /* Invalid N(R) */ 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds #define LAPB_POLLOFF 0 381da177e4SLinus Torvalds #define LAPB_POLLON 1 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds /* LAPB C-bit */ 411da177e4SLinus Torvalds #define LAPB_COMMAND 1 421da177e4SLinus Torvalds #define LAPB_RESPONSE 2 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds #define LAPB_ADDR_A 0x03 451da177e4SLinus Torvalds #define LAPB_ADDR_B 0x01 461da177e4SLinus Torvalds #define LAPB_ADDR_C 0x0F 471da177e4SLinus Torvalds #define LAPB_ADDR_D 0x07 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds /* Define Link State constants. */ 501da177e4SLinus Torvalds enum { 511da177e4SLinus Torvalds LAPB_STATE_0, /* Disconnected State */ 521da177e4SLinus Torvalds LAPB_STATE_1, /* Awaiting Connection State */ 531da177e4SLinus Torvalds LAPB_STATE_2, /* Awaiting Disconnection State */ 541da177e4SLinus Torvalds LAPB_STATE_3, /* Data Transfer State */ 551da177e4SLinus Torvalds LAPB_STATE_4 /* Frame Reject State */ 561da177e4SLinus Torvalds }; 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds #define LAPB_DEFAULT_MODE (LAPB_STANDARD | LAPB_SLP | LAPB_DTE) 591da177e4SLinus Torvalds #define LAPB_DEFAULT_WINDOW 7 /* Window=7 */ 601da177e4SLinus Torvalds #define LAPB_DEFAULT_T1 (5 * HZ) /* T1=5s */ 611da177e4SLinus Torvalds #define LAPB_DEFAULT_T2 (1 * HZ) /* T2=1s */ 621da177e4SLinus Torvalds #define LAPB_DEFAULT_N2 20 /* N2=20 */ 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #define LAPB_SMODULUS 8 651da177e4SLinus Torvalds #define LAPB_EMODULUS 128 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* 681da177e4SLinus Torvalds * Information about the current frame. 691da177e4SLinus Torvalds */ 701da177e4SLinus Torvalds struct lapb_frame { 711da177e4SLinus Torvalds unsigned short type; /* Parsed type */ 721da177e4SLinus Torvalds unsigned short nr, ns; /* N(R), N(S) */ 731da177e4SLinus Torvalds unsigned char cr; /* Command/Response */ 741da177e4SLinus Torvalds unsigned char pf; /* Poll/Final */ 751da177e4SLinus Torvalds unsigned char control[2]; /* Original control data*/ 761da177e4SLinus Torvalds }; 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /* 791da177e4SLinus Torvalds * The per LAPB connection control structure. 801da177e4SLinus Torvalds */ 811da177e4SLinus Torvalds struct lapb_cb { 821da177e4SLinus Torvalds struct list_head node; 831da177e4SLinus Torvalds struct net_device *dev; 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds /* Link status fields */ 861da177e4SLinus Torvalds unsigned int mode; 871da177e4SLinus Torvalds unsigned char state; 881da177e4SLinus Torvalds unsigned short vs, vr, va; 891da177e4SLinus Torvalds unsigned char condition; 901da177e4SLinus Torvalds unsigned short n2, n2count; 911da177e4SLinus Torvalds unsigned short t1, t2; 921da177e4SLinus Torvalds struct timer_list t1timer, t2timer; 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds /* Internal control information */ 951da177e4SLinus Torvalds struct sk_buff_head write_queue; 961da177e4SLinus Torvalds struct sk_buff_head ack_queue; 971da177e4SLinus Torvalds unsigned char window; 98d97a077aSstephen hemminger const struct lapb_register_struct *callbacks; 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds /* FRMR control information */ 1011da177e4SLinus Torvalds struct lapb_frame frmr_data; 1021da177e4SLinus Torvalds unsigned char frmr_type; 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds atomic_t refcnt; 1051da177e4SLinus Torvalds }; 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds /* lapb_iface.c */ 1081da177e4SLinus Torvalds extern void lapb_connect_confirmation(struct lapb_cb *lapb, int); 1091da177e4SLinus Torvalds extern void lapb_connect_indication(struct lapb_cb *lapb, int); 1101da177e4SLinus Torvalds extern void lapb_disconnect_confirmation(struct lapb_cb *lapb, int); 1111da177e4SLinus Torvalds extern void lapb_disconnect_indication(struct lapb_cb *lapb, int); 1121da177e4SLinus Torvalds extern int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *); 1131da177e4SLinus Torvalds extern int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *); 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds /* lapb_in.c */ 1161da177e4SLinus Torvalds extern void lapb_data_input(struct lapb_cb *lapb, struct sk_buff *); 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds /* lapb_out.c */ 1191da177e4SLinus Torvalds extern void lapb_kick(struct lapb_cb *lapb); 1201da177e4SLinus Torvalds extern void lapb_transmit_buffer(struct lapb_cb *lapb, struct sk_buff *, int); 1211da177e4SLinus Torvalds extern void lapb_establish_data_link(struct lapb_cb *lapb); 1221da177e4SLinus Torvalds extern void lapb_enquiry_response(struct lapb_cb *lapb); 1231da177e4SLinus Torvalds extern void lapb_timeout_response(struct lapb_cb *lapb); 1241da177e4SLinus Torvalds extern void lapb_check_iframes_acked(struct lapb_cb *lapb, unsigned short); 1251da177e4SLinus Torvalds extern void lapb_check_need_response(struct lapb_cb *lapb, int, int); 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds /* lapb_subr.c */ 1281da177e4SLinus Torvalds extern void lapb_clear_queues(struct lapb_cb *lapb); 1291da177e4SLinus Torvalds extern void lapb_frames_acked(struct lapb_cb *lapb, unsigned short); 1301da177e4SLinus Torvalds extern void lapb_requeue_frames(struct lapb_cb *lapb); 1311da177e4SLinus Torvalds extern int lapb_validate_nr(struct lapb_cb *lapb, unsigned short); 1321da177e4SLinus Torvalds extern int lapb_decode(struct lapb_cb *lapb, struct sk_buff *, struct lapb_frame *); 1331da177e4SLinus Torvalds extern void lapb_send_control(struct lapb_cb *lapb, int, int, int); 1341da177e4SLinus Torvalds extern void lapb_transmit_frmr(struct lapb_cb *lapb); 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds /* lapb_timer.c */ 1371da177e4SLinus Torvalds extern void lapb_start_t1timer(struct lapb_cb *lapb); 1381da177e4SLinus Torvalds extern void lapb_start_t2timer(struct lapb_cb *lapb); 1391da177e4SLinus Torvalds extern void lapb_stop_t1timer(struct lapb_cb *lapb); 1401da177e4SLinus Torvalds extern void lapb_stop_t2timer(struct lapb_cb *lapb); 1411da177e4SLinus Torvalds extern int lapb_t1timer_running(struct lapb_cb *lapb); 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds /* 1441da177e4SLinus Torvalds * Debug levels. 1451da177e4SLinus Torvalds * 0 = Off 1461da177e4SLinus Torvalds * 1 = State Changes 1471da177e4SLinus Torvalds * 2 = Packets I/O and State Changes 1481da177e4SLinus Torvalds * 3 = Hex dumps, Packets I/O and State Changes. 1491da177e4SLinus Torvalds */ 1501da177e4SLinus Torvalds #define LAPB_DEBUG 0 1511da177e4SLinus Torvalds 152*a508da6cSJoe Perches #define lapb_dbg(level, fmt, ...) \ 153*a508da6cSJoe Perches do { \ 154*a508da6cSJoe Perches if (level < LAPB_DEBUG) \ 155*a508da6cSJoe Perches pr_debug(fmt, ##__VA_ARGS__); \ 156*a508da6cSJoe Perches } while (0) 157*a508da6cSJoe Perches 1581da177e4SLinus Torvalds #endif 159