i4l.c 17 KB

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