INTERFACE.CAPI 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. Kernel CAPI Interface to Hardware Drivers
  2. -----------------------------------------
  3. 1. Overview
  4. From the CAPI 2.0 specification:
  5. COMMON-ISDN-API (CAPI) is an application programming interface standard used
  6. to access ISDN equipment connected to basic rate interfaces (BRI) and primary
  7. rate interfaces (PRI).
  8. Kernel CAPI operates as a dispatching layer between CAPI applications and CAPI
  9. hardware drivers. Hardware drivers register ISDN devices (controllers, in CAPI
  10. lingo) with Kernel CAPI to indicate their readiness to provide their service
  11. to CAPI applications. CAPI applications also register with Kernel CAPI,
  12. requesting association with a CAPI device. Kernel CAPI then dispatches the
  13. application registration to an available device, forwarding it to the
  14. corresponding hardware driver. Kernel CAPI then forwards CAPI messages in both
  15. directions between the application and the hardware driver.
  16. Format and semantics of CAPI messages are specified in the CAPI 2.0 standard.
  17. This standard is freely available from http://www.capi.org.
  18. 2. Driver and Device Registration
  19. CAPI drivers optionally register themselves with Kernel CAPI by calling the
  20. Kernel CAPI function register_capi_driver() with a pointer to a struct
  21. capi_driver. This structure must be filled with the name and revision of the
  22. driver, and optionally a pointer to a callback function, add_card(). The
  23. registration can be revoked by calling the function unregister_capi_driver()
  24. with a pointer to the same struct capi_driver.
  25. CAPI drivers must register each of the ISDN devices they control with Kernel
  26. CAPI by calling the Kernel CAPI function attach_capi_ctr() with a pointer to a
  27. struct capi_ctr before they can be used. This structure must be filled with
  28. the names of the driver and controller, and a number of callback function
  29. pointers which are subsequently used by Kernel CAPI for communicating with the
  30. driver. The registration can be revoked by calling the function
  31. detach_capi_ctr() with a pointer to the same struct capi_ctr.
  32. Before the device can be actually used, the driver must fill in the device
  33. information fields 'manu', 'version', 'profile' and 'serial' in the capi_ctr
  34. structure of the device, and signal its readiness by calling capi_ctr_ready().
  35. From then on, Kernel CAPI may call the registered callback functions for the
  36. device.
  37. If the device becomes unusable for any reason (shutdown, disconnect ...), the
  38. driver has to call capi_ctr_down(). This will prevent further calls to the
  39. callback functions by Kernel CAPI.
  40. 3. Application Registration and Communication
  41. Kernel CAPI forwards registration requests from applications (calls to CAPI
  42. operation CAPI_REGISTER) to an appropriate hardware driver by calling its
  43. register_appl() callback function. A unique Application ID (ApplID, u16) is
  44. allocated by Kernel CAPI and passed to register_appl() along with the
  45. parameter structure provided by the application. This is analogous to the
  46. open() operation on regular files or character devices.
  47. After a successful return from register_appl(), CAPI messages from the
  48. application may be passed to the driver for the device via calls to the
  49. send_message() callback function. Conversely, the driver may call Kernel
  50. CAPI's capi_ctr_handle_message() function to pass a received CAPI message to
  51. Kernel CAPI for forwarding to an application, specifying its ApplID.
  52. Deregistration requests (CAPI operation CAPI_RELEASE) from applications are
  53. forwarded as calls to the release_appl() callback function, passing the same
  54. ApplID as with register_appl(). After return from release_appl(), no CAPI
  55. messages for that application may be passed to or from the device anymore.
  56. 4. Data Structures
  57. 4.1 struct capi_driver
  58. This structure describes a Kernel CAPI driver itself. It is used in the
  59. register_capi_driver() and unregister_capi_driver() functions, and contains
  60. the following non-private fields, all to be set by the driver before calling
  61. register_capi_driver():
  62. char name[32]
  63. the name of the driver, as a zero-terminated ASCII string
  64. char revision[32]
  65. the revision number of the driver, as a zero-terminated ASCII string
  66. int (*add_card)(struct capi_driver *driver, capicardparams *data)
  67. a callback function pointer (may be NULL)
  68. 4.2 struct capi_ctr
  69. This structure describes an ISDN device (controller) handled by a Kernel CAPI
  70. driver. After registration via the attach_capi_ctr() function it is passed to
  71. all controller specific lower layer interface and callback functions to
  72. identify the controller to operate on.
  73. It contains the following non-private fields:
  74. - to be set by the driver before calling attach_capi_ctr():
  75. struct module *owner
  76. pointer to the driver module owning the device
  77. void *driverdata
  78. an opaque pointer to driver specific data, not touched by Kernel CAPI
  79. char name[32]
  80. the name of the controller, as a zero-terminated ASCII string
  81. char *driver_name
  82. the name of the driver, as a zero-terminated ASCII string
  83. int (*load_firmware)(struct capi_ctr *ctrlr, capiloaddata *ldata)
  84. (optional) pointer to a callback function for sending firmware and
  85. configuration data to the device
  86. The function may return before the operation has completed.
  87. Completion must be signalled by a call to capi_ctr_ready().
  88. Return value: 0 on success, error code on error
  89. Called in process context.
  90. void (*reset_ctr)(struct capi_ctr *ctrlr)
  91. (optional) pointer to a callback function for stopping the device,
  92. releasing all registered applications
  93. The function may return before the operation has completed.
  94. Completion must be signalled by a call to capi_ctr_down().
  95. Called in process context.
  96. void (*register_appl)(struct capi_ctr *ctrlr, u16 applid,
  97. capi_register_params *rparam)
  98. void (*release_appl)(struct capi_ctr *ctrlr, u16 applid)
  99. pointers to callback functions for registration and deregistration of
  100. applications with the device
  101. Calls to these functions are serialized by Kernel CAPI so that only
  102. one call to any of them is active at any time.
  103. u16 (*send_message)(struct capi_ctr *ctrlr, struct sk_buff *skb)
  104. pointer to a callback function for sending a CAPI message to the
  105. device
  106. Return value: CAPI error code
  107. If the method returns 0 (CAPI_NOERROR) the driver has taken ownership
  108. of the skb and the caller may no longer access it. If it returns a
  109. non-zero (error) value then ownership of the skb returns to the caller
  110. who may reuse or free it.
  111. The return value should only be used to signal problems with respect
  112. to accepting or queueing the message. Errors occurring during the
  113. actual processing of the message should be signaled with an
  114. appropriate reply message.
  115. May be called in process or interrupt context.
  116. Calls to this function are not serialized by Kernel CAPI, ie. it must
  117. be prepared to be re-entered.
  118. char *(*procinfo)(struct capi_ctr *ctrlr)
  119. pointer to a callback function returning the entry for the device in
  120. the CAPI controller info table, /proc/capi/controller
  121. const struct file_operations *proc_fops
  122. pointers to callback functions for the device's proc file
  123. system entry, /proc/capi/controllers/<n>; pointer to the device's
  124. capi_ctr structure is available from struct proc_dir_entry::data
  125. which is available from struct inode.
  126. Note: Callback functions except send_message() are never called in interrupt
  127. context.
  128. - to be filled in before calling capi_ctr_ready():
  129. u8 manu[CAPI_MANUFACTURER_LEN]
  130. value to return for CAPI_GET_MANUFACTURER
  131. capi_version version
  132. value to return for CAPI_GET_VERSION
  133. capi_profile profile
  134. value to return for CAPI_GET_PROFILE
  135. u8 serial[CAPI_SERIAL_LEN]
  136. value to return for CAPI_GET_SERIAL
  137. 4.3 SKBs
  138. CAPI messages are passed between Kernel CAPI and the driver via send_message()
  139. and capi_ctr_handle_message(), stored in the data portion of a socket buffer
  140. (skb). Each skb contains a single CAPI message coded according to the CAPI 2.0
  141. standard.
  142. For the data transfer messages, DATA_B3_REQ and DATA_B3_IND, the actual
  143. payload data immediately follows the CAPI message itself within the same skb.
  144. The Data and Data64 parameters are not used for processing. The Data64
  145. parameter may be omitted by setting the length field of the CAPI message to 22
  146. instead of 30.
  147. 4.4 The _cmsg Structure
  148. (declared in <linux/isdn/capiutil.h>)
  149. The _cmsg structure stores the contents of a CAPI 2.0 message in an easily
  150. accessible form. It contains members for all possible CAPI 2.0 parameters,
  151. including subparameters of the Additional Info and B Protocol structured
  152. parameters, with the following exceptions:
  153. * second Calling party number (CONNECT_IND)
  154. * Data64 (DATA_B3_REQ and DATA_B3_IND)
  155. * Sending complete (subparameter of Additional Info, CONNECT_REQ and INFO_REQ)
  156. * Global Configuration (subparameter of B Protocol, CONNECT_REQ, CONNECT_RESP
  157. and SELECT_B_PROTOCOL_REQ)
  158. Only those parameters appearing in the message type currently being processed
  159. are actually used. Unused members should be set to zero.
  160. Members are named after the CAPI 2.0 standard names of the parameters they
  161. represent. See <linux/isdn/capiutil.h> for the exact spelling. Member data
  162. types are:
  163. u8 for CAPI parameters of type 'byte'
  164. u16 for CAPI parameters of type 'word'
  165. u32 for CAPI parameters of type 'dword'
  166. _cstruct for CAPI parameters of type 'struct'
  167. The member is a pointer to a buffer containing the parameter in
  168. CAPI encoding (length + content). It may also be NULL, which will
  169. be taken to represent an empty (zero length) parameter.
  170. Subparameters are stored in encoded form within the content part.
  171. _cmstruct alternative representation for CAPI parameters of type 'struct'
  172. (used only for the 'Additional Info' and 'B Protocol' parameters)
  173. The representation is a single byte containing one of the values:
  174. CAPI_DEFAULT: The parameter is empty/absent.
  175. CAPI_COMPOSE: The parameter is present.
  176. Subparameter values are stored individually in the corresponding
  177. _cmsg structure members.
  178. Functions capi_cmsg2message() and capi_message2cmsg() are provided to convert
  179. messages between their transport encoding described in the CAPI 2.0 standard
  180. and their _cmsg structure representation. Note that capi_cmsg2message() does
  181. not know or check the size of its destination buffer. The caller must make
  182. sure it is big enough to accommodate the resulting CAPI message.
  183. 5. Lower Layer Interface Functions
  184. (declared in <linux/isdn/capilli.h>)
  185. void register_capi_driver(struct capi_driver *drvr)
  186. void unregister_capi_driver(struct capi_driver *drvr)
  187. register/unregister a driver with Kernel CAPI
  188. int attach_capi_ctr(struct capi_ctr *ctrlr)
  189. int detach_capi_ctr(struct capi_ctr *ctrlr)
  190. register/unregister a device (controller) with Kernel CAPI
  191. void capi_ctr_ready(struct capi_ctr *ctrlr)
  192. void capi_ctr_down(struct capi_ctr *ctrlr)
  193. signal controller ready/not ready
  194. void capi_ctr_suspend_output(struct capi_ctr *ctrlr)
  195. void capi_ctr_resume_output(struct capi_ctr *ctrlr)
  196. signal suspend/resume
  197. void capi_ctr_handle_message(struct capi_ctr * ctrlr, u16 applid,
  198. struct sk_buff *skb)
  199. pass a received CAPI message to Kernel CAPI
  200. for forwarding to the specified application
  201. 6. Helper Functions and Macros
  202. Library functions (from <linux/isdn/capilli.h>):
  203. void capilib_new_ncci(struct list_head *head, u16 applid,
  204. u32 ncci, u32 winsize)
  205. void capilib_free_ncci(struct list_head *head, u16 applid, u32 ncci)
  206. void capilib_release_appl(struct list_head *head, u16 applid)
  207. void capilib_release(struct list_head *head)
  208. void capilib_data_b3_conf(struct list_head *head, u16 applid,
  209. u32 ncci, u16 msgid)
  210. u16 capilib_data_b3_req(struct list_head *head, u16 applid,
  211. u32 ncci, u16 msgid)
  212. Macros to extract/set element values from/in a CAPI message header
  213. (from <linux/isdn/capiutil.h>):
  214. Get Macro Set Macro Element (Type)
  215. CAPIMSG_LEN(m) CAPIMSG_SETLEN(m, len) Total Length (u16)
  216. CAPIMSG_APPID(m) CAPIMSG_SETAPPID(m, applid) ApplID (u16)
  217. CAPIMSG_COMMAND(m) CAPIMSG_SETCOMMAND(m,cmd) Command (u8)
  218. CAPIMSG_SUBCOMMAND(m) CAPIMSG_SETSUBCOMMAND(m, cmd) Subcommand (u8)
  219. CAPIMSG_CMD(m) - Command*256
  220. + Subcommand (u16)
  221. CAPIMSG_MSGID(m) CAPIMSG_SETMSGID(m, msgid) Message Number (u16)
  222. CAPIMSG_CONTROL(m) CAPIMSG_SETCONTROL(m, contr) Controller/PLCI/NCCI
  223. (u32)
  224. CAPIMSG_DATALEN(m) CAPIMSG_SETDATALEN(m, len) Data Length (u16)
  225. Library functions for working with _cmsg structures
  226. (from <linux/isdn/capiutil.h>):
  227. unsigned capi_cmsg2message(_cmsg *cmsg, u8 *msg)
  228. Assembles a CAPI 2.0 message from the parameters in *cmsg, storing the
  229. result in *msg.
  230. unsigned capi_message2cmsg(_cmsg *cmsg, u8 *msg)
  231. Disassembles the CAPI 2.0 message in *msg, storing the parameters in
  232. *cmsg.
  233. unsigned capi_cmsg_header(_cmsg *cmsg, u16 ApplId, u8 Command, u8 Subcommand,
  234. u16 Messagenumber, u32 Controller)
  235. Fills the header part and address field of the _cmsg structure *cmsg
  236. with the given values, zeroing the remainder of the structure so only
  237. parameters with non-default values need to be changed before sending
  238. the message.
  239. void capi_cmsg_answer(_cmsg *cmsg)
  240. Sets the low bit of the Subcommand field in *cmsg, thereby converting
  241. _REQ to _CONF and _IND to _RESP.
  242. char *capi_cmd2str(u8 Command, u8 Subcommand)
  243. Returns the CAPI 2.0 message name corresponding to the given command
  244. and subcommand values, as a static ASCII string. The return value may
  245. be NULL if the command/subcommand is not one of those defined in the
  246. CAPI 2.0 standard.
  247. 7. Debugging
  248. The module kernelcapi has a module parameter showcapimsgs controlling some
  249. debugging output produced by the module. It can only be set when the module is
  250. loaded, via a parameter "showcapimsgs=<n>" to the modprobe command, either on
  251. the command line or in the configuration file.
  252. If the lowest bit of showcapimsgs is set, kernelcapi logs controller and
  253. application up and down events.
  254. In addition, every registered CAPI controller has an associated traceflag
  255. parameter controlling how CAPI messages sent from and to tha controller are
  256. logged. The traceflag parameter is initialized with the value of the
  257. showcapimsgs parameter when the controller is registered, but can later be
  258. changed via the MANUFACTURER_REQ command KCAPI_CMD_TRACE.
  259. If the value of traceflag is non-zero, CAPI messages are logged.
  260. DATA_B3 messages are only logged if the value of traceflag is > 2.
  261. If the lowest bit of traceflag is set, only the command/subcommand and message
  262. length are logged. Otherwise, kernelcapi logs a readable representation of
  263. the entire message.