162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci=============================== 462306a36Sopenharmony_ciThe Linux LAPB Module Interface 562306a36Sopenharmony_ci=============================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciVersion 1.3 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciJonathan Naylor 29.12.96 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciChanged (Henner Eisen, 2000-10-29): int return value for data_indication() 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciThe LAPB module will be a separately compiled module for use by any parts of 1462306a36Sopenharmony_cithe Linux operating system that require a LAPB service. This document 1562306a36Sopenharmony_cidefines the interfaces to, and the services provided by this module. The 1662306a36Sopenharmony_citerm module in this context does not imply that the LAPB module is a 1762306a36Sopenharmony_ciseparately loadable module, although it may be. The term module is used in 1862306a36Sopenharmony_ciits more standard meaning. 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ciThe interface to the LAPB module consists of functions to the module, 2162306a36Sopenharmony_cicallbacks from the module to indicate important state changes, and 2262306a36Sopenharmony_cistructures for getting and setting information about the module. 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciStructures 2562306a36Sopenharmony_ci---------- 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ciProbably the most important structure is the skbuff structure for holding 2862306a36Sopenharmony_cireceived and transmitted data, however it is beyond the scope of this 2962306a36Sopenharmony_cidocument. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciThe two LAPB specific structures are the LAPB initialisation structure and 3262306a36Sopenharmony_cithe LAPB parameter structure. These will be defined in a standard header 3362306a36Sopenharmony_cifile, <linux/lapb.h>. The header file <net/lapb.h> is internal to the LAPB 3462306a36Sopenharmony_cimodule and is not for use. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciLAPB Initialisation Structure 3762306a36Sopenharmony_ci----------------------------- 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ciThis structure is used only once, in the call to lapb_register (see below). 4062306a36Sopenharmony_ciIt contains information about the device driver that requires the services 4162306a36Sopenharmony_ciof the LAPB module:: 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci struct lapb_register_struct { 4462306a36Sopenharmony_ci void (*connect_confirmation)(int token, int reason); 4562306a36Sopenharmony_ci void (*connect_indication)(int token, int reason); 4662306a36Sopenharmony_ci void (*disconnect_confirmation)(int token, int reason); 4762306a36Sopenharmony_ci void (*disconnect_indication)(int token, int reason); 4862306a36Sopenharmony_ci int (*data_indication)(int token, struct sk_buff *skb); 4962306a36Sopenharmony_ci void (*data_transmit)(int token, struct sk_buff *skb); 5062306a36Sopenharmony_ci }; 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciEach member of this structure corresponds to a function in the device driver 5362306a36Sopenharmony_cithat is called when a particular event in the LAPB module occurs. These will 5462306a36Sopenharmony_cibe described in detail below. If a callback is not required (!!) then a NULL 5562306a36Sopenharmony_cimay be substituted. 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciLAPB Parameter Structure 5962306a36Sopenharmony_ci------------------------ 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciThis structure is used with the lapb_getparms and lapb_setparms functions 6262306a36Sopenharmony_ci(see below). They are used to allow the device driver to get and set the 6362306a36Sopenharmony_cioperational parameters of the LAPB implementation for a given connection:: 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci struct lapb_parms_struct { 6662306a36Sopenharmony_ci unsigned int t1; 6762306a36Sopenharmony_ci unsigned int t1timer; 6862306a36Sopenharmony_ci unsigned int t2; 6962306a36Sopenharmony_ci unsigned int t2timer; 7062306a36Sopenharmony_ci unsigned int n2; 7162306a36Sopenharmony_ci unsigned int n2count; 7262306a36Sopenharmony_ci unsigned int window; 7362306a36Sopenharmony_ci unsigned int state; 7462306a36Sopenharmony_ci unsigned int mode; 7562306a36Sopenharmony_ci }; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ciT1 and T2 are protocol timing parameters and are given in units of 100ms. N2 7862306a36Sopenharmony_ciis the maximum number of tries on the link before it is declared a failure. 7962306a36Sopenharmony_ciThe window size is the maximum number of outstanding data packets allowed to 8062306a36Sopenharmony_cibe unacknowledged by the remote end, the value of the window is between 1 8162306a36Sopenharmony_ciand 7 for a standard LAPB link, and between 1 and 127 for an extended LAPB 8262306a36Sopenharmony_cilink. 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ciThe mode variable is a bit field used for setting (at present) three values. 8562306a36Sopenharmony_ciThe bit fields have the following meanings: 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci====== ================================================= 8862306a36Sopenharmony_ciBit Meaning 8962306a36Sopenharmony_ci====== ================================================= 9062306a36Sopenharmony_ci0 LAPB operation (0=LAPB_STANDARD 1=LAPB_EXTENDED). 9162306a36Sopenharmony_ci1 [SM]LP operation (0=LAPB_SLP 1=LAPB=MLP). 9262306a36Sopenharmony_ci2 DTE/DCE operation (0=LAPB_DTE 1=LAPB_DCE) 9362306a36Sopenharmony_ci3-31 Reserved, must be 0. 9462306a36Sopenharmony_ci====== ================================================= 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ciExtended LAPB operation indicates the use of extended sequence numbers and 9762306a36Sopenharmony_ciconsequently larger window sizes, the default is standard LAPB operation. 9862306a36Sopenharmony_ciMLP operation is the same as SLP operation except that the addresses used by 9962306a36Sopenharmony_ciLAPB are different to indicate the mode of operation, the default is Single 10062306a36Sopenharmony_ciLink Procedure. The difference between DCE and DTE operation is (i) the 10162306a36Sopenharmony_ciaddresses used for commands and responses, and (ii) when the DCE is not 10262306a36Sopenharmony_ciconnected, it sends DM without polls set, every T1. The upper case constant 10362306a36Sopenharmony_cinames will be defined in the public LAPB header file. 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ciFunctions 10762306a36Sopenharmony_ci--------- 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ciThe LAPB module provides a number of function entry points. 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci:: 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci int lapb_register(void *token, struct lapb_register_struct); 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ciThis must be called before the LAPB module may be used. If the call is 11662306a36Sopenharmony_cisuccessful then LAPB_OK is returned. The token must be a unique identifier 11762306a36Sopenharmony_cigenerated by the device driver to allow for the unique identification of the 11862306a36Sopenharmony_ciinstance of the LAPB link. It is returned by the LAPB module in all of the 11962306a36Sopenharmony_cicallbacks, and is used by the device driver in all calls to the LAPB module. 12062306a36Sopenharmony_ciFor multiple LAPB links in a single device driver, multiple calls to 12162306a36Sopenharmony_cilapb_register must be made. The format of the lapb_register_struct is given 12262306a36Sopenharmony_ciabove. The return values are: 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci============= ============================= 12562306a36Sopenharmony_ciLAPB_OK LAPB registered successfully. 12662306a36Sopenharmony_ciLAPB_BADTOKEN Token is already registered. 12762306a36Sopenharmony_ciLAPB_NOMEM Out of memory 12862306a36Sopenharmony_ci============= ============================= 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci:: 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci int lapb_unregister(void *token); 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ciThis releases all the resources associated with a LAPB link. Any current 13562306a36Sopenharmony_ciLAPB link will be abandoned without further messages being passed. After 13662306a36Sopenharmony_cithis call, the value of token is no longer valid for any calls to the LAPB 13762306a36Sopenharmony_cifunction. The valid return values are: 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci============= =============================== 14062306a36Sopenharmony_ciLAPB_OK LAPB unregistered successfully. 14162306a36Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 14262306a36Sopenharmony_ci============= =============================== 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci:: 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci int lapb_getparms(void *token, struct lapb_parms_struct *parms); 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ciThis allows the device driver to get the values of the current LAPB 14962306a36Sopenharmony_civariables, the lapb_parms_struct is described above. The valid return values 15062306a36Sopenharmony_ciare: 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci============= ============================= 15362306a36Sopenharmony_ciLAPB_OK LAPB getparms was successful. 15462306a36Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 15562306a36Sopenharmony_ci============= ============================= 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci:: 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci int lapb_setparms(void *token, struct lapb_parms_struct *parms); 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ciThis allows the device driver to set the values of the current LAPB 16262306a36Sopenharmony_civariables, the lapb_parms_struct is described above. The values of t1timer, 16362306a36Sopenharmony_cit2timer and n2count are ignored, likewise changing the mode bits when 16462306a36Sopenharmony_ciconnected will be ignored. An error implies that none of the values have 16562306a36Sopenharmony_cibeen changed. The valid return values are: 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci============= ================================================= 16862306a36Sopenharmony_ciLAPB_OK LAPB getparms was successful. 16962306a36Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 17062306a36Sopenharmony_ciLAPB_INVALUE One of the values was out of its allowable range. 17162306a36Sopenharmony_ci============= ================================================= 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci:: 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci int lapb_connect_request(void *token); 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ciInitiate a connect using the current parameter settings. The valid return 17862306a36Sopenharmony_civalues are: 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci============== ================================= 18162306a36Sopenharmony_ciLAPB_OK LAPB is starting to connect. 18262306a36Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 18362306a36Sopenharmony_ciLAPB_CONNECTED LAPB module is already connected. 18462306a36Sopenharmony_ci============== ================================= 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci:: 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci int lapb_disconnect_request(void *token); 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ciInitiate a disconnect. The valid return values are: 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci================= =============================== 19362306a36Sopenharmony_ciLAPB_OK LAPB is starting to disconnect. 19462306a36Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 19562306a36Sopenharmony_ciLAPB_NOTCONNECTED LAPB module is not connected. 19662306a36Sopenharmony_ci================= =============================== 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci:: 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci int lapb_data_request(void *token, struct sk_buff *skb); 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ciQueue data with the LAPB module for transmitting over the link. If the call 20362306a36Sopenharmony_ciis successful then the skbuff is owned by the LAPB module and may not be 20462306a36Sopenharmony_ciused by the device driver again. The valid return values are: 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci================= ============================= 20762306a36Sopenharmony_ciLAPB_OK LAPB has accepted the data. 20862306a36Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 20962306a36Sopenharmony_ciLAPB_NOTCONNECTED LAPB module is not connected. 21062306a36Sopenharmony_ci================= ============================= 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci:: 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci int lapb_data_received(void *token, struct sk_buff *skb); 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_ciQueue data with the LAPB module which has been received from the device. It 21762306a36Sopenharmony_ciis expected that the data passed to the LAPB module has skb->data pointing 21862306a36Sopenharmony_cito the beginning of the LAPB data. If the call is successful then the skbuff 21962306a36Sopenharmony_ciis owned by the LAPB module and may not be used by the device driver again. 22062306a36Sopenharmony_ciThe valid return values are: 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci============= =========================== 22362306a36Sopenharmony_ciLAPB_OK LAPB has accepted the data. 22462306a36Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 22562306a36Sopenharmony_ci============= =========================== 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ciCallbacks 22862306a36Sopenharmony_ci--------- 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ciThese callbacks are functions provided by the device driver for the LAPB 23162306a36Sopenharmony_cimodule to call when an event occurs. They are registered with the LAPB 23262306a36Sopenharmony_cimodule with lapb_register (see above) in the structure lapb_register_struct 23362306a36Sopenharmony_ci(see above). 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci:: 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci void (*connect_confirmation)(void *token, int reason); 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ciThis is called by the LAPB module when a connection is established after 24062306a36Sopenharmony_cibeing requested by a call to lapb_connect_request (see above). The reason is 24162306a36Sopenharmony_cialways LAPB_OK. 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci:: 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci void (*connect_indication)(void *token, int reason); 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ciThis is called by the LAPB module when the link is established by the remote 24862306a36Sopenharmony_cisystem. The value of reason is always LAPB_OK. 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci:: 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci void (*disconnect_confirmation)(void *token, int reason); 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ciThis is called by the LAPB module when an event occurs after the device 25562306a36Sopenharmony_cidriver has called lapb_disconnect_request (see above). The reason indicates 25662306a36Sopenharmony_ciwhat has happened. In all cases the LAPB link can be regarded as being 25762306a36Sopenharmony_citerminated. The values for reason are: 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ci================= ==================================================== 26062306a36Sopenharmony_ciLAPB_OK The LAPB link was terminated normally. 26162306a36Sopenharmony_ciLAPB_NOTCONNECTED The remote system was not connected. 26262306a36Sopenharmony_ciLAPB_TIMEDOUT No response was received in N2 tries from the remote 26362306a36Sopenharmony_ci system. 26462306a36Sopenharmony_ci================= ==================================================== 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci:: 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci void (*disconnect_indication)(void *token, int reason); 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ciThis is called by the LAPB module when the link is terminated by the remote 27162306a36Sopenharmony_cisystem or another event has occurred to terminate the link. This may be 27262306a36Sopenharmony_cireturned in response to a lapb_connect_request (see above) if the remote 27362306a36Sopenharmony_cisystem refused the request. The values for reason are: 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci================= ==================================================== 27662306a36Sopenharmony_ciLAPB_OK The LAPB link was terminated normally by the remote 27762306a36Sopenharmony_ci system. 27862306a36Sopenharmony_ciLAPB_REFUSED The remote system refused the connect request. 27962306a36Sopenharmony_ciLAPB_NOTCONNECTED The remote system was not connected. 28062306a36Sopenharmony_ciLAPB_TIMEDOUT No response was received in N2 tries from the remote 28162306a36Sopenharmony_ci system. 28262306a36Sopenharmony_ci================= ==================================================== 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci:: 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_ci int (*data_indication)(void *token, struct sk_buff *skb); 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ciThis is called by the LAPB module when data has been received from the 28962306a36Sopenharmony_ciremote system that should be passed onto the next layer in the protocol 29062306a36Sopenharmony_cistack. The skbuff becomes the property of the device driver and the LAPB 29162306a36Sopenharmony_cimodule will not perform any more actions on it. The skb->data pointer will 29262306a36Sopenharmony_cibe pointing to the first byte of data after the LAPB header. 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ciThis method should return NET_RX_DROP (as defined in the header 29562306a36Sopenharmony_cifile include/linux/netdevice.h) if and only if the frame was dropped 29662306a36Sopenharmony_cibefore it could be delivered to the upper layer. 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci:: 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci void (*data_transmit)(void *token, struct sk_buff *skb); 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ciThis is called by the LAPB module when data is to be transmitted to the 30362306a36Sopenharmony_ciremote system by the device driver. The skbuff becomes the property of the 30462306a36Sopenharmony_cidevice driver and the LAPB module will not perform any more actions on it. 30562306a36Sopenharmony_ciThe skb->data pointer will be pointing to the first byte of the LAPB header. 306