i4l.c 18 KB

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