i4l.c 18 KB

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