1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun=============================== 4*4882a593SmuzhiyunThe Linux LAPB Module Interface 5*4882a593Smuzhiyun=============================== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunVersion 1.3 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunJonathan Naylor 29.12.96 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunChanged (Henner Eisen, 2000-10-29): int return value for data_indication() 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunThe LAPB module will be a separately compiled module for use by any parts of 14*4882a593Smuzhiyunthe Linux operating system that require a LAPB service. This document 15*4882a593Smuzhiyundefines the interfaces to, and the services provided by this module. The 16*4882a593Smuzhiyunterm module in this context does not imply that the LAPB module is a 17*4882a593Smuzhiyunseparately loadable module, although it may be. The term module is used in 18*4882a593Smuzhiyunits more standard meaning. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunThe interface to the LAPB module consists of functions to the module, 21*4882a593Smuzhiyuncallbacks from the module to indicate important state changes, and 22*4882a593Smuzhiyunstructures for getting and setting information about the module. 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunStructures 25*4882a593Smuzhiyun---------- 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunProbably the most important structure is the skbuff structure for holding 28*4882a593Smuzhiyunreceived and transmitted data, however it is beyond the scope of this 29*4882a593Smuzhiyundocument. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunThe two LAPB specific structures are the LAPB initialisation structure and 32*4882a593Smuzhiyunthe LAPB parameter structure. These will be defined in a standard header 33*4882a593Smuzhiyunfile, <linux/lapb.h>. The header file <net/lapb.h> is internal to the LAPB 34*4882a593Smuzhiyunmodule and is not for use. 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunLAPB Initialisation Structure 37*4882a593Smuzhiyun----------------------------- 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunThis structure is used only once, in the call to lapb_register (see below). 40*4882a593SmuzhiyunIt contains information about the device driver that requires the services 41*4882a593Smuzhiyunof the LAPB module:: 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun struct lapb_register_struct { 44*4882a593Smuzhiyun void (*connect_confirmation)(int token, int reason); 45*4882a593Smuzhiyun void (*connect_indication)(int token, int reason); 46*4882a593Smuzhiyun void (*disconnect_confirmation)(int token, int reason); 47*4882a593Smuzhiyun void (*disconnect_indication)(int token, int reason); 48*4882a593Smuzhiyun int (*data_indication)(int token, struct sk_buff *skb); 49*4882a593Smuzhiyun void (*data_transmit)(int token, struct sk_buff *skb); 50*4882a593Smuzhiyun }; 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunEach member of this structure corresponds to a function in the device driver 53*4882a593Smuzhiyunthat is called when a particular event in the LAPB module occurs. These will 54*4882a593Smuzhiyunbe described in detail below. If a callback is not required (!!) then a NULL 55*4882a593Smuzhiyunmay be substituted. 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun 58*4882a593SmuzhiyunLAPB Parameter Structure 59*4882a593Smuzhiyun------------------------ 60*4882a593Smuzhiyun 61*4882a593SmuzhiyunThis structure is used with the lapb_getparms and lapb_setparms functions 62*4882a593Smuzhiyun(see below). They are used to allow the device driver to get and set the 63*4882a593Smuzhiyunoperational parameters of the LAPB implementation for a given connection:: 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun struct lapb_parms_struct { 66*4882a593Smuzhiyun unsigned int t1; 67*4882a593Smuzhiyun unsigned int t1timer; 68*4882a593Smuzhiyun unsigned int t2; 69*4882a593Smuzhiyun unsigned int t2timer; 70*4882a593Smuzhiyun unsigned int n2; 71*4882a593Smuzhiyun unsigned int n2count; 72*4882a593Smuzhiyun unsigned int window; 73*4882a593Smuzhiyun unsigned int state; 74*4882a593Smuzhiyun unsigned int mode; 75*4882a593Smuzhiyun }; 76*4882a593Smuzhiyun 77*4882a593SmuzhiyunT1 and T2 are protocol timing parameters and are given in units of 100ms. N2 78*4882a593Smuzhiyunis the maximum number of tries on the link before it is declared a failure. 79*4882a593SmuzhiyunThe window size is the maximum number of outstanding data packets allowed to 80*4882a593Smuzhiyunbe unacknowledged by the remote end, the value of the window is between 1 81*4882a593Smuzhiyunand 7 for a standard LAPB link, and between 1 and 127 for an extended LAPB 82*4882a593Smuzhiyunlink. 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunThe mode variable is a bit field used for setting (at present) three values. 85*4882a593SmuzhiyunThe bit fields have the following meanings: 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun====== ================================================= 88*4882a593SmuzhiyunBit Meaning 89*4882a593Smuzhiyun====== ================================================= 90*4882a593Smuzhiyun0 LAPB operation (0=LAPB_STANDARD 1=LAPB_EXTENDED). 91*4882a593Smuzhiyun1 [SM]LP operation (0=LAPB_SLP 1=LAPB=MLP). 92*4882a593Smuzhiyun2 DTE/DCE operation (0=LAPB_DTE 1=LAPB_DCE) 93*4882a593Smuzhiyun3-31 Reserved, must be 0. 94*4882a593Smuzhiyun====== ================================================= 95*4882a593Smuzhiyun 96*4882a593SmuzhiyunExtended LAPB operation indicates the use of extended sequence numbers and 97*4882a593Smuzhiyunconsequently larger window sizes, the default is standard LAPB operation. 98*4882a593SmuzhiyunMLP operation is the same as SLP operation except that the addresses used by 99*4882a593SmuzhiyunLAPB are different to indicate the mode of operation, the default is Single 100*4882a593SmuzhiyunLink Procedure. The difference between DCE and DTE operation is (i) the 101*4882a593Smuzhiyunaddresses used for commands and responses, and (ii) when the DCE is not 102*4882a593Smuzhiyunconnected, it sends DM without polls set, every T1. The upper case constant 103*4882a593Smuzhiyunnames will be defined in the public LAPB header file. 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun 106*4882a593SmuzhiyunFunctions 107*4882a593Smuzhiyun--------- 108*4882a593Smuzhiyun 109*4882a593SmuzhiyunThe LAPB module provides a number of function entry points. 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun:: 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun int lapb_register(void *token, struct lapb_register_struct); 114*4882a593Smuzhiyun 115*4882a593SmuzhiyunThis must be called before the LAPB module may be used. If the call is 116*4882a593Smuzhiyunsuccessful then LAPB_OK is returned. The token must be a unique identifier 117*4882a593Smuzhiyungenerated by the device driver to allow for the unique identification of the 118*4882a593Smuzhiyuninstance of the LAPB link. It is returned by the LAPB module in all of the 119*4882a593Smuzhiyuncallbacks, and is used by the device driver in all calls to the LAPB module. 120*4882a593SmuzhiyunFor multiple LAPB links in a single device driver, multiple calls to 121*4882a593Smuzhiyunlapb_register must be made. The format of the lapb_register_struct is given 122*4882a593Smuzhiyunabove. The return values are: 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun============= ============================= 125*4882a593SmuzhiyunLAPB_OK LAPB registered successfully. 126*4882a593SmuzhiyunLAPB_BADTOKEN Token is already registered. 127*4882a593SmuzhiyunLAPB_NOMEM Out of memory 128*4882a593Smuzhiyun============= ============================= 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun:: 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun int lapb_unregister(void *token); 133*4882a593Smuzhiyun 134*4882a593SmuzhiyunThis releases all the resources associated with a LAPB link. Any current 135*4882a593SmuzhiyunLAPB link will be abandoned without further messages being passed. After 136*4882a593Smuzhiyunthis call, the value of token is no longer valid for any calls to the LAPB 137*4882a593Smuzhiyunfunction. The valid return values are: 138*4882a593Smuzhiyun 139*4882a593Smuzhiyun============= =============================== 140*4882a593SmuzhiyunLAPB_OK LAPB unregistered successfully. 141*4882a593SmuzhiyunLAPB_BADTOKEN Invalid/unknown LAPB token. 142*4882a593Smuzhiyun============= =============================== 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun:: 145*4882a593Smuzhiyun 146*4882a593Smuzhiyun int lapb_getparms(void *token, struct lapb_parms_struct *parms); 147*4882a593Smuzhiyun 148*4882a593SmuzhiyunThis allows the device driver to get the values of the current LAPB 149*4882a593Smuzhiyunvariables, the lapb_parms_struct is described above. The valid return values 150*4882a593Smuzhiyunare: 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun============= ============================= 153*4882a593SmuzhiyunLAPB_OK LAPB getparms was successful. 154*4882a593SmuzhiyunLAPB_BADTOKEN Invalid/unknown LAPB token. 155*4882a593Smuzhiyun============= ============================= 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun:: 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun int lapb_setparms(void *token, struct lapb_parms_struct *parms); 160*4882a593Smuzhiyun 161*4882a593SmuzhiyunThis allows the device driver to set the values of the current LAPB 162*4882a593Smuzhiyunvariables, the lapb_parms_struct is described above. The values of t1timer, 163*4882a593Smuzhiyunt2timer and n2count are ignored, likewise changing the mode bits when 164*4882a593Smuzhiyunconnected will be ignored. An error implies that none of the values have 165*4882a593Smuzhiyunbeen changed. The valid return values are: 166*4882a593Smuzhiyun 167*4882a593Smuzhiyun============= ================================================= 168*4882a593SmuzhiyunLAPB_OK LAPB getparms was successful. 169*4882a593SmuzhiyunLAPB_BADTOKEN Invalid/unknown LAPB token. 170*4882a593SmuzhiyunLAPB_INVALUE One of the values was out of its allowable range. 171*4882a593Smuzhiyun============= ================================================= 172*4882a593Smuzhiyun 173*4882a593Smuzhiyun:: 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun int lapb_connect_request(void *token); 176*4882a593Smuzhiyun 177*4882a593SmuzhiyunInitiate a connect using the current parameter settings. The valid return 178*4882a593Smuzhiyunvalues are: 179*4882a593Smuzhiyun 180*4882a593Smuzhiyun============== ================================= 181*4882a593SmuzhiyunLAPB_OK LAPB is starting to connect. 182*4882a593SmuzhiyunLAPB_BADTOKEN Invalid/unknown LAPB token. 183*4882a593SmuzhiyunLAPB_CONNECTED LAPB module is already connected. 184*4882a593Smuzhiyun============== ================================= 185*4882a593Smuzhiyun 186*4882a593Smuzhiyun:: 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun int lapb_disconnect_request(void *token); 189*4882a593Smuzhiyun 190*4882a593SmuzhiyunInitiate a disconnect. The valid return values are: 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun================= =============================== 193*4882a593SmuzhiyunLAPB_OK LAPB is starting to disconnect. 194*4882a593SmuzhiyunLAPB_BADTOKEN Invalid/unknown LAPB token. 195*4882a593SmuzhiyunLAPB_NOTCONNECTED LAPB module is not connected. 196*4882a593Smuzhiyun================= =============================== 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun:: 199*4882a593Smuzhiyun 200*4882a593Smuzhiyun int lapb_data_request(void *token, struct sk_buff *skb); 201*4882a593Smuzhiyun 202*4882a593SmuzhiyunQueue data with the LAPB module for transmitting over the link. If the call 203*4882a593Smuzhiyunis successful then the skbuff is owned by the LAPB module and may not be 204*4882a593Smuzhiyunused by the device driver again. The valid return values are: 205*4882a593Smuzhiyun 206*4882a593Smuzhiyun================= ============================= 207*4882a593SmuzhiyunLAPB_OK LAPB has accepted the data. 208*4882a593SmuzhiyunLAPB_BADTOKEN Invalid/unknown LAPB token. 209*4882a593SmuzhiyunLAPB_NOTCONNECTED LAPB module is not connected. 210*4882a593Smuzhiyun================= ============================= 211*4882a593Smuzhiyun 212*4882a593Smuzhiyun:: 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun int lapb_data_received(void *token, struct sk_buff *skb); 215*4882a593Smuzhiyun 216*4882a593SmuzhiyunQueue data with the LAPB module which has been received from the device. It 217*4882a593Smuzhiyunis expected that the data passed to the LAPB module has skb->data pointing 218*4882a593Smuzhiyunto the beginning of the LAPB data. If the call is successful then the skbuff 219*4882a593Smuzhiyunis owned by the LAPB module and may not be used by the device driver again. 220*4882a593SmuzhiyunThe valid return values are: 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun============= =========================== 223*4882a593SmuzhiyunLAPB_OK LAPB has accepted the data. 224*4882a593SmuzhiyunLAPB_BADTOKEN Invalid/unknown LAPB token. 225*4882a593Smuzhiyun============= =========================== 226*4882a593Smuzhiyun 227*4882a593SmuzhiyunCallbacks 228*4882a593Smuzhiyun--------- 229*4882a593Smuzhiyun 230*4882a593SmuzhiyunThese callbacks are functions provided by the device driver for the LAPB 231*4882a593Smuzhiyunmodule to call when an event occurs. They are registered with the LAPB 232*4882a593Smuzhiyunmodule with lapb_register (see above) in the structure lapb_register_struct 233*4882a593Smuzhiyun(see above). 234*4882a593Smuzhiyun 235*4882a593Smuzhiyun:: 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun void (*connect_confirmation)(void *token, int reason); 238*4882a593Smuzhiyun 239*4882a593SmuzhiyunThis is called by the LAPB module when a connection is established after 240*4882a593Smuzhiyunbeing requested by a call to lapb_connect_request (see above). The reason is 241*4882a593Smuzhiyunalways LAPB_OK. 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun:: 244*4882a593Smuzhiyun 245*4882a593Smuzhiyun void (*connect_indication)(void *token, int reason); 246*4882a593Smuzhiyun 247*4882a593SmuzhiyunThis is called by the LAPB module when the link is established by the remote 248*4882a593Smuzhiyunsystem. The value of reason is always LAPB_OK. 249*4882a593Smuzhiyun 250*4882a593Smuzhiyun:: 251*4882a593Smuzhiyun 252*4882a593Smuzhiyun void (*disconnect_confirmation)(void *token, int reason); 253*4882a593Smuzhiyun 254*4882a593SmuzhiyunThis is called by the LAPB module when an event occurs after the device 255*4882a593Smuzhiyundriver has called lapb_disconnect_request (see above). The reason indicates 256*4882a593Smuzhiyunwhat has happened. In all cases the LAPB link can be regarded as being 257*4882a593Smuzhiyunterminated. The values for reason are: 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun================= ==================================================== 260*4882a593SmuzhiyunLAPB_OK The LAPB link was terminated normally. 261*4882a593SmuzhiyunLAPB_NOTCONNECTED The remote system was not connected. 262*4882a593SmuzhiyunLAPB_TIMEDOUT No response was received in N2 tries from the remote 263*4882a593Smuzhiyun system. 264*4882a593Smuzhiyun================= ==================================================== 265*4882a593Smuzhiyun 266*4882a593Smuzhiyun:: 267*4882a593Smuzhiyun 268*4882a593Smuzhiyun void (*disconnect_indication)(void *token, int reason); 269*4882a593Smuzhiyun 270*4882a593SmuzhiyunThis is called by the LAPB module when the link is terminated by the remote 271*4882a593Smuzhiyunsystem or another event has occurred to terminate the link. This may be 272*4882a593Smuzhiyunreturned in response to a lapb_connect_request (see above) if the remote 273*4882a593Smuzhiyunsystem refused the request. The values for reason are: 274*4882a593Smuzhiyun 275*4882a593Smuzhiyun================= ==================================================== 276*4882a593SmuzhiyunLAPB_OK The LAPB link was terminated normally by the remote 277*4882a593Smuzhiyun system. 278*4882a593SmuzhiyunLAPB_REFUSED The remote system refused the connect request. 279*4882a593SmuzhiyunLAPB_NOTCONNECTED The remote system was not connected. 280*4882a593SmuzhiyunLAPB_TIMEDOUT No response was received in N2 tries from the remote 281*4882a593Smuzhiyun system. 282*4882a593Smuzhiyun================= ==================================================== 283*4882a593Smuzhiyun 284*4882a593Smuzhiyun:: 285*4882a593Smuzhiyun 286*4882a593Smuzhiyun int (*data_indication)(void *token, struct sk_buff *skb); 287*4882a593Smuzhiyun 288*4882a593SmuzhiyunThis is called by the LAPB module when data has been received from the 289*4882a593Smuzhiyunremote system that should be passed onto the next layer in the protocol 290*4882a593Smuzhiyunstack. The skbuff becomes the property of the device driver and the LAPB 291*4882a593Smuzhiyunmodule will not perform any more actions on it. The skb->data pointer will 292*4882a593Smuzhiyunbe pointing to the first byte of data after the LAPB header. 293*4882a593Smuzhiyun 294*4882a593SmuzhiyunThis method should return NET_RX_DROP (as defined in the header 295*4882a593Smuzhiyunfile include/linux/netdevice.h) if and only if the frame was dropped 296*4882a593Smuzhiyunbefore it could be delivered to the upper layer. 297*4882a593Smuzhiyun 298*4882a593Smuzhiyun:: 299*4882a593Smuzhiyun 300*4882a593Smuzhiyun void (*data_transmit)(void *token, struct sk_buff *skb); 301*4882a593Smuzhiyun 302*4882a593SmuzhiyunThis is called by the LAPB module when data is to be transmitted to the 303*4882a593Smuzhiyunremote system by the device driver. The skbuff becomes the property of the 304*4882a593Smuzhiyundevice driver and the LAPB module will not perform any more actions on it. 305*4882a593SmuzhiyunThe skb->data pointer will be pointing to the first byte of the LAPB header. 306