18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci=============================== 48c2ecf20Sopenharmony_ciThe Linux LAPB Module Interface 58c2ecf20Sopenharmony_ci=============================== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciVersion 1.3 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciJonathan Naylor 29.12.96 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciChanged (Henner Eisen, 2000-10-29): int return value for data_indication() 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciThe LAPB module will be a separately compiled module for use by any parts of 148c2ecf20Sopenharmony_cithe Linux operating system that require a LAPB service. This document 158c2ecf20Sopenharmony_cidefines the interfaces to, and the services provided by this module. The 168c2ecf20Sopenharmony_citerm module in this context does not imply that the LAPB module is a 178c2ecf20Sopenharmony_ciseparately loadable module, although it may be. The term module is used in 188c2ecf20Sopenharmony_ciits more standard meaning. 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ciThe interface to the LAPB module consists of functions to the module, 218c2ecf20Sopenharmony_cicallbacks from the module to indicate important state changes, and 228c2ecf20Sopenharmony_cistructures for getting and setting information about the module. 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciStructures 258c2ecf20Sopenharmony_ci---------- 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciProbably the most important structure is the skbuff structure for holding 288c2ecf20Sopenharmony_cireceived and transmitted data, however it is beyond the scope of this 298c2ecf20Sopenharmony_cidocument. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciThe two LAPB specific structures are the LAPB initialisation structure and 328c2ecf20Sopenharmony_cithe LAPB parameter structure. These will be defined in a standard header 338c2ecf20Sopenharmony_cifile, <linux/lapb.h>. The header file <net/lapb.h> is internal to the LAPB 348c2ecf20Sopenharmony_cimodule and is not for use. 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ciLAPB Initialisation Structure 378c2ecf20Sopenharmony_ci----------------------------- 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ciThis structure is used only once, in the call to lapb_register (see below). 408c2ecf20Sopenharmony_ciIt contains information about the device driver that requires the services 418c2ecf20Sopenharmony_ciof the LAPB module:: 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci struct lapb_register_struct { 448c2ecf20Sopenharmony_ci void (*connect_confirmation)(int token, int reason); 458c2ecf20Sopenharmony_ci void (*connect_indication)(int token, int reason); 468c2ecf20Sopenharmony_ci void (*disconnect_confirmation)(int token, int reason); 478c2ecf20Sopenharmony_ci void (*disconnect_indication)(int token, int reason); 488c2ecf20Sopenharmony_ci int (*data_indication)(int token, struct sk_buff *skb); 498c2ecf20Sopenharmony_ci void (*data_transmit)(int token, struct sk_buff *skb); 508c2ecf20Sopenharmony_ci }; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciEach member of this structure corresponds to a function in the device driver 538c2ecf20Sopenharmony_cithat is called when a particular event in the LAPB module occurs. These will 548c2ecf20Sopenharmony_cibe described in detail below. If a callback is not required (!!) then a NULL 558c2ecf20Sopenharmony_cimay be substituted. 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ciLAPB Parameter Structure 598c2ecf20Sopenharmony_ci------------------------ 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciThis structure is used with the lapb_getparms and lapb_setparms functions 628c2ecf20Sopenharmony_ci(see below). They are used to allow the device driver to get and set the 638c2ecf20Sopenharmony_cioperational parameters of the LAPB implementation for a given connection:: 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci struct lapb_parms_struct { 668c2ecf20Sopenharmony_ci unsigned int t1; 678c2ecf20Sopenharmony_ci unsigned int t1timer; 688c2ecf20Sopenharmony_ci unsigned int t2; 698c2ecf20Sopenharmony_ci unsigned int t2timer; 708c2ecf20Sopenharmony_ci unsigned int n2; 718c2ecf20Sopenharmony_ci unsigned int n2count; 728c2ecf20Sopenharmony_ci unsigned int window; 738c2ecf20Sopenharmony_ci unsigned int state; 748c2ecf20Sopenharmony_ci unsigned int mode; 758c2ecf20Sopenharmony_ci }; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ciT1 and T2 are protocol timing parameters and are given in units of 100ms. N2 788c2ecf20Sopenharmony_ciis the maximum number of tries on the link before it is declared a failure. 798c2ecf20Sopenharmony_ciThe window size is the maximum number of outstanding data packets allowed to 808c2ecf20Sopenharmony_cibe unacknowledged by the remote end, the value of the window is between 1 818c2ecf20Sopenharmony_ciand 7 for a standard LAPB link, and between 1 and 127 for an extended LAPB 828c2ecf20Sopenharmony_cilink. 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ciThe mode variable is a bit field used for setting (at present) three values. 858c2ecf20Sopenharmony_ciThe bit fields have the following meanings: 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci====== ================================================= 888c2ecf20Sopenharmony_ciBit Meaning 898c2ecf20Sopenharmony_ci====== ================================================= 908c2ecf20Sopenharmony_ci0 LAPB operation (0=LAPB_STANDARD 1=LAPB_EXTENDED). 918c2ecf20Sopenharmony_ci1 [SM]LP operation (0=LAPB_SLP 1=LAPB=MLP). 928c2ecf20Sopenharmony_ci2 DTE/DCE operation (0=LAPB_DTE 1=LAPB_DCE) 938c2ecf20Sopenharmony_ci3-31 Reserved, must be 0. 948c2ecf20Sopenharmony_ci====== ================================================= 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ciExtended LAPB operation indicates the use of extended sequence numbers and 978c2ecf20Sopenharmony_ciconsequently larger window sizes, the default is standard LAPB operation. 988c2ecf20Sopenharmony_ciMLP operation is the same as SLP operation except that the addresses used by 998c2ecf20Sopenharmony_ciLAPB are different to indicate the mode of operation, the default is Single 1008c2ecf20Sopenharmony_ciLink Procedure. The difference between DCE and DTE operation is (i) the 1018c2ecf20Sopenharmony_ciaddresses used for commands and responses, and (ii) when the DCE is not 1028c2ecf20Sopenharmony_ciconnected, it sends DM without polls set, every T1. The upper case constant 1038c2ecf20Sopenharmony_cinames will be defined in the public LAPB header file. 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ciFunctions 1078c2ecf20Sopenharmony_ci--------- 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ciThe LAPB module provides a number of function entry points. 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci:: 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci int lapb_register(void *token, struct lapb_register_struct); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ciThis must be called before the LAPB module may be used. If the call is 1168c2ecf20Sopenharmony_cisuccessful then LAPB_OK is returned. The token must be a unique identifier 1178c2ecf20Sopenharmony_cigenerated by the device driver to allow for the unique identification of the 1188c2ecf20Sopenharmony_ciinstance of the LAPB link. It is returned by the LAPB module in all of the 1198c2ecf20Sopenharmony_cicallbacks, and is used by the device driver in all calls to the LAPB module. 1208c2ecf20Sopenharmony_ciFor multiple LAPB links in a single device driver, multiple calls to 1218c2ecf20Sopenharmony_cilapb_register must be made. The format of the lapb_register_struct is given 1228c2ecf20Sopenharmony_ciabove. The return values are: 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci============= ============================= 1258c2ecf20Sopenharmony_ciLAPB_OK LAPB registered successfully. 1268c2ecf20Sopenharmony_ciLAPB_BADTOKEN Token is already registered. 1278c2ecf20Sopenharmony_ciLAPB_NOMEM Out of memory 1288c2ecf20Sopenharmony_ci============= ============================= 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci:: 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci int lapb_unregister(void *token); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciThis releases all the resources associated with a LAPB link. Any current 1358c2ecf20Sopenharmony_ciLAPB link will be abandoned without further messages being passed. After 1368c2ecf20Sopenharmony_cithis call, the value of token is no longer valid for any calls to the LAPB 1378c2ecf20Sopenharmony_cifunction. The valid return values are: 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci============= =============================== 1408c2ecf20Sopenharmony_ciLAPB_OK LAPB unregistered successfully. 1418c2ecf20Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 1428c2ecf20Sopenharmony_ci============= =============================== 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci:: 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci int lapb_getparms(void *token, struct lapb_parms_struct *parms); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ciThis allows the device driver to get the values of the current LAPB 1498c2ecf20Sopenharmony_civariables, the lapb_parms_struct is described above. The valid return values 1508c2ecf20Sopenharmony_ciare: 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci============= ============================= 1538c2ecf20Sopenharmony_ciLAPB_OK LAPB getparms was successful. 1548c2ecf20Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 1558c2ecf20Sopenharmony_ci============= ============================= 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci:: 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci int lapb_setparms(void *token, struct lapb_parms_struct *parms); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ciThis allows the device driver to set the values of the current LAPB 1628c2ecf20Sopenharmony_civariables, the lapb_parms_struct is described above. The values of t1timer, 1638c2ecf20Sopenharmony_cit2timer and n2count are ignored, likewise changing the mode bits when 1648c2ecf20Sopenharmony_ciconnected will be ignored. An error implies that none of the values have 1658c2ecf20Sopenharmony_cibeen changed. The valid return values are: 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci============= ================================================= 1688c2ecf20Sopenharmony_ciLAPB_OK LAPB getparms was successful. 1698c2ecf20Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 1708c2ecf20Sopenharmony_ciLAPB_INVALUE One of the values was out of its allowable range. 1718c2ecf20Sopenharmony_ci============= ================================================= 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci:: 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci int lapb_connect_request(void *token); 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ciInitiate a connect using the current parameter settings. The valid return 1788c2ecf20Sopenharmony_civalues are: 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci============== ================================= 1818c2ecf20Sopenharmony_ciLAPB_OK LAPB is starting to connect. 1828c2ecf20Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 1838c2ecf20Sopenharmony_ciLAPB_CONNECTED LAPB module is already connected. 1848c2ecf20Sopenharmony_ci============== ================================= 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci:: 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci int lapb_disconnect_request(void *token); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ciInitiate a disconnect. The valid return values are: 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci================= =============================== 1938c2ecf20Sopenharmony_ciLAPB_OK LAPB is starting to disconnect. 1948c2ecf20Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 1958c2ecf20Sopenharmony_ciLAPB_NOTCONNECTED LAPB module is not connected. 1968c2ecf20Sopenharmony_ci================= =============================== 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci:: 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci int lapb_data_request(void *token, struct sk_buff *skb); 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ciQueue data with the LAPB module for transmitting over the link. If the call 2038c2ecf20Sopenharmony_ciis successful then the skbuff is owned by the LAPB module and may not be 2048c2ecf20Sopenharmony_ciused by the device driver again. The valid return values are: 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci================= ============================= 2078c2ecf20Sopenharmony_ciLAPB_OK LAPB has accepted the data. 2088c2ecf20Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 2098c2ecf20Sopenharmony_ciLAPB_NOTCONNECTED LAPB module is not connected. 2108c2ecf20Sopenharmony_ci================= ============================= 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci:: 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci int lapb_data_received(void *token, struct sk_buff *skb); 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ciQueue data with the LAPB module which has been received from the device. It 2178c2ecf20Sopenharmony_ciis expected that the data passed to the LAPB module has skb->data pointing 2188c2ecf20Sopenharmony_cito the beginning of the LAPB data. If the call is successful then the skbuff 2198c2ecf20Sopenharmony_ciis owned by the LAPB module and may not be used by the device driver again. 2208c2ecf20Sopenharmony_ciThe valid return values are: 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci============= =========================== 2238c2ecf20Sopenharmony_ciLAPB_OK LAPB has accepted the data. 2248c2ecf20Sopenharmony_ciLAPB_BADTOKEN Invalid/unknown LAPB token. 2258c2ecf20Sopenharmony_ci============= =========================== 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ciCallbacks 2288c2ecf20Sopenharmony_ci--------- 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ciThese callbacks are functions provided by the device driver for the LAPB 2318c2ecf20Sopenharmony_cimodule to call when an event occurs. They are registered with the LAPB 2328c2ecf20Sopenharmony_cimodule with lapb_register (see above) in the structure lapb_register_struct 2338c2ecf20Sopenharmony_ci(see above). 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci:: 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci void (*connect_confirmation)(void *token, int reason); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ciThis is called by the LAPB module when a connection is established after 2408c2ecf20Sopenharmony_cibeing requested by a call to lapb_connect_request (see above). The reason is 2418c2ecf20Sopenharmony_cialways LAPB_OK. 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci:: 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci void (*connect_indication)(void *token, int reason); 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ciThis is called by the LAPB module when the link is established by the remote 2488c2ecf20Sopenharmony_cisystem. The value of reason is always LAPB_OK. 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci:: 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci void (*disconnect_confirmation)(void *token, int reason); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ciThis is called by the LAPB module when an event occurs after the device 2558c2ecf20Sopenharmony_cidriver has called lapb_disconnect_request (see above). The reason indicates 2568c2ecf20Sopenharmony_ciwhat has happened. In all cases the LAPB link can be regarded as being 2578c2ecf20Sopenharmony_citerminated. The values for reason are: 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci================= ==================================================== 2608c2ecf20Sopenharmony_ciLAPB_OK The LAPB link was terminated normally. 2618c2ecf20Sopenharmony_ciLAPB_NOTCONNECTED The remote system was not connected. 2628c2ecf20Sopenharmony_ciLAPB_TIMEDOUT No response was received in N2 tries from the remote 2638c2ecf20Sopenharmony_ci system. 2648c2ecf20Sopenharmony_ci================= ==================================================== 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci:: 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci void (*disconnect_indication)(void *token, int reason); 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ciThis is called by the LAPB module when the link is terminated by the remote 2718c2ecf20Sopenharmony_cisystem or another event has occurred to terminate the link. This may be 2728c2ecf20Sopenharmony_cireturned in response to a lapb_connect_request (see above) if the remote 2738c2ecf20Sopenharmony_cisystem refused the request. The values for reason are: 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci================= ==================================================== 2768c2ecf20Sopenharmony_ciLAPB_OK The LAPB link was terminated normally by the remote 2778c2ecf20Sopenharmony_ci system. 2788c2ecf20Sopenharmony_ciLAPB_REFUSED The remote system refused the connect request. 2798c2ecf20Sopenharmony_ciLAPB_NOTCONNECTED The remote system was not connected. 2808c2ecf20Sopenharmony_ciLAPB_TIMEDOUT No response was received in N2 tries from the remote 2818c2ecf20Sopenharmony_ci system. 2828c2ecf20Sopenharmony_ci================= ==================================================== 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci:: 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci int (*data_indication)(void *token, struct sk_buff *skb); 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ciThis is called by the LAPB module when data has been received from the 2898c2ecf20Sopenharmony_ciremote system that should be passed onto the next layer in the protocol 2908c2ecf20Sopenharmony_cistack. The skbuff becomes the property of the device driver and the LAPB 2918c2ecf20Sopenharmony_cimodule will not perform any more actions on it. The skb->data pointer will 2928c2ecf20Sopenharmony_cibe pointing to the first byte of data after the LAPB header. 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ciThis method should return NET_RX_DROP (as defined in the header 2958c2ecf20Sopenharmony_cifile include/linux/netdevice.h) if and only if the frame was dropped 2968c2ecf20Sopenharmony_cibefore it could be delivered to the upper layer. 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci:: 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci void (*data_transmit)(void *token, struct sk_buff *skb); 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ciThis is called by the LAPB module when data is to be transmitted to the 3038c2ecf20Sopenharmony_ciremote system by the device driver. The skbuff becomes the property of the 3048c2ecf20Sopenharmony_cidevice driver and the LAPB module will not perform any more actions on it. 3058c2ecf20Sopenharmony_ciThe skb->data pointer will be pointing to the first byte of the LAPB header. 306