PageRenderTime 1154ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/isdn/gigaset/capi.c

https://github.com/Mengqi/linux-2.6
C | 1750 lines | 1221 code | 158 blank | 371 comment | 202 complexity | 571a79680a0cec6ddef693f962bb5441 MD5 | raw file
  1. /*
  2. * Kernel CAPI interface for the Gigaset driver
  3. *
  4. * Copyright (c) 2009 by Tilman Schmidt <tilman@imap.cc>.
  5. *
  6. * =====================================================================
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. * =====================================================================
  12. */
  13. #include "gigaset.h"
  14. #include <linux/proc_fs.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/isdn/capilli.h>
  17. #include <linux/isdn/capicmd.h>
  18. #include <linux/isdn/capiutil.h>
  19. /* missing from kernelcapi.h */
  20. #define CapiNcpiNotSupportedByProtocol 0x0001
  21. #define CapiFlagsNotSupportedByProtocol 0x0002
  22. #define CapiAlertAlreadySent 0x0003
  23. #define CapiFacilitySpecificFunctionNotSupported 0x3011
  24. /* missing from capicmd.h */
  25. #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
  26. #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
  27. #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
  28. #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
  29. #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
  30. #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
  31. #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
  32. #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
  33. #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
  34. /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
  35. #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
  36. #define CAPI_FACILITY_HANDSET 0x0000
  37. #define CAPI_FACILITY_DTMF 0x0001
  38. #define CAPI_FACILITY_V42BIS 0x0002
  39. #define CAPI_FACILITY_SUPPSVC 0x0003
  40. #define CAPI_FACILITY_WAKEUP 0x0004
  41. #define CAPI_FACILITY_LI 0x0005
  42. #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
  43. #define CAPI_SUPPSVC_LISTEN 0x0001
  44. /* missing from capiutil.h */
  45. #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
  46. #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
  47. #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
  48. #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
  49. #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
  50. #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
  51. #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
  52. #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
  53. /* parameters with differing location in DATA_B3_CONF/_RESP: */
  54. #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
  55. #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
  56. /* Flags (DATA_B3_REQ/_IND) */
  57. #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
  58. #define CAPI_FLAGS_RESERVED (~0x1f)
  59. /* buffer sizes */
  60. #define MAX_BC_OCTETS 11
  61. #define MAX_HLC_OCTETS 3
  62. #define MAX_NUMBER_DIGITS 20
  63. #define MAX_FMT_IE_LEN 20
  64. /* values for bcs->apconnstate */
  65. #define APCONN_NONE 0 /* inactive/listening */
  66. #define APCONN_SETUP 1 /* connecting */
  67. #define APCONN_ACTIVE 2 /* B channel up */
  68. /* registered application data structure */
  69. struct gigaset_capi_appl {
  70. struct list_head ctrlist;
  71. struct gigaset_capi_appl *bcnext;
  72. u16 id;
  73. struct capi_register_params rp;
  74. u16 nextMessageNumber;
  75. u32 listenInfoMask;
  76. u32 listenCIPmask;
  77. };
  78. /* CAPI specific controller data structure */
  79. struct gigaset_capi_ctr {
  80. struct capi_ctr ctr;
  81. struct list_head appls;
  82. struct sk_buff_head sendqueue;
  83. atomic_t sendqlen;
  84. /* two _cmsg structures possibly used concurrently: */
  85. _cmsg hcmsg; /* for message composition triggered from hardware */
  86. _cmsg acmsg; /* for dissection of messages sent from application */
  87. u8 bc_buf[MAX_BC_OCTETS+1];
  88. u8 hlc_buf[MAX_HLC_OCTETS+1];
  89. u8 cgpty_buf[MAX_NUMBER_DIGITS+3];
  90. u8 cdpty_buf[MAX_NUMBER_DIGITS+2];
  91. };
  92. /* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
  93. static struct {
  94. u8 *bc;
  95. u8 *hlc;
  96. } cip2bchlc[] = {
  97. [1] = { "8090A3", NULL },
  98. /* Speech (A-law) */
  99. [2] = { "8890", NULL },
  100. /* Unrestricted digital information */
  101. [3] = { "8990", NULL },
  102. /* Restricted digital information */
  103. [4] = { "9090A3", NULL },
  104. /* 3,1 kHz audio (A-law) */
  105. [5] = { "9190", NULL },
  106. /* 7 kHz audio */
  107. [6] = { "9890", NULL },
  108. /* Video */
  109. [7] = { "88C0C6E6", NULL },
  110. /* Packet mode */
  111. [8] = { "8890218F", NULL },
  112. /* 56 kbit/s rate adaptation */
  113. [9] = { "9190A5", NULL },
  114. /* Unrestricted digital information with tones/announcements */
  115. [16] = { "8090A3", "9181" },
  116. /* Telephony */
  117. [17] = { "9090A3", "9184" },
  118. /* Group 2/3 facsimile */
  119. [18] = { "8890", "91A1" },
  120. /* Group 4 facsimile Class 1 */
  121. [19] = { "8890", "91A4" },
  122. /* Teletex service basic and mixed mode
  123. and Group 4 facsimile service Classes II and III */
  124. [20] = { "8890", "91A8" },
  125. /* Teletex service basic and processable mode */
  126. [21] = { "8890", "91B1" },
  127. /* Teletex service basic mode */
  128. [22] = { "8890", "91B2" },
  129. /* International interworking for Videotex */
  130. [23] = { "8890", "91B5" },
  131. /* Telex */
  132. [24] = { "8890", "91B8" },
  133. /* Message Handling Systems in accordance with X.400 */
  134. [25] = { "8890", "91C1" },
  135. /* OSI application in accordance with X.200 */
  136. [26] = { "9190A5", "9181" },
  137. /* 7 kHz telephony */
  138. [27] = { "9190A5", "916001" },
  139. /* Video telephony, first connection */
  140. [28] = { "8890", "916002" },
  141. /* Video telephony, second connection */
  142. };
  143. /*
  144. * helper functions
  145. * ================
  146. */
  147. /*
  148. * emit unsupported parameter warning
  149. */
  150. static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
  151. char *msgname, char *paramname)
  152. {
  153. if (param && *param)
  154. dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
  155. msgname, paramname);
  156. }
  157. /*
  158. * convert an IE from Gigaset hex string to ETSI binary representation
  159. * including length byte
  160. * return value: result length, -1 on error
  161. */
  162. static int encode_ie(char *in, u8 *out, int maxlen)
  163. {
  164. int l = 0;
  165. while (*in) {
  166. if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
  167. return -1;
  168. out[++l] = (hex_to_bin(in[0]) << 4) + hex_to_bin(in[1]);
  169. in += 2;
  170. }
  171. out[0] = l;
  172. return l;
  173. }
  174. /*
  175. * convert an IE from ETSI binary representation including length byte
  176. * to Gigaset hex string
  177. */
  178. static void decode_ie(u8 *in, char *out)
  179. {
  180. int i = *in;
  181. while (i-- > 0) {
  182. /* ToDo: conversion to upper case necessary? */
  183. *out++ = toupper(hex_asc_hi(*++in));
  184. *out++ = toupper(hex_asc_lo(*in));
  185. }
  186. }
  187. /*
  188. * retrieve application data structure for an application ID
  189. */
  190. static inline struct gigaset_capi_appl *
  191. get_appl(struct gigaset_capi_ctr *iif, u16 appl)
  192. {
  193. struct gigaset_capi_appl *ap;
  194. list_for_each_entry(ap, &iif->appls, ctrlist)
  195. if (ap->id == appl)
  196. return ap;
  197. return NULL;
  198. }
  199. /*
  200. * dump CAPI message to kernel messages for debugging
  201. */
  202. static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
  203. {
  204. #ifdef CONFIG_GIGASET_DEBUG
  205. _cdebbuf *cdb;
  206. if (!(gigaset_debuglevel & level))
  207. return;
  208. cdb = capi_cmsg2str(p);
  209. if (cdb) {
  210. gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
  211. cdebbuf_free(cdb);
  212. } else {
  213. gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
  214. capi_cmd2str(p->Command, p->Subcommand));
  215. }
  216. #endif
  217. }
  218. static inline void dump_rawmsg(enum debuglevel level, const char *tag,
  219. unsigned char *data)
  220. {
  221. #ifdef CONFIG_GIGASET_DEBUG
  222. char *dbgline;
  223. int i, l;
  224. if (!(gigaset_debuglevel & level))
  225. return;
  226. l = CAPIMSG_LEN(data);
  227. if (l < 12) {
  228. gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
  229. return;
  230. }
  231. gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
  232. tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
  233. CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
  234. CAPIMSG_CONTROL(data));
  235. l -= 12;
  236. dbgline = kmalloc(3*l, GFP_ATOMIC);
  237. if (!dbgline)
  238. return;
  239. for (i = 0; i < l; i++) {
  240. dbgline[3*i] = hex_asc_hi(data[12+i]);
  241. dbgline[3*i+1] = hex_asc_lo(data[12+i]);
  242. dbgline[3*i+2] = ' ';
  243. }
  244. dbgline[3*l-1] = '\0';
  245. gig_dbg(level, " %s", dbgline);
  246. kfree(dbgline);
  247. if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
  248. (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
  249. CAPIMSG_SUBCOMMAND(data) == CAPI_IND)) {
  250. l = CAPIMSG_DATALEN(data);
  251. gig_dbg(level, " DataLength=%d", l);
  252. if (l <= 0 || !(gigaset_debuglevel & DEBUG_LLDATA))
  253. return;
  254. if (l > 64)
  255. l = 64; /* arbitrary limit */
  256. dbgline = kmalloc(3*l, GFP_ATOMIC);
  257. if (!dbgline)
  258. return;
  259. data += CAPIMSG_LEN(data);
  260. for (i = 0; i < l; i++) {
  261. dbgline[3*i] = hex_asc_hi(data[i]);
  262. dbgline[3*i+1] = hex_asc_lo(data[i]);
  263. dbgline[3*i+2] = ' ';
  264. }
  265. dbgline[3*l-1] = '\0';
  266. gig_dbg(level, " %s", dbgline);
  267. kfree(dbgline);
  268. }
  269. #endif
  270. }
  271. /*
  272. * format CAPI IE as string
  273. */
  274. static const char *format_ie(const char *ie)
  275. {
  276. static char result[3*MAX_FMT_IE_LEN];
  277. int len, count;
  278. char *pout = result;
  279. if (!ie)
  280. return "NULL";
  281. count = len = ie[0];
  282. if (count > MAX_FMT_IE_LEN)
  283. count = MAX_FMT_IE_LEN-1;
  284. while (count--) {
  285. *pout++ = hex_asc_hi(*++ie);
  286. *pout++ = hex_asc_lo(*ie);
  287. *pout++ = ' ';
  288. }
  289. if (len > MAX_FMT_IE_LEN) {
  290. *pout++ = '.';
  291. *pout++ = '.';
  292. *pout++ = '.';
  293. }
  294. *--pout = 0;
  295. return result;
  296. }
  297. /*
  298. * emit DATA_B3_CONF message
  299. */
  300. static void send_data_b3_conf(struct cardstate *cs, struct capi_ctr *ctr,
  301. u16 appl, u16 msgid, int channel,
  302. u16 handle, u16 info)
  303. {
  304. struct sk_buff *cskb;
  305. u8 *msg;
  306. cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
  307. if (!cskb) {
  308. dev_err(cs->dev, "%s: out of memory\n", __func__);
  309. return;
  310. }
  311. /* frequent message, avoid _cmsg overhead */
  312. msg = __skb_put(cskb, CAPI_DATA_B3_CONF_LEN);
  313. CAPIMSG_SETLEN(msg, CAPI_DATA_B3_CONF_LEN);
  314. CAPIMSG_SETAPPID(msg, appl);
  315. CAPIMSG_SETCOMMAND(msg, CAPI_DATA_B3);
  316. CAPIMSG_SETSUBCOMMAND(msg, CAPI_CONF);
  317. CAPIMSG_SETMSGID(msg, msgid);
  318. CAPIMSG_SETCONTROLLER(msg, ctr->cnr);
  319. CAPIMSG_SETPLCI_PART(msg, channel);
  320. CAPIMSG_SETNCCI_PART(msg, 1);
  321. CAPIMSG_SETHANDLE_CONF(msg, handle);
  322. CAPIMSG_SETINFO_CONF(msg, info);
  323. /* emit message */
  324. dump_rawmsg(DEBUG_MCMD, __func__, msg);
  325. capi_ctr_handle_message(ctr, appl, cskb);
  326. }
  327. /*
  328. * driver interface functions
  329. * ==========================
  330. */
  331. /**
  332. * gigaset_skb_sent() - acknowledge transmission of outgoing skb
  333. * @bcs: B channel descriptor structure.
  334. * @skb: sent data.
  335. *
  336. * Called by hardware module {bas,ser,usb}_gigaset when the data in a
  337. * skb has been successfully sent, for signalling completion to the LL.
  338. */
  339. void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
  340. {
  341. struct cardstate *cs = bcs->cs;
  342. struct gigaset_capi_ctr *iif = cs->iif;
  343. struct gigaset_capi_appl *ap = bcs->ap;
  344. unsigned char *req = skb_mac_header(dskb);
  345. u16 flags;
  346. /* update statistics */
  347. ++bcs->trans_up;
  348. if (!ap) {
  349. gig_dbg(DEBUG_MCMD, "%s: application gone", __func__);
  350. return;
  351. }
  352. /* don't send further B3 messages if disconnected */
  353. if (bcs->apconnstate < APCONN_ACTIVE) {
  354. gig_dbg(DEBUG_MCMD, "%s: disconnected", __func__);
  355. return;
  356. }
  357. /*
  358. * send DATA_B3_CONF if "delivery confirmation" bit was set in request;
  359. * otherwise it has already been sent by do_data_b3_req()
  360. */
  361. flags = CAPIMSG_FLAGS(req);
  362. if (flags & CAPI_FLAGS_DELIVERY_CONFIRMATION)
  363. send_data_b3_conf(cs, &iif->ctr, ap->id, CAPIMSG_MSGID(req),
  364. bcs->channel + 1, CAPIMSG_HANDLE_REQ(req),
  365. (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION) ?
  366. CapiFlagsNotSupportedByProtocol :
  367. CAPI_NOERROR);
  368. }
  369. EXPORT_SYMBOL_GPL(gigaset_skb_sent);
  370. /**
  371. * gigaset_skb_rcvd() - pass received skb to LL
  372. * @bcs: B channel descriptor structure.
  373. * @skb: received data.
  374. *
  375. * Called by hardware module {bas,ser,usb}_gigaset when user data has
  376. * been successfully received, for passing to the LL.
  377. * Warning: skb must not be accessed anymore!
  378. */
  379. void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
  380. {
  381. struct cardstate *cs = bcs->cs;
  382. struct gigaset_capi_ctr *iif = cs->iif;
  383. struct gigaset_capi_appl *ap = bcs->ap;
  384. int len = skb->len;
  385. /* update statistics */
  386. bcs->trans_down++;
  387. if (!ap) {
  388. gig_dbg(DEBUG_MCMD, "%s: application gone", __func__);
  389. dev_kfree_skb_any(skb);
  390. return;
  391. }
  392. /* don't send further B3 messages if disconnected */
  393. if (bcs->apconnstate < APCONN_ACTIVE) {
  394. gig_dbg(DEBUG_MCMD, "%s: disconnected", __func__);
  395. dev_kfree_skb_any(skb);
  396. return;
  397. }
  398. /*
  399. * prepend DATA_B3_IND message to payload
  400. * Parameters: NCCI = 1, all others 0/unused
  401. * frequent message, avoid _cmsg overhead
  402. */
  403. skb_push(skb, CAPI_DATA_B3_REQ_LEN);
  404. CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
  405. CAPIMSG_SETAPPID(skb->data, ap->id);
  406. CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
  407. CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
  408. CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
  409. CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
  410. CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
  411. CAPIMSG_SETNCCI_PART(skb->data, 1);
  412. /* Data parameter not used */
  413. CAPIMSG_SETDATALEN(skb->data, len);
  414. /* Data handle parameter not used */
  415. CAPIMSG_SETFLAGS(skb->data, 0);
  416. /* Data64 parameter not present */
  417. /* emit message */
  418. dump_rawmsg(DEBUG_MCMD, __func__, skb->data);
  419. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  420. }
  421. EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
  422. /**
  423. * gigaset_isdn_rcv_err() - signal receive error
  424. * @bcs: B channel descriptor structure.
  425. *
  426. * Called by hardware module {bas,ser,usb}_gigaset when a receive error
  427. * has occurred, for signalling to the LL.
  428. */
  429. void gigaset_isdn_rcv_err(struct bc_state *bcs)
  430. {
  431. /* if currently ignoring packets, just count down */
  432. if (bcs->ignore) {
  433. bcs->ignore--;
  434. return;
  435. }
  436. /* update statistics */
  437. bcs->corrupted++;
  438. /* ToDo: signal error -> LL */
  439. }
  440. EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
  441. /**
  442. * gigaset_isdn_icall() - signal incoming call
  443. * @at_state: connection state structure.
  444. *
  445. * Called by main module at tasklet level to notify the LL that an incoming
  446. * call has been received. @at_state contains the parameters of the call.
  447. *
  448. * Return value: call disposition (ICALL_*)
  449. */
  450. int gigaset_isdn_icall(struct at_state_t *at_state)
  451. {
  452. struct cardstate *cs = at_state->cs;
  453. struct bc_state *bcs = at_state->bcs;
  454. struct gigaset_capi_ctr *iif = cs->iif;
  455. struct gigaset_capi_appl *ap;
  456. u32 actCIPmask;
  457. struct sk_buff *skb;
  458. unsigned int msgsize;
  459. unsigned long flags;
  460. int i;
  461. /*
  462. * ToDo: signal calls without a free B channel, too
  463. * (requires a u8 handle for the at_state structure that can
  464. * be stored in the PLCI and used in the CONNECT_RESP message
  465. * handler to retrieve it)
  466. */
  467. if (!bcs)
  468. return ICALL_IGNORE;
  469. /* prepare CONNECT_IND message, using B channel number as PLCI */
  470. capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
  471. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  472. /* minimum size, all structs empty */
  473. msgsize = CAPI_CONNECT_IND_BASELEN;
  474. /* Bearer Capability (mandatory) */
  475. if (at_state->str_var[STR_ZBC]) {
  476. /* pass on BC from Gigaset */
  477. if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
  478. MAX_BC_OCTETS) < 0) {
  479. dev_warn(cs->dev, "RING ignored - bad BC %s\n",
  480. at_state->str_var[STR_ZBC]);
  481. return ICALL_IGNORE;
  482. }
  483. /* look up corresponding CIP value */
  484. iif->hcmsg.CIPValue = 0; /* default if nothing found */
  485. for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
  486. if (cip2bchlc[i].bc != NULL &&
  487. cip2bchlc[i].hlc == NULL &&
  488. !strcmp(cip2bchlc[i].bc,
  489. at_state->str_var[STR_ZBC])) {
  490. iif->hcmsg.CIPValue = i;
  491. break;
  492. }
  493. } else {
  494. /* no BC (internal call): assume CIP 1 (speech, A-law) */
  495. iif->hcmsg.CIPValue = 1;
  496. encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
  497. }
  498. iif->hcmsg.BC = iif->bc_buf;
  499. msgsize += iif->hcmsg.BC[0];
  500. /* High Layer Compatibility (optional) */
  501. if (at_state->str_var[STR_ZHLC]) {
  502. /* pass on HLC from Gigaset */
  503. if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
  504. MAX_HLC_OCTETS) < 0) {
  505. dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
  506. at_state->str_var[STR_ZHLC]);
  507. return ICALL_IGNORE;
  508. }
  509. iif->hcmsg.HLC = iif->hlc_buf;
  510. msgsize += iif->hcmsg.HLC[0];
  511. /* look up corresponding CIP value */
  512. /* keep BC based CIP value if none found */
  513. if (at_state->str_var[STR_ZBC])
  514. for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
  515. if (cip2bchlc[i].hlc != NULL &&
  516. !strcmp(cip2bchlc[i].hlc,
  517. at_state->str_var[STR_ZHLC]) &&
  518. !strcmp(cip2bchlc[i].bc,
  519. at_state->str_var[STR_ZBC])) {
  520. iif->hcmsg.CIPValue = i;
  521. break;
  522. }
  523. }
  524. /* Called Party Number (optional) */
  525. if (at_state->str_var[STR_ZCPN]) {
  526. i = strlen(at_state->str_var[STR_ZCPN]);
  527. if (i > MAX_NUMBER_DIGITS) {
  528. dev_warn(cs->dev, "RING ignored - bad number %s\n",
  529. at_state->str_var[STR_ZBC]);
  530. return ICALL_IGNORE;
  531. }
  532. iif->cdpty_buf[0] = i + 1;
  533. iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
  534. memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
  535. iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
  536. msgsize += iif->hcmsg.CalledPartyNumber[0];
  537. }
  538. /* Calling Party Number (optional) */
  539. if (at_state->str_var[STR_NMBR]) {
  540. i = strlen(at_state->str_var[STR_NMBR]);
  541. if (i > MAX_NUMBER_DIGITS) {
  542. dev_warn(cs->dev, "RING ignored - bad number %s\n",
  543. at_state->str_var[STR_ZBC]);
  544. return ICALL_IGNORE;
  545. }
  546. iif->cgpty_buf[0] = i + 2;
  547. iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
  548. iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
  549. memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
  550. iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
  551. msgsize += iif->hcmsg.CallingPartyNumber[0];
  552. }
  553. /* remaining parameters (not supported, always left NULL):
  554. * - CalledPartySubaddress
  555. * - CallingPartySubaddress
  556. * - AdditionalInfo
  557. * - BChannelinformation
  558. * - Keypadfacility
  559. * - Useruserdata
  560. * - Facilitydataarray
  561. */
  562. gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
  563. iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
  564. format_ie(iif->hcmsg.BC));
  565. gig_dbg(DEBUG_CMD, "icall: HLC %s",
  566. format_ie(iif->hcmsg.HLC));
  567. gig_dbg(DEBUG_CMD, "icall: CgPty %s",
  568. format_ie(iif->hcmsg.CallingPartyNumber));
  569. gig_dbg(DEBUG_CMD, "icall: CdPty %s",
  570. format_ie(iif->hcmsg.CalledPartyNumber));
  571. /* scan application list for matching listeners */
  572. spin_lock_irqsave(&bcs->aplock, flags);
  573. if (bcs->ap != NULL || bcs->apconnstate != APCONN_NONE) {
  574. dev_warn(cs->dev, "%s: channel not properly cleared (%p/%d)\n",
  575. __func__, bcs->ap, bcs->apconnstate);
  576. bcs->ap = NULL;
  577. bcs->apconnstate = APCONN_NONE;
  578. }
  579. spin_unlock_irqrestore(&bcs->aplock, flags);
  580. actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
  581. list_for_each_entry(ap, &iif->appls, ctrlist)
  582. if (actCIPmask & ap->listenCIPmask) {
  583. /* build CONNECT_IND message for this application */
  584. iif->hcmsg.ApplId = ap->id;
  585. iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
  586. skb = alloc_skb(msgsize, GFP_ATOMIC);
  587. if (!skb) {
  588. dev_err(cs->dev, "%s: out of memory\n",
  589. __func__);
  590. break;
  591. }
  592. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  593. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  594. /* add to listeners on this B channel, update state */
  595. spin_lock_irqsave(&bcs->aplock, flags);
  596. ap->bcnext = bcs->ap;
  597. bcs->ap = ap;
  598. bcs->chstate |= CHS_NOTIFY_LL;
  599. bcs->apconnstate = APCONN_SETUP;
  600. spin_unlock_irqrestore(&bcs->aplock, flags);
  601. /* emit message */
  602. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  603. }
  604. /*
  605. * Return "accept" if any listeners.
  606. * Gigaset will send ALERTING.
  607. * There doesn't seem to be a way to avoid this.
  608. */
  609. return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
  610. }
  611. /*
  612. * send a DISCONNECT_IND message to an application
  613. * does not sleep, clobbers the controller's hcmsg structure
  614. */
  615. static void send_disconnect_ind(struct bc_state *bcs,
  616. struct gigaset_capi_appl *ap, u16 reason)
  617. {
  618. struct cardstate *cs = bcs->cs;
  619. struct gigaset_capi_ctr *iif = cs->iif;
  620. struct sk_buff *skb;
  621. if (bcs->apconnstate == APCONN_NONE)
  622. return;
  623. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
  624. ap->nextMessageNumber++,
  625. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  626. iif->hcmsg.Reason = reason;
  627. skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
  628. if (!skb) {
  629. dev_err(cs->dev, "%s: out of memory\n", __func__);
  630. return;
  631. }
  632. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
  633. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  634. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  635. }
  636. /*
  637. * send a DISCONNECT_B3_IND message to an application
  638. * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
  639. * does not sleep, clobbers the controller's hcmsg structure
  640. */
  641. static void send_disconnect_b3_ind(struct bc_state *bcs,
  642. struct gigaset_capi_appl *ap)
  643. {
  644. struct cardstate *cs = bcs->cs;
  645. struct gigaset_capi_ctr *iif = cs->iif;
  646. struct sk_buff *skb;
  647. /* nothing to do if no logical connection active */
  648. if (bcs->apconnstate < APCONN_ACTIVE)
  649. return;
  650. bcs->apconnstate = APCONN_SETUP;
  651. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
  652. ap->nextMessageNumber++,
  653. iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
  654. skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
  655. if (!skb) {
  656. dev_err(cs->dev, "%s: out of memory\n", __func__);
  657. return;
  658. }
  659. capi_cmsg2message(&iif->hcmsg,
  660. __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
  661. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  662. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  663. }
  664. /**
  665. * gigaset_isdn_connD() - signal D channel connect
  666. * @bcs: B channel descriptor structure.
  667. *
  668. * Called by main module at tasklet level to notify the LL that the D channel
  669. * connection has been established.
  670. */
  671. void gigaset_isdn_connD(struct bc_state *bcs)
  672. {
  673. struct cardstate *cs = bcs->cs;
  674. struct gigaset_capi_ctr *iif = cs->iif;
  675. struct gigaset_capi_appl *ap;
  676. struct sk_buff *skb;
  677. unsigned int msgsize;
  678. unsigned long flags;
  679. spin_lock_irqsave(&bcs->aplock, flags);
  680. ap = bcs->ap;
  681. if (!ap) {
  682. spin_unlock_irqrestore(&bcs->aplock, flags);
  683. gig_dbg(DEBUG_CMD, "%s: application gone", __func__);
  684. return;
  685. }
  686. if (bcs->apconnstate == APCONN_NONE) {
  687. spin_unlock_irqrestore(&bcs->aplock, flags);
  688. dev_warn(cs->dev, "%s: application %u not connected\n",
  689. __func__, ap->id);
  690. return;
  691. }
  692. spin_unlock_irqrestore(&bcs->aplock, flags);
  693. while (ap->bcnext) {
  694. /* this should never happen */
  695. dev_warn(cs->dev, "%s: dropping extra application %u\n",
  696. __func__, ap->bcnext->id);
  697. send_disconnect_ind(bcs, ap->bcnext,
  698. CapiCallGivenToOtherApplication);
  699. ap->bcnext = ap->bcnext->bcnext;
  700. }
  701. /* prepare CONNECT_ACTIVE_IND message
  702. * Note: LLC not supported by device
  703. */
  704. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
  705. ap->nextMessageNumber++,
  706. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  707. /* minimum size, all structs empty */
  708. msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
  709. /* ToDo: set parameter: Connected number
  710. * (requires ev-layer state machine extension to collect
  711. * ZCON device reply)
  712. */
  713. /* build and emit CONNECT_ACTIVE_IND message */
  714. skb = alloc_skb(msgsize, GFP_ATOMIC);
  715. if (!skb) {
  716. dev_err(cs->dev, "%s: out of memory\n", __func__);
  717. return;
  718. }
  719. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  720. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  721. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  722. }
  723. /**
  724. * gigaset_isdn_hupD() - signal D channel hangup
  725. * @bcs: B channel descriptor structure.
  726. *
  727. * Called by main module at tasklet level to notify the LL that the D channel
  728. * connection has been shut down.
  729. */
  730. void gigaset_isdn_hupD(struct bc_state *bcs)
  731. {
  732. struct gigaset_capi_appl *ap;
  733. unsigned long flags;
  734. /*
  735. * ToDo: pass on reason code reported by device
  736. * (requires ev-layer state machine extension to collect
  737. * ZCAU device reply)
  738. */
  739. spin_lock_irqsave(&bcs->aplock, flags);
  740. while (bcs->ap != NULL) {
  741. ap = bcs->ap;
  742. bcs->ap = ap->bcnext;
  743. spin_unlock_irqrestore(&bcs->aplock, flags);
  744. send_disconnect_b3_ind(bcs, ap);
  745. send_disconnect_ind(bcs, ap, 0);
  746. spin_lock_irqsave(&bcs->aplock, flags);
  747. }
  748. bcs->apconnstate = APCONN_NONE;
  749. spin_unlock_irqrestore(&bcs->aplock, flags);
  750. }
  751. /**
  752. * gigaset_isdn_connB() - signal B channel connect
  753. * @bcs: B channel descriptor structure.
  754. *
  755. * Called by main module at tasklet level to notify the LL that the B channel
  756. * connection has been established.
  757. */
  758. void gigaset_isdn_connB(struct bc_state *bcs)
  759. {
  760. struct cardstate *cs = bcs->cs;
  761. struct gigaset_capi_ctr *iif = cs->iif;
  762. struct gigaset_capi_appl *ap;
  763. struct sk_buff *skb;
  764. unsigned long flags;
  765. unsigned int msgsize;
  766. u8 command;
  767. spin_lock_irqsave(&bcs->aplock, flags);
  768. ap = bcs->ap;
  769. if (!ap) {
  770. spin_unlock_irqrestore(&bcs->aplock, flags);
  771. gig_dbg(DEBUG_CMD, "%s: application gone", __func__);
  772. return;
  773. }
  774. if (!bcs->apconnstate) {
  775. spin_unlock_irqrestore(&bcs->aplock, flags);
  776. dev_warn(cs->dev, "%s: application %u not connected\n",
  777. __func__, ap->id);
  778. return;
  779. }
  780. /*
  781. * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
  782. * otherwise we have to emit CONNECT_B3_IND first, and follow up with
  783. * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
  784. * Parameters in both cases always: NCCI = 1, NCPI empty
  785. */
  786. if (bcs->apconnstate >= APCONN_ACTIVE) {
  787. command = CAPI_CONNECT_B3_ACTIVE;
  788. msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
  789. } else {
  790. command = CAPI_CONNECT_B3;
  791. msgsize = CAPI_CONNECT_B3_IND_BASELEN;
  792. }
  793. bcs->apconnstate = APCONN_ACTIVE;
  794. spin_unlock_irqrestore(&bcs->aplock, flags);
  795. while (ap->bcnext) {
  796. /* this should never happen */
  797. dev_warn(cs->dev, "%s: dropping extra application %u\n",
  798. __func__, ap->bcnext->id);
  799. send_disconnect_ind(bcs, ap->bcnext,
  800. CapiCallGivenToOtherApplication);
  801. ap->bcnext = ap->bcnext->bcnext;
  802. }
  803. capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
  804. ap->nextMessageNumber++,
  805. iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
  806. skb = alloc_skb(msgsize, GFP_ATOMIC);
  807. if (!skb) {
  808. dev_err(cs->dev, "%s: out of memory\n", __func__);
  809. return;
  810. }
  811. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  812. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  813. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  814. }
  815. /**
  816. * gigaset_isdn_hupB() - signal B channel hangup
  817. * @bcs: B channel descriptor structure.
  818. *
  819. * Called by main module to notify the LL that the B channel connection has
  820. * been shut down.
  821. */
  822. void gigaset_isdn_hupB(struct bc_state *bcs)
  823. {
  824. struct gigaset_capi_appl *ap = bcs->ap;
  825. /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
  826. if (!ap) {
  827. gig_dbg(DEBUG_CMD, "%s: application gone", __func__);
  828. return;
  829. }
  830. send_disconnect_b3_ind(bcs, ap);
  831. }
  832. /**
  833. * gigaset_isdn_start() - signal device availability
  834. * @cs: device descriptor structure.
  835. *
  836. * Called by main module to notify the LL that the device is available for
  837. * use.
  838. */
  839. void gigaset_isdn_start(struct cardstate *cs)
  840. {
  841. struct gigaset_capi_ctr *iif = cs->iif;
  842. /* fill profile data: manufacturer name */
  843. strcpy(iif->ctr.manu, "Siemens");
  844. /* CAPI and device version */
  845. iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
  846. iif->ctr.version.minorversion = 0;
  847. /* ToDo: check/assert cs->gotfwver? */
  848. iif->ctr.version.majormanuversion = cs->fwver[0];
  849. iif->ctr.version.minormanuversion = cs->fwver[1];
  850. /* number of B channels supported */
  851. iif->ctr.profile.nbchannel = cs->channels;
  852. /* global options: internal controller, supplementary services */
  853. iif->ctr.profile.goptions = 0x11;
  854. /* B1 protocols: 64 kbit/s HDLC or transparent */
  855. iif->ctr.profile.support1 = 0x03;
  856. /* B2 protocols: transparent only */
  857. /* ToDo: X.75 SLP ? */
  858. iif->ctr.profile.support2 = 0x02;
  859. /* B3 protocols: transparent only */
  860. iif->ctr.profile.support3 = 0x01;
  861. /* no serial number */
  862. strcpy(iif->ctr.serial, "0");
  863. capi_ctr_ready(&iif->ctr);
  864. }
  865. /**
  866. * gigaset_isdn_stop() - signal device unavailability
  867. * @cs: device descriptor structure.
  868. *
  869. * Called by main module to notify the LL that the device is no longer
  870. * available for use.
  871. */
  872. void gigaset_isdn_stop(struct cardstate *cs)
  873. {
  874. struct gigaset_capi_ctr *iif = cs->iif;
  875. capi_ctr_down(&iif->ctr);
  876. }
  877. /*
  878. * kernel CAPI callback methods
  879. * ============================
  880. */
  881. /*
  882. * register CAPI application
  883. */
  884. static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
  885. capi_register_params *rp)
  886. {
  887. struct gigaset_capi_ctr *iif
  888. = container_of(ctr, struct gigaset_capi_ctr, ctr);
  889. struct cardstate *cs = ctr->driverdata;
  890. struct gigaset_capi_appl *ap;
  891. gig_dbg(DEBUG_CMD, "%s [%u] l3cnt=%u blkcnt=%u blklen=%u",
  892. __func__, appl, rp->level3cnt, rp->datablkcnt, rp->datablklen);
  893. list_for_each_entry(ap, &iif->appls, ctrlist)
  894. if (ap->id == appl) {
  895. dev_notice(cs->dev,
  896. "application %u already registered\n", appl);
  897. return;
  898. }
  899. ap = kzalloc(sizeof(*ap), GFP_KERNEL);
  900. if (!ap) {
  901. dev_err(cs->dev, "%s: out of memory\n", __func__);
  902. return;
  903. }
  904. ap->id = appl;
  905. ap->rp = *rp;
  906. list_add(&ap->ctrlist, &iif->appls);
  907. dev_info(cs->dev, "application %u registered\n", ap->id);
  908. }
  909. /*
  910. * remove CAPI application from channel
  911. * helper function to keep indentation levels down and stay in 80 columns
  912. */
  913. static inline void remove_appl_from_channel(struct bc_state *bcs,
  914. struct gigaset_capi_appl *ap)
  915. {
  916. struct cardstate *cs = bcs->cs;
  917. struct gigaset_capi_appl *bcap;
  918. unsigned long flags;
  919. int prevconnstate;
  920. spin_lock_irqsave(&bcs->aplock, flags);
  921. bcap = bcs->ap;
  922. if (bcap == NULL) {
  923. spin_unlock_irqrestore(&bcs->aplock, flags);
  924. return;
  925. }
  926. /* check first application on channel */
  927. if (bcap == ap) {
  928. bcs->ap = ap->bcnext;
  929. if (bcs->ap != NULL) {
  930. spin_unlock_irqrestore(&bcs->aplock, flags);
  931. return;
  932. }
  933. /* none left, clear channel state */
  934. prevconnstate = bcs->apconnstate;
  935. bcs->apconnstate = APCONN_NONE;
  936. spin_unlock_irqrestore(&bcs->aplock, flags);
  937. if (prevconnstate == APCONN_ACTIVE) {
  938. dev_notice(cs->dev, "%s: hanging up channel %u\n",
  939. __func__, bcs->channel);
  940. gigaset_add_event(cs, &bcs->at_state,
  941. EV_HUP, NULL, 0, NULL);
  942. gigaset_schedule_event(cs);
  943. }
  944. return;
  945. }
  946. /* check remaining list */
  947. do {
  948. if (bcap->bcnext == ap) {
  949. bcap->bcnext = bcap->bcnext->bcnext;
  950. spin_unlock_irqrestore(&bcs->aplock, flags);
  951. return;
  952. }
  953. bcap = bcap->bcnext;
  954. } while (bcap != NULL);
  955. spin_unlock_irqrestore(&bcs->aplock, flags);
  956. }
  957. /*
  958. * release CAPI application
  959. */
  960. static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
  961. {
  962. struct gigaset_capi_ctr *iif
  963. = container_of(ctr, struct gigaset_capi_ctr, ctr);
  964. struct cardstate *cs = iif->ctr.driverdata;
  965. struct gigaset_capi_appl *ap, *tmp;
  966. unsigned ch;
  967. gig_dbg(DEBUG_CMD, "%s [%u]", __func__, appl);
  968. list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
  969. if (ap->id == appl) {
  970. /* remove from any channels */
  971. for (ch = 0; ch < cs->channels; ch++)
  972. remove_appl_from_channel(&cs->bcs[ch], ap);
  973. /* remove from registration list */
  974. list_del(&ap->ctrlist);
  975. kfree(ap);
  976. dev_info(cs->dev, "application %u released\n", appl);
  977. }
  978. }
  979. /*
  980. * =====================================================================
  981. * outgoing CAPI message handler
  982. * =====================================================================
  983. */
  984. /*
  985. * helper function: emit reply message with given Info value
  986. */
  987. static void send_conf(struct gigaset_capi_ctr *iif,
  988. struct gigaset_capi_appl *ap,
  989. struct sk_buff *skb,
  990. u16 info)
  991. {
  992. /*
  993. * _CONF replies always only have NCCI and Info parameters
  994. * so they'll fit into the _REQ message skb
  995. */
  996. capi_cmsg_answer(&iif->acmsg);
  997. iif->acmsg.Info = info;
  998. capi_cmsg2message(&iif->acmsg, skb->data);
  999. __skb_trim(skb, CAPI_STDCONF_LEN);
  1000. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1001. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  1002. }
  1003. /*
  1004. * process FACILITY_REQ message
  1005. */
  1006. static void do_facility_req(struct gigaset_capi_ctr *iif,
  1007. struct gigaset_capi_appl *ap,
  1008. struct sk_buff *skb)
  1009. {
  1010. struct cardstate *cs = iif->ctr.driverdata;
  1011. _cmsg *cmsg = &iif->acmsg;
  1012. struct sk_buff *cskb;
  1013. u8 *pparam;
  1014. unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
  1015. u16 function, info;
  1016. static u8 confparam[10]; /* max. 9 octets + length byte */
  1017. /* decode message */
  1018. capi_message2cmsg(cmsg, skb->data);
  1019. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1020. /*
  1021. * Facility Request Parameter is not decoded by capi_message2cmsg()
  1022. * encoding depends on Facility Selector
  1023. */
  1024. switch (cmsg->FacilitySelector) {
  1025. case CAPI_FACILITY_DTMF: /* ToDo */
  1026. info = CapiFacilityNotSupported;
  1027. confparam[0] = 2; /* length */
  1028. /* DTMF information: Unknown DTMF request */
  1029. capimsg_setu16(confparam, 1, 2);
  1030. break;
  1031. case CAPI_FACILITY_V42BIS: /* not supported */
  1032. info = CapiFacilityNotSupported;
  1033. confparam[0] = 2; /* length */
  1034. /* V.42 bis information: not available */
  1035. capimsg_setu16(confparam, 1, 1);
  1036. break;
  1037. case CAPI_FACILITY_SUPPSVC:
  1038. /* decode Function parameter */
  1039. pparam = cmsg->FacilityRequestParameter;
  1040. if (pparam == NULL || pparam[0] < 2) {
  1041. dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
  1042. "Facility Request Parameter");
  1043. send_conf(iif, ap, skb, CapiIllMessageParmCoding);
  1044. return;
  1045. }
  1046. function = CAPIMSG_U16(pparam, 1);
  1047. switch (function) {
  1048. case CAPI_SUPPSVC_GETSUPPORTED:
  1049. info = CapiSuccess;
  1050. /* Supplementary Service specific parameter */
  1051. confparam[3] = 6; /* length */
  1052. /* Supplementary services info: Success */
  1053. capimsg_setu16(confparam, 4, CapiSuccess);
  1054. /* Supported Services: none */
  1055. capimsg_setu32(confparam, 6, 0);
  1056. break;
  1057. case CAPI_SUPPSVC_LISTEN:
  1058. if (pparam[0] < 7 || pparam[3] < 4) {
  1059. dev_notice(cs->dev, "%s: %s missing\n",
  1060. "FACILITY_REQ", "Notification Mask");
  1061. send_conf(iif, ap, skb,
  1062. CapiIllMessageParmCoding);
  1063. return;
  1064. }
  1065. if (CAPIMSG_U32(pparam, 4) != 0) {
  1066. dev_notice(cs->dev,
  1067. "%s: unsupported supplementary service notification mask 0x%x\n",
  1068. "FACILITY_REQ", CAPIMSG_U32(pparam, 4));
  1069. info = CapiFacilitySpecificFunctionNotSupported;
  1070. confparam[3] = 2; /* length */
  1071. capimsg_setu16(confparam, 4,
  1072. CapiSupplementaryServiceNotSupported);
  1073. }
  1074. info = CapiSuccess;
  1075. confparam[3] = 2; /* length */
  1076. capimsg_setu16(confparam, 4, CapiSuccess);
  1077. break;
  1078. /* ToDo: add supported services */
  1079. default:
  1080. dev_notice(cs->dev,
  1081. "%s: unsupported supplementary service function 0x%04x\n",
  1082. "FACILITY_REQ", function);
  1083. info = CapiFacilitySpecificFunctionNotSupported;
  1084. /* Supplementary Service specific parameter */
  1085. confparam[3] = 2; /* length */
  1086. /* Supplementary services info: not supported */
  1087. capimsg_setu16(confparam, 4,
  1088. CapiSupplementaryServiceNotSupported);
  1089. }
  1090. /* Facility confirmation parameter */
  1091. confparam[0] = confparam[3] + 3; /* total length */
  1092. /* Function: copy from _REQ message */
  1093. capimsg_setu16(confparam, 1, function);
  1094. /* Supplementary Service specific parameter already set above */
  1095. break;
  1096. case CAPI_FACILITY_WAKEUP: /* ToDo */
  1097. info = CapiFacilityNotSupported;
  1098. confparam[0] = 2; /* length */
  1099. /* Number of accepted awake request parameters: 0 */
  1100. capimsg_setu16(confparam, 1, 0);
  1101. break;
  1102. default:
  1103. info = CapiFacilityNotSupported;
  1104. confparam[0] = 0; /* empty struct */
  1105. }
  1106. /* send FACILITY_CONF with given Info and confirmation parameter */
  1107. capi_cmsg_answer(cmsg);
  1108. cmsg->Info = info;
  1109. cmsg->FacilityConfirmationParameter = confparam;
  1110. msgsize += confparam[0]; /* length */
  1111. cskb = alloc_skb(msgsize, GFP_ATOMIC);
  1112. if (!cskb) {
  1113. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1114. return;
  1115. }
  1116. capi_cmsg2message(cmsg, __skb_put(cskb, msgsize));
  1117. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1118. capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
  1119. }
  1120. /*
  1121. * process LISTEN_REQ message
  1122. * just store the masks in the application data structure
  1123. */
  1124. static void do_listen_req(struct gigaset_capi_ctr *iif,
  1125. struct gigaset_capi_appl *ap,
  1126. struct sk_buff *skb)
  1127. {
  1128. /* decode message */
  1129. capi_message2cmsg(&iif->acmsg, skb->data);
  1130. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1131. /* store listening parameters */
  1132. ap->listenInfoMask = iif->acmsg.InfoMask;
  1133. ap->listenCIPmask = iif->acmsg.CIPmask;
  1134. send_conf(iif, ap, skb, CapiSuccess);
  1135. }
  1136. /*
  1137. * process ALERT_REQ message
  1138. * nothing to do, Gigaset always alerts anyway
  1139. */
  1140. static void do_alert_req(struct gigaset_capi_ctr *iif,
  1141. struct gigaset_capi_appl *ap,
  1142. struct sk_buff *skb)
  1143. {
  1144. /* decode message */
  1145. capi_message2cmsg(&iif->acmsg, skb->data);
  1146. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1147. send_conf(iif, ap, skb, CapiAlertAlreadySent);
  1148. }
  1149. /*
  1150. * process CONNECT_REQ message
  1151. * allocate a B channel, prepare dial commands, queue a DIAL event,
  1152. * emit CONNECT_CONF reply
  1153. */
  1154. static void do_connect_req(struct gigaset_capi_ctr *iif,
  1155. struct gigaset_capi_appl *ap,
  1156. struct sk_buff *skb)
  1157. {
  1158. struct cardstate *cs = iif->ctr.driverdata;
  1159. _cmsg *cmsg = &iif->acmsg;
  1160. struct bc_state *bcs;
  1161. char **commands;
  1162. char *s;
  1163. u8 *pp;
  1164. unsigned long flags;
  1165. int i, l, lbc, lhlc;
  1166. u16 info;
  1167. /* decode message */
  1168. capi_message2cmsg(cmsg, skb->data);
  1169. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1170. /* get free B channel & construct PLCI */
  1171. bcs = gigaset_get_free_channel(cs);
  1172. if (!bcs) {
  1173. dev_notice(cs->dev, "%s: no B channel available\n",
  1174. "CONNECT_REQ");
  1175. send_conf(iif, ap, skb, CapiNoPlciAvailable);
  1176. return;
  1177. }
  1178. spin_lock_irqsave(&bcs->aplock, flags);
  1179. if (bcs->ap != NULL || bcs->apconnstate != APCONN_NONE)
  1180. dev_warn(cs->dev, "%s: channel not properly cleared (%p/%d)\n",
  1181. __func__, bcs->ap, bcs->apconnstate);
  1182. ap->bcnext = NULL;
  1183. bcs->ap = ap;
  1184. bcs->apconnstate = APCONN_SETUP;
  1185. spin_unlock_irqrestore(&bcs->aplock, flags);
  1186. bcs->rx_bufsize = ap->rp.datablklen;
  1187. dev_kfree_skb(bcs->rx_skb);
  1188. gigaset_new_rx_skb(bcs);
  1189. cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
  1190. /* build command table */
  1191. commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
  1192. if (!commands)
  1193. goto oom;
  1194. /* encode parameter: Called party number */
  1195. pp = cmsg->CalledPartyNumber;
  1196. if (pp == NULL || *pp == 0) {
  1197. dev_notice(cs->dev, "%s: %s missing\n",
  1198. "CONNECT_REQ", "Called party number");
  1199. info = CapiIllMessageParmCoding;
  1200. goto error;
  1201. }
  1202. l = *pp++;
  1203. /* check type of number/numbering plan byte */
  1204. switch (*pp) {
  1205. case 0x80: /* unknown type / unknown numbering plan */
  1206. case 0x81: /* unknown type / ISDN/Telephony numbering plan */
  1207. break;
  1208. default: /* others: warn about potential misinterpretation */
  1209. dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
  1210. "CONNECT_REQ", "Called party number", *pp);
  1211. }
  1212. pp++;
  1213. l--;
  1214. /* translate "**" internal call prefix to CTP value */
  1215. if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
  1216. s = "^SCTP=0\r";
  1217. pp += 2;
  1218. l -= 2;
  1219. } else {
  1220. s = "^SCTP=1\r";
  1221. }
  1222. commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
  1223. if (!commands[AT_TYPE])
  1224. goto oom;
  1225. commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
  1226. if (!commands[AT_DIAL])
  1227. goto oom;
  1228. snprintf(commands[AT_DIAL], l+3, "D%.*s\r", l, pp);
  1229. /* encode parameter: Calling party number */
  1230. pp = cmsg->CallingPartyNumber;
  1231. if (pp != NULL && *pp > 0) {
  1232. l = *pp++;
  1233. /* check type of number/numbering plan byte */
  1234. /* ToDo: allow for/handle Ext=1? */
  1235. switch (*pp) {
  1236. case 0x00: /* unknown type / unknown numbering plan */
  1237. case 0x01: /* unknown type / ISDN/Telephony num. plan */
  1238. break;
  1239. default:
  1240. dev_notice(cs->dev,
  1241. "%s: %s type/plan 0x%02x unsupported\n",
  1242. "CONNECT_REQ", "Calling party number", *pp);
  1243. }
  1244. pp++;
  1245. l--;
  1246. /* check presentation indicator */
  1247. if (!l) {
  1248. dev_notice(cs->dev, "%s: %s IE truncated\n",
  1249. "CONNECT_REQ", "Calling party number");
  1250. info = CapiIllMessageParmCoding;
  1251. goto error;
  1252. }
  1253. switch (*pp & 0xfc) { /* ignore Screening indicator */
  1254. case 0x80: /* Presentation allowed */
  1255. s = "^SCLIP=1\r";
  1256. break;
  1257. case 0xa0: /* Presentation restricted */
  1258. s = "^SCLIP=0\r";
  1259. break;
  1260. default:
  1261. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1262. "CONNECT_REQ",
  1263. "Presentation/Screening indicator",
  1264. *pp);
  1265. s = "^SCLIP=1\r";
  1266. }
  1267. commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
  1268. if (!commands[AT_CLIP])
  1269. goto oom;
  1270. pp++;
  1271. l--;
  1272. if (l) {
  1273. /* number */
  1274. commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
  1275. if (!commands[AT_MSN])
  1276. goto oom;
  1277. snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
  1278. }
  1279. }
  1280. /* check parameter: CIP Value */
  1281. if (cmsg->CIPValue >= ARRAY_SIZE(cip2bchlc) ||
  1282. (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
  1283. dev_notice(cs->dev, "%s: unknown CIP value %d\n",
  1284. "CONNECT_REQ", cmsg->CIPValue);
  1285. info = CapiCipValueUnknown;
  1286. goto error;
  1287. }
  1288. /*
  1289. * check/encode parameters: BC & HLC
  1290. * must be encoded together as device doesn't accept HLC separately
  1291. * explicit parameters override values derived from CIP
  1292. */
  1293. /* determine lengths */
  1294. if (cmsg->BC && cmsg->BC[0]) /* BC specified explicitly */
  1295. lbc = 2*cmsg->BC[0];
  1296. else if (cip2bchlc[cmsg->CIPValue].bc) /* BC derived from CIP */
  1297. lbc = strlen(cip2bchlc[cmsg->CIPValue].bc);
  1298. else /* no BC */
  1299. lbc = 0;
  1300. if (cmsg->HLC && cmsg->HLC[0]) /* HLC specified explicitly */
  1301. lhlc = 2*cmsg->HLC[0];
  1302. else if (cip2bchlc[cmsg->CIPValue].hlc) /* HLC derived from CIP */
  1303. lhlc = strlen(cip2bchlc[cmsg->CIPValue].hlc);
  1304. else /* no HLC */
  1305. lhlc = 0;
  1306. if (lbc) {
  1307. /* have BC: allocate and assemble command string */
  1308. l = lbc + 7; /* "^SBC=" + value + "\r" + null byte */
  1309. if (lhlc)
  1310. l += lhlc + 7; /* ";^SHLC=" + value */
  1311. commands[AT_BC] = kmalloc(l, GFP_KERNEL);
  1312. if (!commands[AT_BC])
  1313. goto oom;
  1314. strcpy(commands[AT_BC], "^SBC=");
  1315. if (cmsg->BC && cmsg->BC[0]) /* BC specified explicitly */
  1316. decode_ie(cmsg->BC, commands[AT_BC] + 5);
  1317. else /* BC derived from CIP */
  1318. strcpy(commands[AT_BC] + 5,
  1319. cip2bchlc[cmsg->CIPValue].bc);
  1320. if (lhlc) {
  1321. strcpy(commands[AT_BC] + lbc + 5, ";^SHLC=");
  1322. if (cmsg->HLC && cmsg->HLC[0])
  1323. /* HLC specified explicitly */
  1324. decode_ie(cmsg->HLC,
  1325. commands[AT_BC] + lbc + 12);
  1326. else /* HLC derived from CIP */
  1327. strcpy(commands[AT_BC] + lbc + 12,
  1328. cip2bchlc[cmsg->CIPValue].hlc);
  1329. }
  1330. strcpy(commands[AT_BC] + l - 2, "\r");
  1331. } else {
  1332. /* no BC */
  1333. if (lhlc) {
  1334. dev_notice(cs->dev, "%s: cannot set HLC without BC\n",
  1335. "CONNECT_REQ");
  1336. info = CapiIllMessageParmCoding; /* ? */
  1337. goto error;
  1338. }
  1339. }
  1340. /* check/encode parameter: B Protocol */
  1341. if (cmsg->BProtocol == CAPI_DEFAULT) {
  1342. bcs->proto2 = L2_HDLC;
  1343. dev_warn(cs->dev,
  1344. "B2 Protocol X.75 SLP unsupported, using Transparent\n");
  1345. } else {
  1346. switch (cmsg->B1protocol) {
  1347. case 0:
  1348. bcs->proto2 = L2_HDLC;
  1349. break;
  1350. case 1:
  1351. bcs->proto2 = L2_VOICE;
  1352. break;
  1353. default:
  1354. dev_warn(cs->dev,
  1355. "B1 Protocol %u unsupported, using Transparent\n",
  1356. cmsg->B1protocol);
  1357. bcs->proto2 = L2_VOICE;
  1358. }
  1359. if (cmsg->B2protocol != 1)
  1360. dev_warn(cs->dev,
  1361. "B2 Protocol %u unsupported, using Transparent\n",
  1362. cmsg->B2protocol);
  1363. if (cmsg->B3protocol != 0)
  1364. dev_warn(cs->dev,
  1365. "B3 Protocol %u unsupported, using Transparent\n",
  1366. cmsg->B3protocol);
  1367. ignore_cstruct_param(cs, cmsg->B1configuration,
  1368. "CONNECT_REQ", "B1 Configuration");
  1369. ignore_cstruct_param(cs, cmsg->B2configuration,
  1370. "CONNECT_REQ", "B2 Configuration");
  1371. ignore_cstruct_param(cs, cmsg->B3configuration,
  1372. "CONNECT_REQ", "B3 Configuration");
  1373. }
  1374. commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
  1375. if (!commands[AT_PROTO])
  1376. goto oom;
  1377. snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
  1378. /* ToDo: check/encode remaining parameters */
  1379. ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
  1380. "CONNECT_REQ", "Called pty subaddr");
  1381. ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
  1382. "CONNECT_REQ", "Calling pty subaddr");
  1383. ignore_cstruct_param(cs, cmsg->LLC,
  1384. "CONNECT_REQ", "LLC");
  1385. if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
  1386. ignore_cstruct_param(cs, cmsg->BChannelinformation,
  1387. "CONNECT_REQ", "B Channel Information");
  1388. ignore_cstruct_param(cs, cmsg->Keypadfacility,
  1389. "CONNECT_REQ", "Keypad Facility");
  1390. ignore_cstruct_param(cs, cmsg->Useruserdata,
  1391. "CONNECT_REQ", "User-User Data");
  1392. ignore_cstruct_param(cs, cmsg->Facilitydataarray,
  1393. "CONNECT_REQ", "Facility Data Array");
  1394. }
  1395. /* encode parameter: B channel to use */
  1396. commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
  1397. if (!commands[AT_ISO])
  1398. goto oom;
  1399. snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
  1400. (unsigned) bcs->channel + 1);
  1401. /* queue & schedule EV_DIAL event */
  1402. if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
  1403. bcs->at_state.seq_index, NULL)) {
  1404. info = CAPI_MSGOSRESOURCEERR;
  1405. goto error;
  1406. }
  1407. gigaset_schedule_event(cs);
  1408. send_conf(iif, ap, skb, CapiSuccess);
  1409. return;
  1410. oom:
  1411. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1412. info = CAPI_MSGOSRESOURCEERR;
  1413. error:
  1414. if (commands)
  1415. for (i = 0; i < AT_NUM; i++)
  1416. kfree(commands[i]);
  1417. kfree(commands);
  1418. gigaset_free_channel(bcs);
  1419. send_conf(iif, ap, skb, info);
  1420. }
  1421. /*
  1422. * process CONNECT_RESP message
  1423. * checks protocol parameters and queues an ACCEPT or HUP event
  1424. */
  1425. static void do_connect_resp(struct gigaset_capi_ctr *iif,
  1426. struct gigaset_capi_appl *ap,
  1427. struct sk_buff *skb)
  1428. {
  1429. struct cardstate *cs = iif->ctr.driverdata;
  1430. _cmsg *cmsg = &iif->acmsg;
  1431. struct bc_state *bcs;
  1432. struct gigaset_capi_appl *oap;
  1433. unsigned long flags;
  1434. int channel;
  1435. /* decode message */
  1436. capi_message2cmsg(cmsg, skb->data);
  1437. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1438. dev_kfree_skb_any(skb);
  1439. /* extract and check channel number from PLCI */
  1440. channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
  1441. if (!channel || channel > cs->channels) {
  1442. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1443. "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
  1444. return;
  1445. }
  1446. bcs = cs->bcs + channel - 1;
  1447. switch (cmsg->Reject) {
  1448. case 0: /* Accept */
  1449. /* drop all competing applications, keep only this one */
  1450. spin_lock_irqsave(&bcs->aplock, flags);
  1451. while (bcs->ap != NULL) {
  1452. oap = bcs->ap;
  1453. bcs->ap = oap->bcnext;
  1454. if (oap != ap) {
  1455. spin_unlock_irqrestore(&bcs->aplock, flags);
  1456. send_disconnect_ind(bcs, oap,
  1457. CapiCallGivenToOtherApplication);
  1458. spin_lock_irqsave(&bcs->aplock, flags);
  1459. }
  1460. }
  1461. ap->bcnext = NULL;
  1462. bcs->ap = ap;
  1463. spin_unlock_irqrestore(&bcs->aplock, flags);
  1464. bcs->rx_bufsize = ap->rp.datablklen;
  1465. dev_kfree_skb(bcs->rx_skb);
  1466. gigaset_new_rx_skb(bcs);
  1467. bcs->chstate |= CHS_NOTIFY_LL;
  1468. /* check/encode B channel protocol */
  1469. if (cmsg->BProtocol == CAPI_DEFAULT) {
  1470. bcs->proto2 = L2_HDLC;
  1471. dev_warn(cs->dev,
  1472. "B2 Protocol X.75 SLP unsupported, using Transparent\n");
  1473. } else {
  1474. switch (cmsg->B1protocol) {
  1475. case 0:
  1476. bcs->proto2 = L2_HDLC;
  1477. break;
  1478. case 1:
  1479. bcs->proto2 = L2_VOICE;
  1480. break;
  1481. default:
  1482. dev_warn(cs->dev,
  1483. "B1 Protocol %u unsupported, using Transparent\n",
  1484. cmsg->B1protocol);
  1485. bcs->proto2 = L2_VOICE;
  1486. }
  1487. if (cmsg->B2protocol != 1)
  1488. dev_warn(cs->dev,
  1489. "B2 Protocol %u unsupported, using Transparent\n",
  1490. cmsg->B2protocol);
  1491. if (cmsg->B3protocol != 0)
  1492. dev_warn(cs->dev,
  1493. "B3 Protocol %u unsupported, using Transparent\n",
  1494. cmsg->B3protocol);
  1495. ignore_cstruct_param(cs, cmsg->B1configuration,
  1496. "CONNECT_RESP", "B1 Configuration");
  1497. ignore_cstruct_param(cs, cmsg->B2configuration,
  1498. "CONNECT_RESP", "B2 Configuration");
  1499. ignore_cstruct_param(cs, cmsg->B3configuration,
  1500. "CONNECT_RESP", "B3 Configuration");
  1501. }
  1502. /* ToDo: check/encode remaining parameters */
  1503. ignore_cstruct_param(cs, cmsg->ConnectedNumber,
  1504. "CONNECT_RESP", "Connected Number");
  1505. ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
  1506. "CONNECT_RESP", "Connected Subaddress");
  1507. ignore_cstruct_param(cs, cmsg->LLC,
  1508. "CONNECT_RESP", "LLC");
  1509. if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
  1510. ignore_cstruct_param(cs, cmsg->BChannelinformation,
  1511. "CONNECT_RESP", "BChannel Information");
  1512. ignore_cstruct_param(cs, cmsg->Keypadfacility,
  1513. "CONNECT_RESP", "Keypad Facility");
  1514. ignore_cstruct_param(cs, cmsg->Useruserdata,
  1515. "CONNECT_RESP", "User-User Data");
  1516. ignore_cstruct_param(cs, cmsg->Facilitydataarray,
  1517. "CONNECT_RESP", "Facility Data Array");
  1518. }
  1519. /* Accept call */
  1520. if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
  1521. EV_ACCEPT, NULL, 0, NULL))
  1522. return;
  1523. gigaset_schedule_event(cs);
  1524. return;
  1525. case 1: /* Ignore */
  1526. /* send DISCONNECT_IND to this application */
  1527. send_disconnect_ind(bcs, ap, 0);
  1528. /* remove it from the list of listening apps */
  1529. spin_lock_irqsave(&bcs->aplock, flags);
  1530. if (bcs->ap == ap) {
  1531. bcs->ap = ap->bcnext;
  1532. if (bcs->ap == NULL) {
  1533. /* last one: stop ev-layer hupD notifications */
  1534. bcs->apconnstate = APCONN_NONE;
  1535. bcs->chstate &= ~CHS_NOTIFY_LL;
  1536. }
  1537. spin_unlock_irqrestore(&bcs->aplock, flags);
  1538. return;
  1539. }
  1540. for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
  1541. if (oap->bcnext == ap) {
  1542. oap->bcnext = oap->bcnext->bcnext;
  1543. spin_unlock_irqrestore(&bcs->aplock, flags);
  1544. return;
  1545. }
  1546. }
  1547. spin_unlock_irqrestore(&bcs->aplock, flags);
  1548. dev_err(cs->dev, "%s: application %u not found\n",
  1549. __func__, ap->id);
  1550. return;
  1551. default: /* Reject */
  1552. /* drop all competing applications, keep only this one */
  1553. spin_lock_irqsave(&bcs->aplock, flags);
  1554. while (bcs->ap != NULL) {
  1555. oap = bcs->ap;
  1556. bcs->ap = oap->bcnext;
  1557. if (oap != ap) {
  1558. spin_unlock_irqrestore(&bcs->aplock, flags);
  1559. send_disconnect_ind(bcs, oap,
  1560. CapiCallGivenToOtherApplication);
  1561. spin_lock_irqsave(&bcs->aplock, flags);
  1562. }
  1563. }
  1564. ap->bcnext = NULL;
  1565. bcs->ap = ap;
  1566. spin_unlock_irqrestore(&bcs->aplock, flags);
  1567. /* reject call - will trigger DISCONNECT_IND for this app */
  1568. dev_info(cs->dev, "%s: Reject=%x\n",
  1569. "CONNECT_RESP", cmsg->Reject);
  1570. if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
  1571. EV_HUP, NULL, 0, NULL))
  1572. return;
  1573. gigaset_schedule_event(cs);
  1574. return;
  1575. }
  1576. }
  1577. /*
  1578. * process CONNECT_B3_REQ message
  1579. * build NCCI and emit CONNECT_B3_CONF reply
  1580. */
  1581. static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
  1582. struct gigaset_capi_appl *ap,
  1583. struct sk_buff *skb)
  1584. {
  1585. struct cardstate *cs = iif->ctr.driverdata;
  1586. _cmsg *cmsg = &iif->acmsg;
  1587. struct bc_state *bcs;
  1588. int channel;
  1589. /* decode message */
  1590. capi_message2cmsg(cmsg, skb->data);
  1591. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1592. /* extract and check channel number