i4l.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * Stuff used by all variants of the driver
  3. *
  4. * Copyright (c) 2001 by Stefan Eilers,
  5. * Hansjoerg Lipp <hjlipp@web.de>,
  6. * Tilman Schmidt <tilman@imap.cc>.
  7. *
  8. * =====================================================================
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. * =====================================================================
  14. */
  15. #include "gigaset.h"
  16. #include <linux/isdnif.h>
  17. #define HW_HDR_LEN 2 /* Header size used to store ack info */
  18. /* == Handling of I4L IO =====================================================*/
  19. /* writebuf_from_LL
  20. * called by LL to transmit data on an open channel
  21. * inserts the buffer data into the send queue and starts the transmission
  22. * Note that this operation must not sleep!
  23. * When the buffer is processed completely, gigaset_skb_sent() should be called.
  24. * parameters:
  25. * driverID driver ID as assigned by LL
  26. * channel channel number
  27. * ack if != 0 LL wants to be notified on completion via
  28. * statcallb(ISDN_STAT_BSENT)
  29. * skb skb containing data to send
  30. * return value:
  31. * number of accepted bytes
  32. * 0 if temporarily unable to accept data (out of buffer space)
  33. * <0 on error (eg. -EINVAL)
  34. */
  35. static int writebuf_from_LL(int driverID, int channel, int ack,
  36. struct sk_buff *skb)
  37. {
  38. struct cardstate *cs = gigaset_get_cs_by_id(driverID);
  39. struct bc_state *bcs;
  40. unsigned char *ack_header;
  41. unsigned len;
  42. if (!cs) {
  43. pr_err("%s: invalid driver ID (%d)\n", __func__, driverID);
  44. return -ENODEV;
  45. }
  46. if (channel < 0 || channel >= cs->channels) {
  47. dev_err(cs->dev, "%s: invalid channel ID (%d)\n",
  48. __func__, channel);
  49. return -ENODEV;
  50. }
  51. bcs = &cs->bcs[channel];
  52. /* can only handle linear sk_buffs */
  53. if (skb_linearize(skb) < 0) {
  54. dev_err(cs->dev, "%s: skb_linearize failed\n", __func__);
  55. return -ENOMEM;
  56. }
  57. len = skb->len;
  58. gig_dbg(DEBUG_LLDATA,
  59. "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)",
  60. driverID, channel, ack, len);
  61. if (!len) {
  62. if (ack)
  63. dev_notice(cs->dev, "%s: not ACKing empty packet\n",
  64. __func__);
  65. return 0;
  66. }
  67. if (len > MAX_BUF_SIZE) {
  68. dev_err(cs->dev, "%s: packet too large (%d bytes)\n",
  69. __func__, len);
  70. return -EINVAL;
  71. }
  72. /* set up acknowledgement header */
  73. if (skb_headroom(skb) < HW_HDR_LEN) {
  74. /* should never happen */
  75. dev_err(cs->dev, "%s: insufficient skb headroom\n", __func__);
  76. return -ENOMEM;
  77. }
  78. skb_set_mac_header(skb, -HW_HDR_LEN);
  79. skb->mac_len = HW_HDR_LEN;
  80. ack_header = skb_mac_header(skb);
  81. if (ack) {
  82. ack_header[0] = len & 0xff;
  83. ack_header[1] = len >> 8;
  84. } else {
  85. ack_header[0] = ack_header[1] = 0;
  86. }
  87. gig_dbg(DEBUG_MCMD, "skb: len=%u, ack=%d: %02x %02x",
  88. len, ack, ack_header[0], ack_header[1]);
  89. /* pass to device-specific module */
  90. return cs->ops->send_skb(bcs, skb);
  91. }
  92. /**
  93. * gigaset_skb_sent() - acknowledge sending an skb
  94. * @bcs: B channel descriptor structure.
  95. * @skb: sent data.
  96. *
  97. * Called by hardware module {bas,ser,usb}_gigaset when the data in a
  98. * skb has been successfully sent, for signalling completion to the LL.
  99. */
  100. void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
  101. {
  102. isdn_if *iif = bcs->cs->iif;
  103. unsigned char *ack_header = skb_mac_header(skb);
  104. unsigned len;
  105. isdn_ctrl response;
  106. ++bcs->trans_up;
  107. if (skb->len)
  108. dev_warn(bcs->cs->dev, "%s: skb->len==%d\n",
  109. __func__, skb->len);
  110. len = ack_header[0] + ((unsigned) ack_header[1] << 8);
  111. if (len) {
  112. gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)",
  113. bcs->cs->myid, bcs->channel, len);
  114. response.driver = bcs->cs->myid;
  115. response.command = ISDN_STAT_BSENT;
  116. response.arg = bcs->channel;
  117. response.parm.length = len;
  118. iif->statcallb(&response);
  119. }
  120. }
  121. EXPORT_SYMBOL_GPL(gigaset_skb_sent);
  122. /**
  123. * gigaset_skb_rcvd() - pass received skb to LL
  124. * @bcs: B channel descriptor structure.
  125. * @skb: received data.
  126. *
  127. * Called by hardware module {bas,ser,usb}_gigaset when user data has
  128. * been successfully received, for passing to the LL.
  129. * Warning: skb must not be accessed anymore!
  130. */
  131. void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
  132. {
  133. isdn_if *iif = bcs->cs->iif;
  134. iif->rcvcallb_skb(bcs->cs->myid, bcs->channel, skb);
  135. bcs->trans_down++;
  136. }
  137. EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
  138. /**
  139. * gigaset_isdn_rcv_err() - signal receive error
  140. * @bcs: B channel descriptor structure.
  141. *
  142. * Called by hardware module {bas,ser,usb}_gigaset when a receive error
  143. * has occurred, for signalling to the LL.
  144. */
  145. void gigaset_isdn_rcv_err(struct bc_state *bcs)
  146. {
  147. isdn_if *iif = bcs->cs->iif;
  148. isdn_ctrl response;
  149. /* if currently ignoring packets, just count down */
  150. if (bcs->ignore) {
  151. bcs->ignore--;
  152. return;
  153. }
  154. /* update statistics */
  155. bcs->corrupted++;
  156. /* error -> LL */
  157. gig_dbg(DEBUG_CMD, "sending L1ERR");
  158. response.driver = bcs->cs->myid;
  159. response.command = ISDN_STAT_L1ERR;
  160. response.arg = bcs->channel;
  161. response.parm.errcode = ISDN_STAT_L1ERR_RECV;
  162. iif->statcallb(&response);
  163. }
  164. EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
  165. /* This function will be called by LL to send commands
  166. * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL,
  167. * so don't put too much effort into it.
  168. */
  169. static int command_from_LL(isdn_ctrl *cntrl)
  170. {
  171. struct cardstate *cs;
  172. struct bc_state *bcs;
  173. int retval = 0;
  174. char **commands;
  175. int ch;
  176. int i;
  177. size_t l;
  178. gigaset_debugdrivers();
  179. gig_dbg(DEBUG_CMD, "driver: %d, command: %d, arg: 0x%lx",
  180. cntrl->driver, cntrl->command, cntrl->arg);
  181. cs = gigaset_get_cs_by_id(cntrl->driver);
  182. if (cs == NULL) {
  183. pr_err("%s: invalid driver ID (%d)\n", __func__, cntrl->driver);
  184. return -ENODEV;
  185. }
  186. ch = cntrl->arg & 0xff;
  187. switch (cntrl->command) {
  188. case ISDN_CMD_IOCTL:
  189. dev_warn(cs->dev, "ISDN_CMD_IOCTL not supported\n");
  190. return -EINVAL;
  191. case ISDN_CMD_DIAL:
  192. gig_dbg(DEBUG_ANY,
  193. "ISDN_CMD_DIAL (phone: %s, msn: %s, si1: %d, si2: %d)",
  194. cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn,
  195. cntrl->parm.setup.si1, cntrl->parm.setup.si2);
  196. if (ch >= cs->channels) {
  197. dev_err(cs->dev,
  198. "ISDN_CMD_DIAL: invalid channel (%d)\n", ch);
  199. return -EINVAL;
  200. }
  201. bcs = cs->bcs + ch;
  202. if (!gigaset_get_channel(bcs)) {
  203. dev_err(cs->dev, "ISDN_CMD_DIAL: channel not free\n");
  204. return -EBUSY;
  205. }
  206. commands = kzalloc(AT_NUM*(sizeof *commands), GFP_ATOMIC);
  207. if (!commands) {
  208. gigaset_free_channel(bcs);
  209. dev_err(cs->dev, "ISDN_CMD_DIAL: out of memory\n");
  210. return -ENOMEM;
  211. }
  212. l = 3 + strlen(cntrl->parm.setup.phone);
  213. commands[AT_DIAL] = kmalloc(l, GFP_ATOMIC);
  214. if (!commands[AT_DIAL])
  215. goto oom;
  216. if (cntrl->parm.setup.phone[0] == '*' &&
  217. cntrl->parm.setup.phone[1] == '*') {
  218. /* internal call: translate ** prefix to CTP value */
  219. commands[AT_TYPE] = kstrdup("^SCTP=0\r", GFP_ATOMIC);
  220. if (!commands[AT_TYPE])
  221. goto oom;
  222. snprintf(commands[AT_DIAL], l,
  223. "D%s\r", cntrl->parm.setup.phone+2);
  224. } else {
  225. commands[AT_TYPE] = kstrdup("^SCTP=1\r", GFP_ATOMIC);
  226. if (!commands[AT_TYPE])
  227. goto oom;
  228. snprintf(commands[AT_DIAL], l,
  229. "D%s\r", cntrl->parm.setup.phone);
  230. }
  231. l = strlen(cntrl->parm.setup.eazmsn);
  232. if (l) {
  233. l += 8;
  234. commands[AT_MSN] = kmalloc(l, GFP_ATOMIC);
  235. if (!commands[AT_MSN])
  236. goto oom;
  237. snprintf(commands[AT_MSN], l, "^SMSN=%s\r",
  238. cntrl->parm.setup.eazmsn);
  239. }
  240. switch (cntrl->parm.setup.si1) {
  241. case 1: /* audio */
  242. /* BC = 9090A3: 3.1 kHz audio, A-law */
  243. commands[AT_BC] = kstrdup("^SBC=9090A3\r", GFP_ATOMIC);
  244. if (!commands[AT_BC])
  245. goto oom;
  246. break;
  247. case 7: /* data */
  248. default: /* hope the app knows what it is doing */
  249. /* BC = 8890: unrestricted digital information */
  250. commands[AT_BC] = kstrdup("^SBC=8890\r", GFP_ATOMIC);
  251. if (!commands[AT_BC])
  252. goto oom;
  253. }
  254. /* ToDo: other si1 values, inspect si2, set HLC/LLC */
  255. commands[AT_PROTO] = kmalloc(9, GFP_ATOMIC);
  256. if (!commands[AT_PROTO])
  257. goto oom;
  258. snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
  259. commands[AT_ISO] = kmalloc(9, GFP_ATOMIC);
  260. if (!commands[AT_ISO])
  261. goto oom;
  262. snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
  263. (unsigned) bcs->channel + 1);
  264. if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
  265. bcs->at_state.seq_index, NULL)) {
  266. for (i = 0; i < AT_NUM; ++i)
  267. kfree(commands[i]);
  268. kfree(commands);
  269. gigaset_free_channel(bcs);
  270. return -ENOMEM;
  271. }
  272. gig_dbg(DEBUG_CMD, "scheduling DIAL");
  273. gigaset_schedule_event(cs);
  274. break;
  275. case ISDN_CMD_ACCEPTD:
  276. if (ch >= cs->channels) {
  277. dev_err(cs->dev,
  278. "ISDN_CMD_ACCEPTD: invalid channel (%d)\n", ch);
  279. return -EINVAL;
  280. }
  281. bcs = cs->bcs + ch;
  282. if (!gigaset_add_event(cs, &bcs->at_state,
  283. EV_ACCEPT, NULL, 0, NULL))
  284. return -ENOMEM;
  285. gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
  286. gigaset_schedule_event(cs);
  287. break;
  288. case ISDN_CMD_ACCEPTB:
  289. break;
  290. case ISDN_CMD_HANGUP:
  291. if (ch >= cs->channels) {
  292. dev_err(cs->dev,
  293. "ISDN_CMD_HANGUP: invalid channel (%d)\n", ch);
  294. return -EINVAL;
  295. }
  296. bcs = cs->bcs + ch;
  297. if (!gigaset_add_event(cs, &bcs->at_state,
  298. EV_HUP, NULL, 0, NULL))
  299. return -ENOMEM;
  300. gig_dbg(DEBUG_CMD, "scheduling HUP");
  301. gigaset_schedule_event(cs);
  302. break;
  303. case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */
  304. dev_info(cs->dev, "ignoring ISDN_CMD_CLREAZ\n");
  305. break;
  306. case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */
  307. dev_info(cs->dev, "ignoring ISDN_CMD_SETEAZ (%s)\n",
  308. cntrl->parm.num);
  309. break;
  310. case ISDN_CMD_SETL2: /* Set L2 to given protocol */
  311. if (ch >= cs->channels) {
  312. dev_err(cs->dev,
  313. "ISDN_CMD_SETL2: invalid channel (%d)\n", ch);
  314. return -EINVAL;
  315. }
  316. bcs = cs->bcs + ch;
  317. if (bcs->chstate & CHS_D_UP) {
  318. dev_err(cs->dev,
  319. "ISDN_CMD_SETL2: channel active (%d)\n", ch);
  320. return -EINVAL;
  321. }
  322. switch (cntrl->arg >> 8) {
  323. case ISDN_PROTO_L2_HDLC:
  324. gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_HDLC");
  325. bcs->proto2 = L2_HDLC;
  326. break;
  327. case ISDN_PROTO_L2_TRANS:
  328. gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL2: setting L2_VOICE");
  329. bcs->proto2 = L2_VOICE;
  330. break;
  331. default:
  332. dev_err(cs->dev,
  333. "ISDN_CMD_SETL2: unsupported protocol (%lu)\n",
  334. cntrl->arg >> 8);
  335. return -EINVAL;
  336. }
  337. break;
  338. case ISDN_CMD_SETL3: /* Set L3 to given protocol */
  339. if (ch >= cs->channels) {
  340. dev_err(cs->dev,
  341. "ISDN_CMD_SETL3: invalid channel (%d)\n", ch);
  342. return -EINVAL;
  343. }
  344. if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) {
  345. dev_err(cs->dev,
  346. "ISDN_CMD_SETL3: unsupported protocol (%lu)\n",
  347. cntrl->arg >> 8);
  348. return -EINVAL;
  349. }
  350. break;
  351. case ISDN_CMD_PROCEED:
  352. gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED");
  353. break;
  354. case ISDN_CMD_ALERT:
  355. gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT");
  356. if (cntrl->arg >= cs->channels) {
  357. dev_err(cs->dev,
  358. "ISDN_CMD_ALERT: invalid channel (%d)\n",
  359. (int) cntrl->arg);
  360. return -EINVAL;
  361. }
  362. break;
  363. case ISDN_CMD_REDIR:
  364. gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR");
  365. break;
  366. case ISDN_CMD_PROT_IO:
  367. gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO");
  368. break;
  369. case ISDN_CMD_FAXCMD:
  370. gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD");
  371. break;
  372. case ISDN_CMD_GETL2:
  373. gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2");
  374. break;
  375. case ISDN_CMD_GETL3:
  376. gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3");
  377. break;
  378. case ISDN_CMD_GETEAZ:
  379. gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ");
  380. break;
  381. case ISDN_CMD_SETSIL:
  382. gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL");
  383. break;
  384. case ISDN_CMD_GETSIL:
  385. gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
  386. break;
  387. default:
  388. dev_err(cs->dev, "unknown command %d from LL\n",
  389. cntrl->command);
  390. return -EINVAL;
  391. }
  392. return retval;
  393. oom:
  394. dev_err(bcs->cs->dev, "out of memory\n");
  395. for (i = 0; i < AT_NUM; ++i)
  396. kfree(commands[i]);
  397. return -ENOMEM;
  398. }
  399. static void gigaset_i4l_cmd(struct cardstate *cs, int cmd)
  400. {
  401. isdn_if *iif = cs->iif;
  402. isdn_ctrl command;
  403. command.driver = cs->myid;
  404. command.command = cmd;
  405. command.arg = 0;
  406. iif->statcallb(&command);
  407. }
  408. static void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd)
  409. {
  410. isdn_if *iif = bcs->cs->iif;
  411. isdn_ctrl command;
  412. command.driver = bcs->cs->myid;
  413. command.command = cmd;
  414. command.arg = bcs->channel;
  415. iif->statcallb(&command);
  416. }
  417. /**
  418. * gigaset_isdn_icall() - signal incoming call
  419. * @at_state: connection state structure.
  420. *
  421. * Called by main module to notify the LL that an incoming call has been
  422. * received. @at_state contains the parameters of the call.
  423. *
  424. * Return value: call disposition (ICALL_*)
  425. */
  426. int gigaset_isdn_icall(struct at_state_t *at_state)
  427. {
  428. struct cardstate *cs = at_state->cs;
  429. struct bc_state *bcs = at_state->bcs;
  430. isdn_if *iif = cs->iif;
  431. isdn_ctrl response;
  432. int retval;
  433. /* fill ICALL structure */
  434. response.parm.setup.si1 = 0; /* default: unknown */
  435. response.parm.setup.si2 = 0;
  436. response.parm.setup.screen = 0;
  437. response.parm.setup.plan = 0;
  438. if (!at_state->str_var[STR_ZBC]) {
  439. /* no BC (internal call): assume speech, A-law */
  440. response.parm.setup.si1 = 1;
  441. } else if (!strcmp(at_state->str_var[STR_ZBC], "8890")) {
  442. /* unrestricted digital information */
  443. response.parm.setup.si1 = 7;
  444. } else if (!strcmp(at_state->str_var[STR_ZBC], "8090A3")) {
  445. /* speech, A-law */
  446. response.parm.setup.si1 = 1;
  447. } else if (!strcmp(at_state->str_var[STR_ZBC], "9090A3")) {
  448. /* 3,1 kHz audio, A-law */
  449. response.parm.setup.si1 = 1;
  450. response.parm.setup.si2 = 2;
  451. } else {
  452. dev_warn(cs->dev, "RING ignored - unsupported BC %s\n",
  453. at_state->str_var[STR_ZBC]);
  454. return ICALL_IGNORE;
  455. }
  456. if (at_state->str_var[STR_NMBR]) {
  457. strlcpy(response.parm.setup.phone, at_state->str_var[STR_NMBR],
  458. sizeof response.parm.setup.phone);
  459. } else
  460. response.parm.setup.phone[0] = 0;
  461. if (at_state->str_var[STR_ZCPN]) {
  462. strlcpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN],
  463. sizeof response.parm.setup.eazmsn);
  464. } else
  465. response.parm.setup.eazmsn[0] = 0;
  466. if (!bcs) {
  467. dev_notice(cs->dev, "no channel for incoming call\n");
  468. response.command = ISDN_STAT_ICALLW;
  469. response.arg = 0;
  470. } else {
  471. gig_dbg(DEBUG_CMD, "Sending ICALL");
  472. response.command = ISDN_STAT_ICALL;
  473. response.arg = bcs->channel;
  474. }
  475. response.driver = cs->myid;
  476. retval = iif->statcallb(&response);
  477. gig_dbg(DEBUG_CMD, "Response: %d", retval);
  478. switch (retval) {
  479. case 0: /* no takers */
  480. return ICALL_IGNORE;
  481. case 1: /* alerting */
  482. bcs->chstate |= CHS_NOTIFY_LL;
  483. return ICALL_ACCEPT;
  484. case 2: /* reject */
  485. return ICALL_REJECT;
  486. case 3: /* incomplete */
  487. dev_warn(cs->dev,
  488. "LL requested unsupported feature: Incomplete Number\n");
  489. return ICALL_IGNORE;
  490. case 4: /* proceeding */
  491. /* Gigaset will send ALERTING anyway.
  492. * There doesn't seem to be a way to avoid this.
  493. */
  494. return ICALL_ACCEPT;
  495. case 5: /* deflect */
  496. dev_warn(cs->dev,
  497. "LL requested unsupported feature: Call Deflection\n");
  498. return ICALL_IGNORE;
  499. default:
  500. dev_err(cs->dev, "LL error %d on ICALL\n", retval);
  501. return ICALL_IGNORE;
  502. }
  503. }
  504. /**
  505. * gigaset_isdn_connD() - signal D channel connect
  506. * @bcs: B channel descriptor structure.
  507. *
  508. * Called by main module to notify the LL that the D channel connection has
  509. * been established.
  510. */
  511. void gigaset_isdn_connD(struct bc_state *bcs)
  512. {
  513. gig_dbg(DEBUG_CMD, "sending DCONN");
  514. gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
  515. }
  516. /**
  517. * gigaset_isdn_hupD() - signal D channel hangup
  518. * @bcs: B channel descriptor structure.
  519. *
  520. * Called by main module to notify the LL that the D channel connection has
  521. * been shut down.
  522. */
  523. void gigaset_isdn_hupD(struct bc_state *bcs)
  524. {
  525. gig_dbg(DEBUG_CMD, "sending DHUP");
  526. gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DHUP);
  527. }
  528. /**
  529. * gigaset_isdn_connB() - signal B channel connect
  530. * @bcs: B channel descriptor structure.
  531. *
  532. * Called by main module to notify the LL that the B channel connection has
  533. * been established.
  534. */
  535. void gigaset_isdn_connB(struct bc_state *bcs)
  536. {
  537. gig_dbg(DEBUG_CMD, "sending BCONN");
  538. gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN);
  539. }
  540. /**
  541. * gigaset_isdn_hupB() - signal B channel hangup
  542. * @bcs: B channel descriptor structure.
  543. *
  544. * Called by main module to notify the LL that the B channel connection has
  545. * been shut down.
  546. */
  547. void gigaset_isdn_hupB(struct bc_state *bcs)
  548. {
  549. gig_dbg(DEBUG_CMD, "sending BHUP");
  550. gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP);
  551. }
  552. /**
  553. * gigaset_isdn_start() - signal device availability
  554. * @cs: device descriptor structure.
  555. *
  556. * Called by main module to notify the LL that the device is available for
  557. * use.
  558. */
  559. void gigaset_isdn_start(struct cardstate *cs)
  560. {
  561. gig_dbg(DEBUG_CMD, "sending RUN");
  562. gigaset_i4l_cmd(cs, ISDN_STAT_RUN);
  563. }
  564. /**
  565. * gigaset_isdn_stop() - signal device unavailability
  566. * @cs: device descriptor structure.
  567. *
  568. * Called by main module to notify the LL that the device is no longer
  569. * available for use.
  570. */
  571. void gigaset_isdn_stop(struct cardstate *cs)
  572. {
  573. gig_dbg(DEBUG_CMD, "sending STOP");
  574. gigaset_i4l_cmd(cs, ISDN_STAT_STOP);
  575. }
  576. /**
  577. * gigaset_isdn_register() - register to LL
  578. * @cs: device descriptor structure.
  579. * @isdnid: device name.
  580. *
  581. * Called by main module to register the device with the LL.
  582. *
  583. * Return value: 1 for success, 0 for failure
  584. */
  585. int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
  586. {
  587. isdn_if *iif;
  588. pr_info("ISDN4Linux interface\n");
  589. iif = kmalloc(sizeof *iif, GFP_KERNEL);
  590. if (!iif) {
  591. pr_err("out of memory\n");
  592. return 0;
  593. }
  594. if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index)
  595. >= sizeof iif->id) {
  596. pr_err("ID too long: %s\n", isdnid);
  597. kfree(iif);
  598. return 0;
  599. }
  600. iif->owner = THIS_MODULE;
  601. iif->channels = cs->channels;
  602. iif->maxbufsize = MAX_BUF_SIZE;
  603. iif->features = ISDN_FEATURE_L2_TRANS |
  604. ISDN_FEATURE_L2_HDLC |
  605. #ifdef GIG_X75
  606. ISDN_FEATURE_L2_X75I |
  607. #endif
  608. ISDN_FEATURE_L3_TRANS |
  609. ISDN_FEATURE_P_EURO;
  610. iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */
  611. iif->command = command_from_LL;
  612. iif->writebuf_skb = writebuf_from_LL;
  613. iif->writecmd = NULL; /* Don't support isdnctrl */
  614. iif->readstat = NULL; /* Don't support isdnctrl */
  615. iif->rcvcallb_skb = NULL; /* Will be set by LL */
  616. iif->statcallb = NULL; /* Will be set by LL */
  617. if (!register_isdn(iif)) {
  618. pr_err("register_isdn failed\n");
  619. kfree(iif);
  620. return 0;
  621. }
  622. cs->iif = iif;
  623. cs->myid = iif->channels; /* Set my device id */
  624. cs->hw_hdr_len = HW_HDR_LEN;
  625. return 1;
  626. }
  627. /**
  628. * gigaset_isdn_unregister() - unregister from LL
  629. * @cs: device descriptor structure.
  630. *
  631. * Called by main module to unregister the device from the LL.
  632. */
  633. void gigaset_isdn_unregister(struct cardstate *cs)
  634. {
  635. gig_dbg(DEBUG_CMD, "sending UNLOAD");
  636. gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
  637. kfree(cs->iif);
  638. cs->iif = NULL;
  639. }