i4l.c 18 KB

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