i4l.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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 char *ack_header;
  41. unsigned len;
  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. /* 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"); //FIXME
  353. break;
  354. case ISDN_CMD_ALERT:
  355. gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME
  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. //bcs = cs->bcs + cntrl->arg;
  363. //bcs->proto2 = -1;
  364. // FIXME
  365. break;
  366. case ISDN_CMD_REDIR:
  367. gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME
  368. break;
  369. case ISDN_CMD_PROT_IO:
  370. gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO");
  371. break;
  372. case ISDN_CMD_FAXCMD:
  373. gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD");
  374. break;
  375. case ISDN_CMD_GETL2:
  376. gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2");
  377. break;
  378. case ISDN_CMD_GETL3:
  379. gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3");
  380. break;
  381. case ISDN_CMD_GETEAZ:
  382. gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ");
  383. break;
  384. case ISDN_CMD_SETSIL:
  385. gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL");
  386. break;
  387. case ISDN_CMD_GETSIL:
  388. gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
  389. break;
  390. default:
  391. dev_err(cs->dev, "unknown command %d from LL\n",
  392. cntrl->command);
  393. return -EINVAL;
  394. }
  395. return retval;
  396. oom:
  397. dev_err(bcs->cs->dev, "out of memory\n");
  398. for (i = 0; i < AT_NUM; ++i)
  399. kfree(commands[i]);
  400. return -ENOMEM;
  401. }
  402. static void gigaset_i4l_cmd(struct cardstate *cs, int cmd)
  403. {
  404. isdn_if *iif = cs->iif;
  405. isdn_ctrl command;
  406. command.driver = cs->myid;
  407. command.command = cmd;
  408. command.arg = 0;
  409. iif->statcallb(&command);
  410. }
  411. static void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd)
  412. {
  413. isdn_if *iif = bcs->cs->iif;
  414. isdn_ctrl command;
  415. command.driver = bcs->cs->myid;
  416. command.command = cmd;
  417. command.arg = bcs->channel;
  418. iif->statcallb(&command);
  419. }
  420. /**
  421. * gigaset_isdn_icall() - signal incoming call
  422. * @at_state: connection state structure.
  423. *
  424. * Called by main module to notify the LL that an incoming call has been
  425. * received. @at_state contains the parameters of the call.
  426. *
  427. * Return value: call disposition (ICALL_*)
  428. */
  429. int gigaset_isdn_icall(struct at_state_t *at_state)
  430. {
  431. struct cardstate *cs = at_state->cs;
  432. struct bc_state *bcs = at_state->bcs;
  433. isdn_if *iif = cs->iif;
  434. isdn_ctrl response;
  435. int retval;
  436. /* fill ICALL structure */
  437. response.parm.setup.si1 = 0; /* default: unknown */
  438. response.parm.setup.si2 = 0;
  439. response.parm.setup.screen = 0; //FIXME how to set these?
  440. response.parm.setup.plan = 0;
  441. if (!at_state->str_var[STR_ZBC]) {
  442. /* no BC (internal call): assume speech, A-law */
  443. response.parm.setup.si1 = 1;
  444. } else if (!strcmp(at_state->str_var[STR_ZBC], "8890")) {
  445. /* unrestricted digital information */
  446. response.parm.setup.si1 = 7;
  447. } else if (!strcmp(at_state->str_var[STR_ZBC], "8090A3")) {
  448. /* speech, A-law */
  449. response.parm.setup.si1 = 1;
  450. } else if (!strcmp(at_state->str_var[STR_ZBC], "9090A3")) {
  451. /* 3,1 kHz audio, A-law */
  452. response.parm.setup.si1 = 1;
  453. response.parm.setup.si2 = 2;
  454. } else {
  455. dev_warn(cs->dev, "RING ignored - unsupported BC %s\n",
  456. at_state->str_var[STR_ZBC]);
  457. return ICALL_IGNORE;
  458. }
  459. if (at_state->str_var[STR_NMBR]) {
  460. strncpy(response.parm.setup.phone, at_state->str_var[STR_NMBR],
  461. sizeof response.parm.setup.phone - 1);
  462. response.parm.setup.phone[sizeof response.parm.setup.phone - 1] = 0;
  463. } else
  464. response.parm.setup.phone[0] = 0;
  465. if (at_state->str_var[STR_ZCPN]) {
  466. strncpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN],
  467. sizeof response.parm.setup.eazmsn - 1);
  468. response.parm.setup.eazmsn[sizeof response.parm.setup.eazmsn - 1] = 0;
  469. } else
  470. response.parm.setup.eazmsn[0] = 0;
  471. if (!bcs) {
  472. dev_notice(cs->dev, "no channel for incoming call\n");
  473. response.command = ISDN_STAT_ICALLW;
  474. response.arg = 0; //FIXME
  475. } else {
  476. gig_dbg(DEBUG_CMD, "Sending ICALL");
  477. response.command = ISDN_STAT_ICALL;
  478. response.arg = bcs->channel; //FIXME
  479. }
  480. response.driver = cs->myid;
  481. retval = iif->statcallb(&response);
  482. gig_dbg(DEBUG_CMD, "Response: %d", retval);
  483. switch (retval) {
  484. case 0: /* no takers */
  485. return ICALL_IGNORE;
  486. case 1: /* alerting */
  487. bcs->chstate |= CHS_NOTIFY_LL;
  488. return ICALL_ACCEPT;
  489. case 2: /* reject */
  490. return ICALL_REJECT;
  491. case 3: /* incomplete */
  492. dev_warn(cs->dev,
  493. "LL requested unsupported feature: Incomplete Number\n");
  494. return ICALL_IGNORE;
  495. case 4: /* proceeding */
  496. /* Gigaset will send ALERTING anyway.
  497. * There doesn't seem to be a way to avoid this.
  498. */
  499. return ICALL_ACCEPT;
  500. case 5: /* deflect */
  501. dev_warn(cs->dev,
  502. "LL requested unsupported feature: Call Deflection\n");
  503. return ICALL_IGNORE;
  504. default:
  505. dev_err(cs->dev, "LL error %d on ICALL\n", retval);
  506. return ICALL_IGNORE;
  507. }
  508. }
  509. /**
  510. * gigaset_isdn_connD() - signal D channel connect
  511. * @bcs: B channel descriptor structure.
  512. *
  513. * Called by main module to notify the LL that the D channel connection has
  514. * been established.
  515. */
  516. void gigaset_isdn_connD(struct bc_state *bcs)
  517. {
  518. gig_dbg(DEBUG_CMD, "sending DCONN");
  519. gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
  520. }
  521. /**
  522. * gigaset_isdn_hupD() - signal D channel hangup
  523. * @bcs: B channel descriptor structure.
  524. *
  525. * Called by main module to notify the LL that the D channel connection has
  526. * been shut down.
  527. */
  528. void gigaset_isdn_hupD(struct bc_state *bcs)
  529. {
  530. gig_dbg(DEBUG_CMD, "sending DHUP");
  531. gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DHUP);
  532. }
  533. /**
  534. * gigaset_isdn_connB() - signal B channel connect
  535. * @bcs: B channel descriptor structure.
  536. *
  537. * Called by main module to notify the LL that the B channel connection has
  538. * been established.
  539. */
  540. void gigaset_isdn_connB(struct bc_state *bcs)
  541. {
  542. gig_dbg(DEBUG_CMD, "sending BCONN");
  543. gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN);
  544. }
  545. /**
  546. * gigaset_isdn_hupB() - signal B channel hangup
  547. * @bcs: B channel descriptor structure.
  548. *
  549. * Called by main module to notify the LL that the B channel connection has
  550. * been shut down.
  551. */
  552. void gigaset_isdn_hupB(struct bc_state *bcs)
  553. {
  554. gig_dbg(DEBUG_CMD, "sending BHUP");
  555. gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP);
  556. }
  557. /**
  558. * gigaset_isdn_start() - signal device availability
  559. * @cs: device descriptor structure.
  560. *
  561. * Called by main module to notify the LL that the device is available for
  562. * use.
  563. */
  564. void gigaset_isdn_start(struct cardstate *cs)
  565. {
  566. gig_dbg(DEBUG_CMD, "sending RUN");
  567. gigaset_i4l_cmd(cs, ISDN_STAT_RUN);
  568. }
  569. /**
  570. * gigaset_isdn_stop() - signal device unavailability
  571. * @cs: device descriptor structure.
  572. *
  573. * Called by main module to notify the LL that the device is no longer
  574. * available for use.
  575. */
  576. void gigaset_isdn_stop(struct cardstate *cs)
  577. {
  578. gig_dbg(DEBUG_CMD, "sending STOP");
  579. gigaset_i4l_cmd(cs, ISDN_STAT_STOP);
  580. }
  581. /**
  582. * gigaset_isdn_register() - register to LL
  583. * @cs: device descriptor structure.
  584. * @isdnid: device name.
  585. *
  586. * Called by main module to register the device with the LL.
  587. *
  588. * Return value: 1 for success, 0 for failure
  589. */
  590. int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
  591. {
  592. isdn_if *iif;
  593. pr_info("ISDN4Linux interface\n");
  594. iif = kmalloc(sizeof *iif, GFP_KERNEL);
  595. if (!iif) {
  596. pr_err("out of memory\n");
  597. return 0;
  598. }
  599. if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index)
  600. >= sizeof iif->id) {
  601. pr_err("ID too long: %s\n", isdnid);
  602. kfree(iif);
  603. return 0;
  604. }
  605. iif->owner = THIS_MODULE;
  606. iif->channels = cs->channels;
  607. iif->maxbufsize = MAX_BUF_SIZE;
  608. iif->features = ISDN_FEATURE_L2_TRANS |
  609. ISDN_FEATURE_L2_HDLC |
  610. #ifdef GIG_X75
  611. ISDN_FEATURE_L2_X75I |
  612. #endif
  613. ISDN_FEATURE_L3_TRANS |
  614. ISDN_FEATURE_P_EURO;
  615. iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */
  616. iif->command = command_from_LL;
  617. iif->writebuf_skb = writebuf_from_LL;
  618. iif->writecmd = NULL; /* Don't support isdnctrl */
  619. iif->readstat = NULL; /* Don't support isdnctrl */
  620. iif->rcvcallb_skb = NULL; /* Will be set by LL */
  621. iif->statcallb = NULL; /* Will be set by LL */
  622. if (!register_isdn(iif)) {
  623. pr_err("register_isdn failed\n");
  624. kfree(iif);
  625. return 0;
  626. }
  627. cs->iif = iif;
  628. cs->myid = iif->channels; /* Set my device id */
  629. cs->hw_hdr_len = HW_HDR_LEN;
  630. return 1;
  631. }
  632. /**
  633. * gigaset_isdn_unregister() - unregister from LL
  634. * @cs: device descriptor structure.
  635. *
  636. * Called by main module to unregister the device from the LL.
  637. */
  638. void gigaset_isdn_unregister(struct cardstate *cs)
  639. {
  640. gig_dbg(DEBUG_CMD, "sending UNLOAD");
  641. gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
  642. kfree(cs->iif);
  643. cs->iif = NULL;
  644. }