xref: /OK3568_Linux_fs/kernel/Documentation/isdn/interface_capi.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=========================================
2*4882a593SmuzhiyunKernel CAPI Interface to Hardware Drivers
3*4882a593Smuzhiyun=========================================
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun1. Overview
6*4882a593Smuzhiyun===========
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunFrom the CAPI 2.0 specification:
9*4882a593SmuzhiyunCOMMON-ISDN-API (CAPI) is an application programming interface standard used
10*4882a593Smuzhiyunto access ISDN equipment connected to basic rate interfaces (BRI) and primary
11*4882a593Smuzhiyunrate interfaces (PRI).
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunKernel CAPI operates as a dispatching layer between CAPI applications and CAPI
14*4882a593Smuzhiyunhardware drivers. Hardware drivers register ISDN devices (controllers, in CAPI
15*4882a593Smuzhiyunlingo) with Kernel CAPI to indicate their readiness to provide their service
16*4882a593Smuzhiyunto CAPI applications. CAPI applications also register with Kernel CAPI,
17*4882a593Smuzhiyunrequesting association with a CAPI device. Kernel CAPI then dispatches the
18*4882a593Smuzhiyunapplication registration to an available device, forwarding it to the
19*4882a593Smuzhiyuncorresponding hardware driver. Kernel CAPI then forwards CAPI messages in both
20*4882a593Smuzhiyundirections between the application and the hardware driver.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunFormat and semantics of CAPI messages are specified in the CAPI 2.0 standard.
23*4882a593SmuzhiyunThis standard is freely available from https://www.capi.org.
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun2. Driver and Device Registration
27*4882a593Smuzhiyun=================================
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunCAPI drivers must register each of the ISDN devices they control with Kernel
30*4882a593SmuzhiyunCAPI by calling the Kernel CAPI function attach_capi_ctr() with a pointer to a
31*4882a593Smuzhiyunstruct capi_ctr before they can be used. This structure must be filled with
32*4882a593Smuzhiyunthe names of the driver and controller, and a number of callback function
33*4882a593Smuzhiyunpointers which are subsequently used by Kernel CAPI for communicating with the
34*4882a593Smuzhiyundriver. The registration can be revoked by calling the function
35*4882a593Smuzhiyundetach_capi_ctr() with a pointer to the same struct capi_ctr.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunBefore the device can be actually used, the driver must fill in the device
38*4882a593Smuzhiyuninformation fields 'manu', 'version', 'profile' and 'serial' in the capi_ctr
39*4882a593Smuzhiyunstructure of the device, and signal its readiness by calling capi_ctr_ready().
40*4882a593SmuzhiyunFrom then on, Kernel CAPI may call the registered callback functions for the
41*4882a593Smuzhiyundevice.
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunIf the device becomes unusable for any reason (shutdown, disconnect ...), the
44*4882a593Smuzhiyundriver has to call capi_ctr_down(). This will prevent further calls to the
45*4882a593Smuzhiyuncallback functions by Kernel CAPI.
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun3. Application Registration and Communication
49*4882a593Smuzhiyun=============================================
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunKernel CAPI forwards registration requests from applications (calls to CAPI
52*4882a593Smuzhiyunoperation CAPI_REGISTER) to an appropriate hardware driver by calling its
53*4882a593Smuzhiyunregister_appl() callback function. A unique Application ID (ApplID, u16) is
54*4882a593Smuzhiyunallocated by Kernel CAPI and passed to register_appl() along with the
55*4882a593Smuzhiyunparameter structure provided by the application. This is analogous to the
56*4882a593Smuzhiyunopen() operation on regular files or character devices.
57*4882a593Smuzhiyun
58*4882a593SmuzhiyunAfter a successful return from register_appl(), CAPI messages from the
59*4882a593Smuzhiyunapplication may be passed to the driver for the device via calls to the
60*4882a593Smuzhiyunsend_message() callback function. Conversely, the driver may call Kernel
61*4882a593SmuzhiyunCAPI's capi_ctr_handle_message() function to pass a received CAPI message to
62*4882a593SmuzhiyunKernel CAPI for forwarding to an application, specifying its ApplID.
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunDeregistration requests (CAPI operation CAPI_RELEASE) from applications are
65*4882a593Smuzhiyunforwarded as calls to the release_appl() callback function, passing the same
66*4882a593SmuzhiyunApplID as with register_appl(). After return from release_appl(), no CAPI
67*4882a593Smuzhiyunmessages for that application may be passed to or from the device anymore.
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun4. Data Structures
71*4882a593Smuzhiyun==================
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun4.1 struct capi_driver
74*4882a593Smuzhiyun----------------------
75*4882a593Smuzhiyun
76*4882a593SmuzhiyunThis structure describes a Kernel CAPI driver itself. It is used in the
77*4882a593Smuzhiyunregister_capi_driver() and unregister_capi_driver() functions, and contains
78*4882a593Smuzhiyunthe following non-private fields, all to be set by the driver before calling
79*4882a593Smuzhiyunregister_capi_driver():
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun``char name[32]``
82*4882a593Smuzhiyun	the name of the driver, as a zero-terminated ASCII string
83*4882a593Smuzhiyun``char revision[32]``
84*4882a593Smuzhiyun	the revision number of the driver, as a zero-terminated ASCII string
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun4.2 struct capi_ctr
87*4882a593Smuzhiyun-------------------
88*4882a593Smuzhiyun
89*4882a593SmuzhiyunThis structure describes an ISDN device (controller) handled by a Kernel CAPI
90*4882a593Smuzhiyundriver. After registration via the attach_capi_ctr() function it is passed to
91*4882a593Smuzhiyunall controller specific lower layer interface and callback functions to
92*4882a593Smuzhiyunidentify the controller to operate on.
93*4882a593Smuzhiyun
94*4882a593SmuzhiyunIt contains the following non-private fields:
95*4882a593Smuzhiyun
96*4882a593Smuzhiyunto be set by the driver before calling attach_capi_ctr():
97*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun``struct module *owner``
100*4882a593Smuzhiyun	pointer to the driver module owning the device
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun``void *driverdata``
103*4882a593Smuzhiyun	an opaque pointer to driver specific data, not touched by Kernel CAPI
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun``char name[32]``
106*4882a593Smuzhiyun	the name of the controller, as a zero-terminated ASCII string
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun``char *driver_name``
109*4882a593Smuzhiyun	the name of the driver, as a zero-terminated ASCII string
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun``int (*load_firmware)(struct capi_ctr *ctrlr, capiloaddata *ldata)``
112*4882a593Smuzhiyun	(optional) pointer to a callback function for sending firmware and
113*4882a593Smuzhiyun	configuration data to the device
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun	The function may return before the operation has completed.
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun	Completion must be signalled by a call to capi_ctr_ready().
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun	Return value: 0 on success, error code on error
120*4882a593Smuzhiyun	Called in process context.
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun``void (*reset_ctr)(struct capi_ctr *ctrlr)``
123*4882a593Smuzhiyun	(optional) pointer to a callback function for stopping the device,
124*4882a593Smuzhiyun	releasing all registered applications
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun	The function may return before the operation has completed.
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun	Completion must be signalled by a call to capi_ctr_down().
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun	Called in process context.
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun``void (*register_appl)(struct capi_ctr *ctrlr, u16 applid, capi_register_params *rparam)``
133*4882a593Smuzhiyun	pointers to callback function for registration of
134*4882a593Smuzhiyun	applications with the device
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun	Calls to these functions are serialized by Kernel CAPI so that only
137*4882a593Smuzhiyun	one call to any of them is active at any time.
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun``void (*release_appl)(struct capi_ctr *ctrlr, u16 applid)``
140*4882a593Smuzhiyun	pointers to callback functions deregistration of
141*4882a593Smuzhiyun	applications with the device
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun	Calls to these functions are serialized by Kernel CAPI so that only
144*4882a593Smuzhiyun	one call to any of them is active at any time.
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun``u16  (*send_message)(struct capi_ctr *ctrlr, struct sk_buff *skb)``
147*4882a593Smuzhiyun	pointer to a callback function for sending a CAPI message to the
148*4882a593Smuzhiyun	device
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun	Return value: CAPI error code
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun	If the method returns 0 (CAPI_NOERROR) the driver has taken ownership
153*4882a593Smuzhiyun	of the skb and the caller may no longer access it. If it returns a
154*4882a593Smuzhiyun	non-zero (error) value then ownership of the skb returns to the caller
155*4882a593Smuzhiyun	who may reuse or free it.
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun	The return value should only be used to signal problems with respect
158*4882a593Smuzhiyun	to accepting or queueing the message. Errors occurring during the
159*4882a593Smuzhiyun	actual processing of the message should be signaled with an
160*4882a593Smuzhiyun	appropriate reply message.
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun	May be called in process or interrupt context.
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun	Calls to this function are not serialized by Kernel CAPI, ie. it must
165*4882a593Smuzhiyun	be prepared to be re-entered.
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun``char *(*procinfo)(struct capi_ctr *ctrlr)``
168*4882a593Smuzhiyun	pointer to a callback function returning the entry for the device in
169*4882a593Smuzhiyun	the CAPI controller info table, /proc/capi/controller
170*4882a593Smuzhiyun
171*4882a593SmuzhiyunNote:
172*4882a593Smuzhiyun  Callback functions except send_message() are never called in interrupt
173*4882a593Smuzhiyun  context.
174*4882a593Smuzhiyun
175*4882a593Smuzhiyunto be filled in before calling capi_ctr_ready():
176*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun``u8 manu[CAPI_MANUFACTURER_LEN]``
179*4882a593Smuzhiyun	value to return for CAPI_GET_MANUFACTURER
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun``capi_version version``
182*4882a593Smuzhiyun	value to return for CAPI_GET_VERSION
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun``capi_profile profile``
185*4882a593Smuzhiyun	value to return for CAPI_GET_PROFILE
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun``u8 serial[CAPI_SERIAL_LEN]``
188*4882a593Smuzhiyun	value to return for CAPI_GET_SERIAL
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun4.3 SKBs
192*4882a593Smuzhiyun--------
193*4882a593Smuzhiyun
194*4882a593SmuzhiyunCAPI messages are passed between Kernel CAPI and the driver via send_message()
195*4882a593Smuzhiyunand capi_ctr_handle_message(), stored in the data portion of a socket buffer
196*4882a593Smuzhiyun(skb).  Each skb contains a single CAPI message coded according to the CAPI 2.0
197*4882a593Smuzhiyunstandard.
198*4882a593Smuzhiyun
199*4882a593SmuzhiyunFor the data transfer messages, DATA_B3_REQ and DATA_B3_IND, the actual
200*4882a593Smuzhiyunpayload data immediately follows the CAPI message itself within the same skb.
201*4882a593SmuzhiyunThe Data and Data64 parameters are not used for processing. The Data64
202*4882a593Smuzhiyunparameter may be omitted by setting the length field of the CAPI message to 22
203*4882a593Smuzhiyuninstead of 30.
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun4.4 The _cmsg Structure
207*4882a593Smuzhiyun-----------------------
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun(declared in <linux/isdn/capiutil.h>)
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunThe _cmsg structure stores the contents of a CAPI 2.0 message in an easily
212*4882a593Smuzhiyunaccessible form. It contains members for all possible CAPI 2.0 parameters,
213*4882a593Smuzhiyunincluding subparameters of the Additional Info and B Protocol structured
214*4882a593Smuzhiyunparameters, with the following exceptions:
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun* second Calling party number (CONNECT_IND)
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun* Data64 (DATA_B3_REQ and DATA_B3_IND)
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun* Sending complete (subparameter of Additional Info, CONNECT_REQ and INFO_REQ)
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun* Global Configuration (subparameter of B Protocol, CONNECT_REQ, CONNECT_RESP
223*4882a593Smuzhiyun  and SELECT_B_PROTOCOL_REQ)
224*4882a593Smuzhiyun
225*4882a593SmuzhiyunOnly those parameters appearing in the message type currently being processed
226*4882a593Smuzhiyunare actually used. Unused members should be set to zero.
227*4882a593Smuzhiyun
228*4882a593SmuzhiyunMembers are named after the CAPI 2.0 standard names of the parameters they
229*4882a593Smuzhiyunrepresent. See <linux/isdn/capiutil.h> for the exact spelling. Member data
230*4882a593Smuzhiyuntypes are:
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun=========== =================================================================
233*4882a593Smuzhiyunu8          for CAPI parameters of type 'byte'
234*4882a593Smuzhiyun
235*4882a593Smuzhiyunu16         for CAPI parameters of type 'word'
236*4882a593Smuzhiyun
237*4882a593Smuzhiyunu32         for CAPI parameters of type 'dword'
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun_cstruct    for CAPI parameters of type 'struct'
240*4882a593Smuzhiyun	    The member is a pointer to a buffer containing the parameter in
241*4882a593Smuzhiyun	    CAPI encoding (length + content). It may also be NULL, which will
242*4882a593Smuzhiyun	    be taken to represent an empty (zero length) parameter.
243*4882a593Smuzhiyun	    Subparameters are stored in encoded form within the content part.
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun_cmstruct   alternative representation for CAPI parameters of type 'struct'
246*4882a593Smuzhiyun	    (used only for the 'Additional Info' and 'B Protocol' parameters)
247*4882a593Smuzhiyun	    The representation is a single byte containing one of the values:
248*4882a593Smuzhiyun	    CAPI_DEFAULT: The parameter is empty/absent.
249*4882a593Smuzhiyun	    CAPI_COMPOSE: The parameter is present.
250*4882a593Smuzhiyun	    Subparameter values are stored individually in the corresponding
251*4882a593Smuzhiyun	    _cmsg structure members.
252*4882a593Smuzhiyun=========== =================================================================
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun5. Lower Layer Interface Functions
256*4882a593Smuzhiyun==================================
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun::
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun  int attach_capi_ctr(struct capi_ctr *ctrlr)
261*4882a593Smuzhiyun  int detach_capi_ctr(struct capi_ctr *ctrlr)
262*4882a593Smuzhiyun
263*4882a593Smuzhiyunregister/unregister a device (controller) with Kernel CAPI
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun::
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun  void capi_ctr_ready(struct capi_ctr *ctrlr)
268*4882a593Smuzhiyun  void capi_ctr_down(struct capi_ctr *ctrlr)
269*4882a593Smuzhiyun
270*4882a593Smuzhiyunsignal controller ready/not ready
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun::
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun  void capi_ctr_handle_message(struct capi_ctr * ctrlr, u16 applid,
275*4882a593Smuzhiyun			       struct sk_buff *skb)
276*4882a593Smuzhiyun
277*4882a593Smuzhiyunpass a received CAPI message to Kernel CAPI
278*4882a593Smuzhiyunfor forwarding to the specified application
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun6. Helper Functions and Macros
282*4882a593Smuzhiyun==============================
283*4882a593Smuzhiyun
284*4882a593SmuzhiyunMacros to extract/set element values from/in a CAPI message header
285*4882a593Smuzhiyun(from <linux/isdn/capiutil.h>):
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun======================  =============================   ====================
288*4882a593SmuzhiyunGet Macro		Set Macro			Element (Type)
289*4882a593Smuzhiyun======================  =============================   ====================
290*4882a593SmuzhiyunCAPIMSG_LEN(m)		CAPIMSG_SETLEN(m, len)		Total Length (u16)
291*4882a593SmuzhiyunCAPIMSG_APPID(m)	CAPIMSG_SETAPPID(m, applid)	ApplID (u16)
292*4882a593SmuzhiyunCAPIMSG_COMMAND(m)	CAPIMSG_SETCOMMAND(m,cmd)	Command (u8)
293*4882a593SmuzhiyunCAPIMSG_SUBCOMMAND(m)	CAPIMSG_SETSUBCOMMAND(m, cmd)	Subcommand (u8)
294*4882a593SmuzhiyunCAPIMSG_CMD(m)		-				Command*256
295*4882a593Smuzhiyun							+ Subcommand (u16)
296*4882a593SmuzhiyunCAPIMSG_MSGID(m)	CAPIMSG_SETMSGID(m, msgid)	Message Number (u16)
297*4882a593Smuzhiyun
298*4882a593SmuzhiyunCAPIMSG_CONTROL(m)	CAPIMSG_SETCONTROL(m, contr)	Controller/PLCI/NCCI
299*4882a593Smuzhiyun							(u32)
300*4882a593SmuzhiyunCAPIMSG_DATALEN(m)	CAPIMSG_SETDATALEN(m, len)	Data Length (u16)
301*4882a593Smuzhiyun======================  =============================   ====================
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun
304*4882a593SmuzhiyunLibrary functions for working with _cmsg structures
305*4882a593Smuzhiyun(from <linux/isdn/capiutil.h>):
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun``char *capi_cmd2str(u8 Command, u8 Subcommand)``
308*4882a593Smuzhiyun	Returns the CAPI 2.0 message name corresponding to the given command
309*4882a593Smuzhiyun	and subcommand values, as a static ASCII string. The return value may
310*4882a593Smuzhiyun	be NULL if the command/subcommand is not one of those defined in the
311*4882a593Smuzhiyun	CAPI 2.0 standard.
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun7. Debugging
315*4882a593Smuzhiyun============
316*4882a593Smuzhiyun
317*4882a593SmuzhiyunThe module kernelcapi has a module parameter showcapimsgs controlling some
318*4882a593Smuzhiyundebugging output produced by the module. It can only be set when the module is
319*4882a593Smuzhiyunloaded, via a parameter "showcapimsgs=<n>" to the modprobe command, either on
320*4882a593Smuzhiyunthe command line or in the configuration file.
321*4882a593Smuzhiyun
322*4882a593SmuzhiyunIf the lowest bit of showcapimsgs is set, kernelcapi logs controller and
323*4882a593Smuzhiyunapplication up and down events.
324*4882a593Smuzhiyun
325*4882a593SmuzhiyunIn addition, every registered CAPI controller has an associated traceflag
326*4882a593Smuzhiyunparameter controlling how CAPI messages sent from and to tha controller are
327*4882a593Smuzhiyunlogged. The traceflag parameter is initialized with the value of the
328*4882a593Smuzhiyunshowcapimsgs parameter when the controller is registered, but can later be
329*4882a593Smuzhiyunchanged via the MANUFACTURER_REQ command KCAPI_CMD_TRACE.
330*4882a593Smuzhiyun
331*4882a593SmuzhiyunIf the value of traceflag is non-zero, CAPI messages are logged.
332*4882a593SmuzhiyunDATA_B3 messages are only logged if the value of traceflag is > 2.
333*4882a593Smuzhiyun
334*4882a593SmuzhiyunIf the lowest bit of traceflag is set, only the command/subcommand and message
335*4882a593Smuzhiyunlength are logged. Otherwise, kernelcapi logs a readable representation of
336*4882a593Smuzhiyunthe entire message.
337