capi.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274
  1. /*
  2. * Kernel CAPI interface for the Gigaset driver
  3. *
  4. * Copyright (c) 2009 by Tilman Schmidt <tilman@imap.cc>.
  5. *
  6. * =====================================================================
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. * =====================================================================
  12. */
  13. #include "gigaset.h"
  14. #include <linux/ctype.h>
  15. #include <linux/proc_fs.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/isdn/capilli.h>
  18. #include <linux/isdn/capicmd.h>
  19. #include <linux/isdn/capiutil.h>
  20. /* missing from kernelcapi.h */
  21. #define CapiNcpiNotSupportedByProtocol 0x0001
  22. #define CapiFlagsNotSupportedByProtocol 0x0002
  23. #define CapiAlertAlreadySent 0x0003
  24. #define CapiFacilitySpecificFunctionNotSupported 0x3011
  25. /* missing from capicmd.h */
  26. #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
  27. #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
  28. #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
  29. #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
  30. #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
  31. #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
  32. #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
  33. #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
  34. #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
  35. /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
  36. #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
  37. #define CAPI_FACILITY_HANDSET 0x0000
  38. #define CAPI_FACILITY_DTMF 0x0001
  39. #define CAPI_FACILITY_V42BIS 0x0002
  40. #define CAPI_FACILITY_SUPPSVC 0x0003
  41. #define CAPI_FACILITY_WAKEUP 0x0004
  42. #define CAPI_FACILITY_LI 0x0005
  43. #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
  44. /* missing from capiutil.h */
  45. #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
  46. #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
  47. #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
  48. #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
  49. #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
  50. #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
  51. #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
  52. #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
  53. /* parameters with differing location in DATA_B3_CONF/_RESP: */
  54. #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
  55. #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
  56. /* Flags (DATA_B3_REQ/_IND) */
  57. #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
  58. #define CAPI_FLAGS_RESERVED (~0x1f)
  59. /* buffer sizes */
  60. #define MAX_BC_OCTETS 11
  61. #define MAX_HLC_OCTETS 3
  62. #define MAX_NUMBER_DIGITS 20
  63. #define MAX_FMT_IE_LEN 20
  64. /* values for gigaset_capi_appl.connected */
  65. #define APCONN_NONE 0 /* inactive/listening */
  66. #define APCONN_SETUP 1 /* connecting */
  67. #define APCONN_ACTIVE 2 /* B channel up */
  68. /* registered application data structure */
  69. struct gigaset_capi_appl {
  70. struct list_head ctrlist;
  71. struct gigaset_capi_appl *bcnext;
  72. u16 id;
  73. u16 nextMessageNumber;
  74. u32 listenInfoMask;
  75. u32 listenCIPmask;
  76. int connected;
  77. };
  78. /* CAPI specific controller data structure */
  79. struct gigaset_capi_ctr {
  80. struct capi_ctr ctr;
  81. struct list_head appls;
  82. struct sk_buff_head sendqueue;
  83. atomic_t sendqlen;
  84. /* two _cmsg structures possibly used concurrently: */
  85. _cmsg hcmsg; /* for message composition triggered from hardware */
  86. _cmsg acmsg; /* for dissection of messages sent from application */
  87. u8 bc_buf[MAX_BC_OCTETS+1];
  88. u8 hlc_buf[MAX_HLC_OCTETS+1];
  89. u8 cgpty_buf[MAX_NUMBER_DIGITS+3];
  90. u8 cdpty_buf[MAX_NUMBER_DIGITS+2];
  91. };
  92. /* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
  93. static struct {
  94. u8 *bc;
  95. u8 *hlc;
  96. } cip2bchlc[] = {
  97. [1] = { "8090A3", NULL },
  98. /* Speech (A-law) */
  99. [2] = { "8890", NULL },
  100. /* Unrestricted digital information */
  101. [3] = { "8990", NULL },
  102. /* Restricted digital information */
  103. [4] = { "9090A3", NULL },
  104. /* 3,1 kHz audio (A-law) */
  105. [5] = { "9190", NULL },
  106. /* 7 kHz audio */
  107. [6] = { "9890", NULL },
  108. /* Video */
  109. [7] = { "88C0C6E6", NULL },
  110. /* Packet mode */
  111. [8] = { "8890218F", NULL },
  112. /* 56 kbit/s rate adaptation */
  113. [9] = { "9190A5", NULL },
  114. /* Unrestricted digital information with tones/announcements */
  115. [16] = { "8090A3", "9181" },
  116. /* Telephony */
  117. [17] = { "9090A3", "9184" },
  118. /* Group 2/3 facsimile */
  119. [18] = { "8890", "91A1" },
  120. /* Group 4 facsimile Class 1 */
  121. [19] = { "8890", "91A4" },
  122. /* Teletex service basic and mixed mode
  123. and Group 4 facsimile service Classes II and III */
  124. [20] = { "8890", "91A8" },
  125. /* Teletex service basic and processable mode */
  126. [21] = { "8890", "91B1" },
  127. /* Teletex service basic mode */
  128. [22] = { "8890", "91B2" },
  129. /* International interworking for Videotex */
  130. [23] = { "8890", "91B5" },
  131. /* Telex */
  132. [24] = { "8890", "91B8" },
  133. /* Message Handling Systems in accordance with X.400 */
  134. [25] = { "8890", "91C1" },
  135. /* OSI application in accordance with X.200 */
  136. [26] = { "9190A5", "9181" },
  137. /* 7 kHz telephony */
  138. [27] = { "9190A5", "916001" },
  139. /* Video telephony, first connection */
  140. [28] = { "8890", "916002" },
  141. /* Video telephony, second connection */
  142. };
  143. /*
  144. * helper functions
  145. * ================
  146. */
  147. /*
  148. * emit unsupported parameter warning
  149. */
  150. static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
  151. char *msgname, char *paramname)
  152. {
  153. if (param && *param)
  154. dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
  155. msgname, paramname);
  156. }
  157. /*
  158. * convert hex to binary
  159. */
  160. static inline u8 hex2bin(char c)
  161. {
  162. int result = c & 0x0f;
  163. if (c & 0x40)
  164. result += 9;
  165. return result;
  166. }
  167. /*
  168. * convert an IE from Gigaset hex string to ETSI binary representation
  169. * including length byte
  170. * return value: result length, -1 on error
  171. */
  172. static int encode_ie(char *in, u8 *out, int maxlen)
  173. {
  174. int l = 0;
  175. while (*in) {
  176. if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
  177. return -1;
  178. out[++l] = (hex2bin(in[0]) << 4) + hex2bin(in[1]);
  179. in += 2;
  180. }
  181. out[0] = l;
  182. return l;
  183. }
  184. /*
  185. * convert an IE from ETSI binary representation including length byte
  186. * to Gigaset hex string
  187. */
  188. static void decode_ie(u8 *in, char *out)
  189. {
  190. int i = *in;
  191. while (i-- > 0) {
  192. /* ToDo: conversion to upper case necessary? */
  193. *out++ = toupper(hex_asc_hi(*++in));
  194. *out++ = toupper(hex_asc_lo(*in));
  195. }
  196. }
  197. /*
  198. * retrieve application data structure for an application ID
  199. */
  200. static inline struct gigaset_capi_appl *
  201. get_appl(struct gigaset_capi_ctr *iif, u16 appl)
  202. {
  203. struct gigaset_capi_appl *ap;
  204. list_for_each_entry(ap, &iif->appls, ctrlist)
  205. if (ap->id == appl)
  206. return ap;
  207. return NULL;
  208. }
  209. /*
  210. * dump CAPI message to kernel messages for debugging
  211. */
  212. static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
  213. {
  214. #ifdef CONFIG_GIGASET_DEBUG
  215. _cdebbuf *cdb;
  216. if (!(gigaset_debuglevel & level))
  217. return;
  218. cdb = capi_cmsg2str(p);
  219. if (cdb) {
  220. gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
  221. cdebbuf_free(cdb);
  222. } else {
  223. gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
  224. capi_cmd2str(p->Command, p->Subcommand));
  225. }
  226. #endif
  227. }
  228. static inline void dump_rawmsg(enum debuglevel level, const char *tag,
  229. unsigned char *data)
  230. {
  231. #ifdef CONFIG_GIGASET_DEBUG
  232. char *dbgline;
  233. int i, l;
  234. if (!(gigaset_debuglevel & level))
  235. return;
  236. l = CAPIMSG_LEN(data);
  237. if (l < 12) {
  238. gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
  239. return;
  240. }
  241. gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
  242. tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
  243. CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
  244. CAPIMSG_CONTROL(data));
  245. l -= 12;
  246. dbgline = kmalloc(3*l, GFP_ATOMIC);
  247. if (!dbgline)
  248. return;
  249. for (i = 0; i < l; i++) {
  250. dbgline[3*i] = hex_asc_hi(data[12+i]);
  251. dbgline[3*i+1] = hex_asc_lo(data[12+i]);
  252. dbgline[3*i+2] = ' ';
  253. }
  254. dbgline[3*l-1] = '\0';
  255. gig_dbg(level, " %s", dbgline);
  256. kfree(dbgline);
  257. if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
  258. (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
  259. CAPIMSG_SUBCOMMAND(data) == CAPI_IND) &&
  260. CAPIMSG_DATALEN(data) > 0) {
  261. l = CAPIMSG_DATALEN(data);
  262. dbgline = kmalloc(3*l, GFP_ATOMIC);
  263. if (!dbgline)
  264. return;
  265. data += CAPIMSG_LEN(data);
  266. for (i = 0; i < l; i++) {
  267. dbgline[3*i] = hex_asc_hi(data[i]);
  268. dbgline[3*i+1] = hex_asc_lo(data[i]);
  269. dbgline[3*i+2] = ' ';
  270. }
  271. dbgline[3*l-1] = '\0';
  272. gig_dbg(level, " %s", dbgline);
  273. kfree(dbgline);
  274. }
  275. #endif
  276. }
  277. /*
  278. * format CAPI IE as string
  279. */
  280. static const char *format_ie(const char *ie)
  281. {
  282. static char result[3*MAX_FMT_IE_LEN];
  283. int len, count;
  284. char *pout = result;
  285. if (!ie)
  286. return "NULL";
  287. count = len = ie[0];
  288. if (count > MAX_FMT_IE_LEN)
  289. count = MAX_FMT_IE_LEN-1;
  290. while (count--) {
  291. *pout++ = hex_asc_hi(*++ie);
  292. *pout++ = hex_asc_lo(*ie);
  293. *pout++ = ' ';
  294. }
  295. if (len > MAX_FMT_IE_LEN) {
  296. *pout++ = '.';
  297. *pout++ = '.';
  298. *pout++ = '.';
  299. }
  300. *--pout = 0;
  301. return result;
  302. }
  303. /*
  304. * driver interface functions
  305. * ==========================
  306. */
  307. /**
  308. * gigaset_skb_sent() - acknowledge transmission of outgoing skb
  309. * @bcs: B channel descriptor structure.
  310. * @skb: sent data.
  311. *
  312. * Called by hardware module {bas,ser,usb}_gigaset when the data in a
  313. * skb has been successfully sent, for signalling completion to the LL.
  314. */
  315. void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
  316. {
  317. struct cardstate *cs = bcs->cs;
  318. struct gigaset_capi_ctr *iif = cs->iif;
  319. struct gigaset_capi_appl *ap = bcs->ap;
  320. unsigned char *req = skb_mac_header(dskb);
  321. struct sk_buff *cskb;
  322. u16 flags;
  323. /* update statistics */
  324. ++bcs->trans_up;
  325. if (!ap) {
  326. dev_err(cs->dev, "%s: no application\n", __func__);
  327. return;
  328. }
  329. /* don't send further B3 messages if disconnected */
  330. if (ap->connected < APCONN_ACTIVE) {
  331. gig_dbg(DEBUG_LLDATA, "disconnected, discarding ack");
  332. return;
  333. }
  334. /* ToDo: honor unset "delivery confirmation" bit */
  335. flags = CAPIMSG_FLAGS(req);
  336. /* build DATA_B3_CONF message */
  337. cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
  338. if (!cskb) {
  339. dev_err(cs->dev, "%s: out of memory\n", __func__);
  340. return;
  341. }
  342. /* frequent message, avoid _cmsg overhead */
  343. CAPIMSG_SETLEN(cskb->data, CAPI_DATA_B3_CONF_LEN);
  344. CAPIMSG_SETAPPID(cskb->data, ap->id);
  345. CAPIMSG_SETCOMMAND(cskb->data, CAPI_DATA_B3);
  346. CAPIMSG_SETSUBCOMMAND(cskb->data, CAPI_CONF);
  347. CAPIMSG_SETMSGID(cskb->data, CAPIMSG_MSGID(req));
  348. CAPIMSG_SETCONTROLLER(cskb->data, iif->ctr.cnr);
  349. CAPIMSG_SETPLCI_PART(cskb->data, bcs->channel + 1);
  350. CAPIMSG_SETNCCI_PART(cskb->data, 1);
  351. CAPIMSG_SETHANDLE_CONF(cskb->data, CAPIMSG_HANDLE_REQ(req));
  352. if (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION)
  353. CAPIMSG_SETINFO_CONF(cskb->data,
  354. CapiFlagsNotSupportedByProtocol);
  355. else
  356. CAPIMSG_SETINFO_CONF(cskb->data, CAPI_NOERROR);
  357. /* emit message */
  358. dump_rawmsg(DEBUG_LLDATA, "DATA_B3_CONF", cskb->data);
  359. capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
  360. }
  361. EXPORT_SYMBOL_GPL(gigaset_skb_sent);
  362. /**
  363. * gigaset_skb_rcvd() - pass received skb to LL
  364. * @bcs: B channel descriptor structure.
  365. * @skb: received data.
  366. *
  367. * Called by hardware module {bas,ser,usb}_gigaset when user data has
  368. * been successfully received, for passing to the LL.
  369. * Warning: skb must not be accessed anymore!
  370. */
  371. void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
  372. {
  373. struct cardstate *cs = bcs->cs;
  374. struct gigaset_capi_ctr *iif = cs->iif;
  375. struct gigaset_capi_appl *ap = bcs->ap;
  376. int len = skb->len;
  377. /* update statistics */
  378. bcs->trans_down++;
  379. if (!ap) {
  380. dev_err(cs->dev, "%s: no application\n", __func__);
  381. return;
  382. }
  383. /* don't send further B3 messages if disconnected */
  384. if (ap->connected < APCONN_ACTIVE) {
  385. gig_dbg(DEBUG_LLDATA, "disconnected, discarding data");
  386. dev_kfree_skb_any(skb);
  387. return;
  388. }
  389. /*
  390. * prepend DATA_B3_IND message to payload
  391. * Parameters: NCCI = 1, all others 0/unused
  392. * frequent message, avoid _cmsg overhead
  393. */
  394. skb_push(skb, CAPI_DATA_B3_REQ_LEN);
  395. CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
  396. CAPIMSG_SETAPPID(skb->data, ap->id);
  397. CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
  398. CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
  399. CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
  400. CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
  401. CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
  402. CAPIMSG_SETNCCI_PART(skb->data, 1);
  403. /* Data parameter not used */
  404. CAPIMSG_SETDATALEN(skb->data, len);
  405. /* Data handle parameter not used */
  406. CAPIMSG_SETFLAGS(skb->data, 0);
  407. /* Data64 parameter not present */
  408. /* emit message */
  409. dump_rawmsg(DEBUG_LLDATA, "DATA_B3_IND", skb->data);
  410. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  411. }
  412. EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
  413. /**
  414. * gigaset_isdn_rcv_err() - signal receive error
  415. * @bcs: B channel descriptor structure.
  416. *
  417. * Called by hardware module {bas,ser,usb}_gigaset when a receive error
  418. * has occurred, for signalling to the LL.
  419. */
  420. void gigaset_isdn_rcv_err(struct bc_state *bcs)
  421. {
  422. /* if currently ignoring packets, just count down */
  423. if (bcs->ignore) {
  424. bcs->ignore--;
  425. return;
  426. }
  427. /* update statistics */
  428. bcs->corrupted++;
  429. /* ToDo: signal error -> LL */
  430. }
  431. EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
  432. /**
  433. * gigaset_isdn_icall() - signal incoming call
  434. * @at_state: connection state structure.
  435. *
  436. * Called by main module at tasklet level to notify the LL that an incoming
  437. * call has been received. @at_state contains the parameters of the call.
  438. *
  439. * Return value: call disposition (ICALL_*)
  440. */
  441. int gigaset_isdn_icall(struct at_state_t *at_state)
  442. {
  443. struct cardstate *cs = at_state->cs;
  444. struct bc_state *bcs = at_state->bcs;
  445. struct gigaset_capi_ctr *iif = cs->iif;
  446. struct gigaset_capi_appl *ap;
  447. u32 actCIPmask;
  448. struct sk_buff *skb;
  449. unsigned int msgsize;
  450. int i;
  451. /*
  452. * ToDo: signal calls without a free B channel, too
  453. * (requires a u8 handle for the at_state structure that can
  454. * be stored in the PLCI and used in the CONNECT_RESP message
  455. * handler to retrieve it)
  456. */
  457. if (!bcs)
  458. return ICALL_IGNORE;
  459. /* prepare CONNECT_IND message, using B channel number as PLCI */
  460. capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
  461. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  462. /* minimum size, all structs empty */
  463. msgsize = CAPI_CONNECT_IND_BASELEN;
  464. /* Bearer Capability (mandatory) */
  465. if (at_state->str_var[STR_ZBC]) {
  466. /* pass on BC from Gigaset */
  467. if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
  468. MAX_BC_OCTETS) < 0) {
  469. dev_warn(cs->dev, "RING ignored - bad BC %s\n",
  470. at_state->str_var[STR_ZBC]);
  471. return ICALL_IGNORE;
  472. }
  473. /* look up corresponding CIP value */
  474. iif->hcmsg.CIPValue = 0; /* default if nothing found */
  475. for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
  476. if (cip2bchlc[i].bc != NULL &&
  477. cip2bchlc[i].hlc == NULL &&
  478. !strcmp(cip2bchlc[i].bc,
  479. at_state->str_var[STR_ZBC])) {
  480. iif->hcmsg.CIPValue = i;
  481. break;
  482. }
  483. } else {
  484. /* no BC (internal call): assume CIP 1 (speech, A-law) */
  485. iif->hcmsg.CIPValue = 1;
  486. encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
  487. }
  488. iif->hcmsg.BC = iif->bc_buf;
  489. msgsize += iif->hcmsg.BC[0];
  490. /* High Layer Compatibility (optional) */
  491. if (at_state->str_var[STR_ZHLC]) {
  492. /* pass on HLC from Gigaset */
  493. if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
  494. MAX_HLC_OCTETS) < 0) {
  495. dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
  496. at_state->str_var[STR_ZHLC]);
  497. return ICALL_IGNORE;
  498. }
  499. iif->hcmsg.HLC = iif->hlc_buf;
  500. msgsize += iif->hcmsg.HLC[0];
  501. /* look up corresponding CIP value */
  502. /* keep BC based CIP value if none found */
  503. if (at_state->str_var[STR_ZBC])
  504. for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
  505. if (cip2bchlc[i].hlc != NULL &&
  506. !strcmp(cip2bchlc[i].hlc,
  507. at_state->str_var[STR_ZHLC]) &&
  508. !strcmp(cip2bchlc[i].bc,
  509. at_state->str_var[STR_ZBC])) {
  510. iif->hcmsg.CIPValue = i;
  511. break;
  512. }
  513. }
  514. /* Called Party Number (optional) */
  515. if (at_state->str_var[STR_ZCPN]) {
  516. i = strlen(at_state->str_var[STR_ZCPN]);
  517. if (i > MAX_NUMBER_DIGITS) {
  518. dev_warn(cs->dev, "RING ignored - bad number %s\n",
  519. at_state->str_var[STR_ZBC]);
  520. return ICALL_IGNORE;
  521. }
  522. iif->cdpty_buf[0] = i + 1;
  523. iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
  524. memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
  525. iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
  526. msgsize += iif->hcmsg.CalledPartyNumber[0];
  527. }
  528. /* Calling Party Number (optional) */
  529. if (at_state->str_var[STR_NMBR]) {
  530. i = strlen(at_state->str_var[STR_NMBR]);
  531. if (i > MAX_NUMBER_DIGITS) {
  532. dev_warn(cs->dev, "RING ignored - bad number %s\n",
  533. at_state->str_var[STR_ZBC]);
  534. return ICALL_IGNORE;
  535. }
  536. iif->cgpty_buf[0] = i + 2;
  537. iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
  538. iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
  539. memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
  540. iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
  541. msgsize += iif->hcmsg.CallingPartyNumber[0];
  542. }
  543. /* remaining parameters (not supported, always left NULL):
  544. * - CalledPartySubaddress
  545. * - CallingPartySubaddress
  546. * - AdditionalInfo
  547. * - BChannelinformation
  548. * - Keypadfacility
  549. * - Useruserdata
  550. * - Facilitydataarray
  551. */
  552. gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
  553. iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
  554. format_ie(iif->hcmsg.BC));
  555. gig_dbg(DEBUG_CMD, "icall: HLC %s",
  556. format_ie(iif->hcmsg.HLC));
  557. gig_dbg(DEBUG_CMD, "icall: CgPty %s",
  558. format_ie(iif->hcmsg.CallingPartyNumber));
  559. gig_dbg(DEBUG_CMD, "icall: CdPty %s",
  560. format_ie(iif->hcmsg.CalledPartyNumber));
  561. /* scan application list for matching listeners */
  562. bcs->ap = NULL;
  563. actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
  564. list_for_each_entry(ap, &iif->appls, ctrlist)
  565. if (actCIPmask & ap->listenCIPmask) {
  566. /* build CONNECT_IND message for this application */
  567. iif->hcmsg.ApplId = ap->id;
  568. iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
  569. skb = alloc_skb(msgsize, GFP_ATOMIC);
  570. if (!skb) {
  571. dev_err(cs->dev, "%s: out of memory\n",
  572. __func__);
  573. break;
  574. }
  575. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  576. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  577. /* add to listeners on this B channel, update state */
  578. ap->bcnext = bcs->ap;
  579. bcs->ap = ap;
  580. bcs->chstate |= CHS_NOTIFY_LL;
  581. ap->connected = APCONN_SETUP;
  582. /* emit message */
  583. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  584. }
  585. /*
  586. * Return "accept" if any listeners.
  587. * Gigaset will send ALERTING.
  588. * There doesn't seem to be a way to avoid this.
  589. */
  590. return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
  591. }
  592. /*
  593. * send a DISCONNECT_IND message to an application
  594. * does not sleep, clobbers the controller's hcmsg structure
  595. */
  596. static void send_disconnect_ind(struct bc_state *bcs,
  597. struct gigaset_capi_appl *ap, u16 reason)
  598. {
  599. struct cardstate *cs = bcs->cs;
  600. struct gigaset_capi_ctr *iif = cs->iif;
  601. struct sk_buff *skb;
  602. if (ap->connected == APCONN_NONE)
  603. return;
  604. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
  605. ap->nextMessageNumber++,
  606. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  607. iif->hcmsg.Reason = reason;
  608. skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
  609. if (!skb) {
  610. dev_err(cs->dev, "%s: out of memory\n", __func__);
  611. return;
  612. }
  613. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
  614. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  615. ap->connected = APCONN_NONE;
  616. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  617. }
  618. /*
  619. * send a DISCONNECT_B3_IND message to an application
  620. * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
  621. * does not sleep, clobbers the controller's hcmsg structure
  622. */
  623. static void send_disconnect_b3_ind(struct bc_state *bcs,
  624. struct gigaset_capi_appl *ap)
  625. {
  626. struct cardstate *cs = bcs->cs;
  627. struct gigaset_capi_ctr *iif = cs->iif;
  628. struct sk_buff *skb;
  629. /* nothing to do if no logical connection active */
  630. if (ap->connected < APCONN_ACTIVE)
  631. return;
  632. ap->connected = APCONN_SETUP;
  633. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
  634. ap->nextMessageNumber++,
  635. iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
  636. skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
  637. if (!skb) {
  638. dev_err(cs->dev, "%s: out of memory\n", __func__);
  639. return;
  640. }
  641. capi_cmsg2message(&iif->hcmsg,
  642. __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
  643. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  644. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  645. }
  646. /**
  647. * gigaset_isdn_connD() - signal D channel connect
  648. * @bcs: B channel descriptor structure.
  649. *
  650. * Called by main module at tasklet level to notify the LL that the D channel
  651. * connection has been established.
  652. */
  653. void gigaset_isdn_connD(struct bc_state *bcs)
  654. {
  655. struct cardstate *cs = bcs->cs;
  656. struct gigaset_capi_ctr *iif = cs->iif;
  657. struct gigaset_capi_appl *ap = bcs->ap;
  658. struct sk_buff *skb;
  659. unsigned int msgsize;
  660. if (!ap) {
  661. dev_err(cs->dev, "%s: no application\n", __func__);
  662. return;
  663. }
  664. while (ap->bcnext) {
  665. /* this should never happen */
  666. dev_warn(cs->dev, "%s: dropping extra application %u\n",
  667. __func__, ap->bcnext->id);
  668. send_disconnect_ind(bcs, ap->bcnext,
  669. CapiCallGivenToOtherApplication);
  670. ap->bcnext = ap->bcnext->bcnext;
  671. }
  672. if (ap->connected == APCONN_NONE) {
  673. dev_warn(cs->dev, "%s: application %u not connected\n",
  674. __func__, ap->id);
  675. return;
  676. }
  677. /* prepare CONNECT_ACTIVE_IND message
  678. * Note: LLC not supported by device
  679. */
  680. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
  681. ap->nextMessageNumber++,
  682. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  683. /* minimum size, all structs empty */
  684. msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
  685. /* ToDo: set parameter: Connected number
  686. * (requires ev-layer state machine extension to collect
  687. * ZCON device reply)
  688. */
  689. /* build and emit CONNECT_ACTIVE_IND message */
  690. skb = alloc_skb(msgsize, GFP_ATOMIC);
  691. if (!skb) {
  692. dev_err(cs->dev, "%s: out of memory\n", __func__);
  693. return;
  694. }
  695. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  696. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  697. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  698. }
  699. /**
  700. * gigaset_isdn_hupD() - signal D channel hangup
  701. * @bcs: B channel descriptor structure.
  702. *
  703. * Called by main module at tasklet level to notify the LL that the D channel
  704. * connection has been shut down.
  705. */
  706. void gigaset_isdn_hupD(struct bc_state *bcs)
  707. {
  708. struct gigaset_capi_appl *ap;
  709. /*
  710. * ToDo: pass on reason code reported by device
  711. * (requires ev-layer state machine extension to collect
  712. * ZCAU device reply)
  713. */
  714. for (ap = bcs->ap; ap != NULL; ap = ap->bcnext) {
  715. send_disconnect_b3_ind(bcs, ap);
  716. send_disconnect_ind(bcs, ap, 0);
  717. }
  718. bcs->ap = NULL;
  719. }
  720. /**
  721. * gigaset_isdn_connB() - signal B channel connect
  722. * @bcs: B channel descriptor structure.
  723. *
  724. * Called by main module at tasklet level to notify the LL that the B channel
  725. * connection has been established.
  726. */
  727. void gigaset_isdn_connB(struct bc_state *bcs)
  728. {
  729. struct cardstate *cs = bcs->cs;
  730. struct gigaset_capi_ctr *iif = cs->iif;
  731. struct gigaset_capi_appl *ap = bcs->ap;
  732. struct sk_buff *skb;
  733. unsigned int msgsize;
  734. u8 command;
  735. if (!ap) {
  736. dev_err(cs->dev, "%s: no application\n", __func__);
  737. return;
  738. }
  739. while (ap->bcnext) {
  740. /* this should never happen */
  741. dev_warn(cs->dev, "%s: dropping extra application %u\n",
  742. __func__, ap->bcnext->id);
  743. send_disconnect_ind(bcs, ap->bcnext,
  744. CapiCallGivenToOtherApplication);
  745. ap->bcnext = ap->bcnext->bcnext;
  746. }
  747. if (!ap->connected) {
  748. dev_warn(cs->dev, "%s: application %u not connected\n",
  749. __func__, ap->id);
  750. return;
  751. }
  752. /*
  753. * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
  754. * otherwise we have to emit CONNECT_B3_IND first, and follow up with
  755. * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
  756. * Parameters in both cases always: NCCI = 1, NCPI empty
  757. */
  758. if (ap->connected >= APCONN_ACTIVE) {
  759. command = CAPI_CONNECT_B3_ACTIVE;
  760. msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
  761. } else {
  762. command = CAPI_CONNECT_B3;
  763. msgsize = CAPI_CONNECT_B3_IND_BASELEN;
  764. }
  765. capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
  766. ap->nextMessageNumber++,
  767. iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
  768. skb = alloc_skb(msgsize, GFP_ATOMIC);
  769. if (!skb) {
  770. dev_err(cs->dev, "%s: out of memory\n", __func__);
  771. return;
  772. }
  773. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  774. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  775. ap->connected = APCONN_ACTIVE;
  776. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  777. }
  778. /**
  779. * gigaset_isdn_hupB() - signal B channel hangup
  780. * @bcs: B channel descriptor structure.
  781. *
  782. * Called by main module to notify the LL that the B channel connection has
  783. * been shut down.
  784. */
  785. void gigaset_isdn_hupB(struct bc_state *bcs)
  786. {
  787. struct cardstate *cs = bcs->cs;
  788. struct gigaset_capi_appl *ap = bcs->ap;
  789. /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
  790. if (!ap) {
  791. dev_err(cs->dev, "%s: no application\n", __func__);
  792. return;
  793. }
  794. send_disconnect_b3_ind(bcs, ap);
  795. }
  796. /**
  797. * gigaset_isdn_start() - signal device availability
  798. * @cs: device descriptor structure.
  799. *
  800. * Called by main module to notify the LL that the device is available for
  801. * use.
  802. */
  803. void gigaset_isdn_start(struct cardstate *cs)
  804. {
  805. struct gigaset_capi_ctr *iif = cs->iif;
  806. /* fill profile data: manufacturer name */
  807. strcpy(iif->ctr.manu, "Siemens");
  808. /* CAPI and device version */
  809. iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
  810. iif->ctr.version.minorversion = 0;
  811. /* ToDo: check/assert cs->gotfwver? */
  812. iif->ctr.version.majormanuversion = cs->fwver[0];
  813. iif->ctr.version.minormanuversion = cs->fwver[1];
  814. /* number of B channels supported */
  815. iif->ctr.profile.nbchannel = cs->channels;
  816. /* global options: internal controller, supplementary services */
  817. iif->ctr.profile.goptions = 0x11;
  818. /* B1 protocols: 64 kbit/s HDLC or transparent */
  819. iif->ctr.profile.support1 = 0x03;
  820. /* B2 protocols: transparent only */
  821. /* ToDo: X.75 SLP ? */
  822. iif->ctr.profile.support2 = 0x02;
  823. /* B3 protocols: transparent only */
  824. iif->ctr.profile.support3 = 0x01;
  825. /* no serial number */
  826. strcpy(iif->ctr.serial, "0");
  827. capi_ctr_ready(&iif->ctr);
  828. }
  829. /**
  830. * gigaset_isdn_stop() - signal device unavailability
  831. * @cs: device descriptor structure.
  832. *
  833. * Called by main module to notify the LL that the device is no longer
  834. * available for use.
  835. */
  836. void gigaset_isdn_stop(struct cardstate *cs)
  837. {
  838. struct gigaset_capi_ctr *iif = cs->iif;
  839. capi_ctr_down(&iif->ctr);
  840. }
  841. /*
  842. * kernel CAPI callback methods
  843. * ============================
  844. */
  845. /*
  846. * load firmware
  847. */
  848. static int gigaset_load_firmware(struct capi_ctr *ctr, capiloaddata *data)
  849. {
  850. struct cardstate *cs = ctr->driverdata;
  851. /* AVM specific operation, not needed for Gigaset -- ignore */
  852. dev_notice(cs->dev, "load_firmware ignored\n");
  853. return 0;
  854. }
  855. /*
  856. * reset (deactivate) controller
  857. */
  858. static void gigaset_reset_ctr(struct capi_ctr *ctr)
  859. {
  860. struct cardstate *cs = ctr->driverdata;
  861. /* AVM specific operation, not needed for Gigaset -- ignore */
  862. dev_notice(cs->dev, "reset_ctr ignored\n");
  863. }
  864. /*
  865. * register CAPI application
  866. */
  867. static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
  868. capi_register_params *rp)
  869. {
  870. struct gigaset_capi_ctr *iif
  871. = container_of(ctr, struct gigaset_capi_ctr, ctr);
  872. struct cardstate *cs = ctr->driverdata;
  873. struct gigaset_capi_appl *ap;
  874. list_for_each_entry(ap, &iif->appls, ctrlist)
  875. if (ap->id == appl) {
  876. dev_notice(cs->dev,
  877. "application %u already registered\n", appl);
  878. return;
  879. }
  880. ap = kzalloc(sizeof(*ap), GFP_KERNEL);
  881. if (!ap) {
  882. dev_err(cs->dev, "%s: out of memory\n", __func__);
  883. return;
  884. }
  885. ap->id = appl;
  886. list_add(&ap->ctrlist, &iif->appls);
  887. }
  888. /*
  889. * release CAPI application
  890. */
  891. static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
  892. {
  893. struct gigaset_capi_ctr *iif
  894. = container_of(ctr, struct gigaset_capi_ctr, ctr);
  895. struct cardstate *cs = iif->ctr.driverdata;
  896. struct gigaset_capi_appl *ap, *tmp;
  897. list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
  898. if (ap->id == appl) {
  899. if (ap->connected != APCONN_NONE) {
  900. dev_err(cs->dev,
  901. "%s: application %u still connected\n",
  902. __func__, ap->id);
  903. /* ToDo: clear active connection */
  904. }
  905. list_del(&ap->ctrlist);
  906. kfree(ap);
  907. }
  908. }
  909. /*
  910. * =====================================================================
  911. * outgoing CAPI message handler
  912. * =====================================================================
  913. */
  914. /*
  915. * helper function: emit reply message with given Info value
  916. */
  917. static void send_conf(struct gigaset_capi_ctr *iif,
  918. struct gigaset_capi_appl *ap,
  919. struct sk_buff *skb,
  920. u16 info)
  921. {
  922. /*
  923. * _CONF replies always only have NCCI and Info parameters
  924. * so they'll fit into the _REQ message skb
  925. */
  926. capi_cmsg_answer(&iif->acmsg);
  927. iif->acmsg.Info = info;
  928. capi_cmsg2message(&iif->acmsg, skb->data);
  929. __skb_trim(skb, CAPI_STDCONF_LEN);
  930. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  931. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  932. }
  933. /*
  934. * process FACILITY_REQ message
  935. */
  936. static void do_facility_req(struct gigaset_capi_ctr *iif,
  937. struct gigaset_capi_appl *ap,
  938. struct sk_buff *skb)
  939. {
  940. struct cardstate *cs = iif->ctr.driverdata;
  941. _cmsg *cmsg = &iif->acmsg;
  942. struct sk_buff *cskb;
  943. u8 *pparam;
  944. unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
  945. u16 function, info;
  946. static u8 confparam[10]; /* max. 9 octets + length byte */
  947. /* decode message */
  948. capi_message2cmsg(cmsg, skb->data);
  949. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  950. /*
  951. * Facility Request Parameter is not decoded by capi_message2cmsg()
  952. * encoding depends on Facility Selector
  953. */
  954. switch (cmsg->FacilitySelector) {
  955. case CAPI_FACILITY_DTMF: /* ToDo */
  956. info = CapiFacilityNotSupported;
  957. confparam[0] = 2; /* length */
  958. /* DTMF information: Unknown DTMF request */
  959. capimsg_setu16(confparam, 1, 2);
  960. break;
  961. case CAPI_FACILITY_V42BIS: /* not supported */
  962. info = CapiFacilityNotSupported;
  963. confparam[0] = 2; /* length */
  964. /* V.42 bis information: not available */
  965. capimsg_setu16(confparam, 1, 1);
  966. break;
  967. case CAPI_FACILITY_SUPPSVC:
  968. /* decode Function parameter */
  969. pparam = cmsg->FacilityRequestParameter;
  970. if (pparam == NULL || *pparam < 2) {
  971. dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
  972. "Facility Request Parameter");
  973. send_conf(iif, ap, skb, CapiIllMessageParmCoding);
  974. return;
  975. }
  976. function = CAPIMSG_U16(pparam, 1);
  977. switch (function) {
  978. case CAPI_SUPPSVC_GETSUPPORTED:
  979. info = CapiSuccess;
  980. /* Supplementary Service specific parameter */
  981. confparam[3] = 6; /* length */
  982. /* Supplementary services info: Success */
  983. capimsg_setu16(confparam, 4, CapiSuccess);
  984. /* Supported Services: none */
  985. capimsg_setu32(confparam, 6, 0);
  986. break;
  987. /* ToDo: add supported services */
  988. default:
  989. info = CapiFacilitySpecificFunctionNotSupported;
  990. /* Supplementary Service specific parameter */
  991. confparam[3] = 2; /* length */
  992. /* Supplementary services info: not supported */
  993. capimsg_setu16(confparam, 4,
  994. CapiSupplementaryServiceNotSupported);
  995. }
  996. /* Facility confirmation parameter */
  997. confparam[0] = confparam[3] + 3; /* total length */
  998. /* Function: copy from _REQ message */
  999. capimsg_setu16(confparam, 1, function);
  1000. /* Supplementary Service specific parameter already set above */
  1001. break;
  1002. case CAPI_FACILITY_WAKEUP: /* ToDo */
  1003. info = CapiFacilityNotSupported;
  1004. confparam[0] = 2; /* length */
  1005. /* Number of accepted awake request parameters: 0 */
  1006. capimsg_setu16(confparam, 1, 0);
  1007. break;
  1008. default:
  1009. info = CapiFacilityNotSupported;
  1010. confparam[0] = 0; /* empty struct */
  1011. }
  1012. /* send FACILITY_CONF with given Info and confirmation parameter */
  1013. capi_cmsg_answer(cmsg);
  1014. cmsg->Info = info;
  1015. cmsg->FacilityConfirmationParameter = confparam;
  1016. msgsize += confparam[0]; /* length */
  1017. cskb = alloc_skb(msgsize, GFP_ATOMIC);
  1018. if (!cskb) {
  1019. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1020. return;
  1021. }
  1022. capi_cmsg2message(cmsg, __skb_put(cskb, msgsize));
  1023. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1024. capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
  1025. }
  1026. /*
  1027. * process LISTEN_REQ message
  1028. * just store the masks in the application data structure
  1029. */
  1030. static void do_listen_req(struct gigaset_capi_ctr *iif,
  1031. struct gigaset_capi_appl *ap,
  1032. struct sk_buff *skb)
  1033. {
  1034. /* decode message */
  1035. capi_message2cmsg(&iif->acmsg, skb->data);
  1036. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1037. /* store listening parameters */
  1038. ap->listenInfoMask = iif->acmsg.InfoMask;
  1039. ap->listenCIPmask = iif->acmsg.CIPmask;
  1040. send_conf(iif, ap, skb, CapiSuccess);
  1041. }
  1042. /*
  1043. * process ALERT_REQ message
  1044. * nothing to do, Gigaset always alerts anyway
  1045. */
  1046. static void do_alert_req(struct gigaset_capi_ctr *iif,
  1047. struct gigaset_capi_appl *ap,
  1048. struct sk_buff *skb)
  1049. {
  1050. /* decode message */
  1051. capi_message2cmsg(&iif->acmsg, skb->data);
  1052. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1053. send_conf(iif, ap, skb, CapiAlertAlreadySent);
  1054. }
  1055. /*
  1056. * process CONNECT_REQ message
  1057. * allocate a B channel, prepare dial commands, queue a DIAL event,
  1058. * emit CONNECT_CONF reply
  1059. */
  1060. static void do_connect_req(struct gigaset_capi_ctr *iif,
  1061. struct gigaset_capi_appl *ap,
  1062. struct sk_buff *skb)
  1063. {
  1064. struct cardstate *cs = iif->ctr.driverdata;
  1065. _cmsg *cmsg = &iif->acmsg;
  1066. struct bc_state *bcs;
  1067. char **commands;
  1068. char *s;
  1069. u8 *pp;
  1070. int i, l;
  1071. u16 info;
  1072. /* decode message */
  1073. capi_message2cmsg(cmsg, skb->data);
  1074. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1075. /* get free B channel & construct PLCI */
  1076. bcs = gigaset_get_free_channel(cs);
  1077. if (!bcs) {
  1078. dev_notice(cs->dev, "%s: no B channel available\n",
  1079. "CONNECT_REQ");
  1080. send_conf(iif, ap, skb, CapiNoPlciAvailable);
  1081. return;
  1082. }
  1083. ap->bcnext = NULL;
  1084. bcs->ap = ap;
  1085. cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
  1086. /* build command table */
  1087. commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
  1088. if (!commands)
  1089. goto oom;
  1090. /* encode parameter: Called party number */
  1091. pp = cmsg->CalledPartyNumber;
  1092. if (pp == NULL || *pp == 0) {
  1093. dev_notice(cs->dev, "%s: %s missing\n",
  1094. "CONNECT_REQ", "Called party number");
  1095. info = CapiIllMessageParmCoding;
  1096. goto error;
  1097. }
  1098. l = *pp++;
  1099. /* check type of number/numbering plan byte */
  1100. switch (*pp) {
  1101. case 0x80: /* unknown type / unknown numbering plan */
  1102. case 0x81: /* unknown type / ISDN/Telephony numbering plan */
  1103. break;
  1104. default: /* others: warn about potential misinterpretation */
  1105. dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
  1106. "CONNECT_REQ", "Called party number", *pp);
  1107. }
  1108. pp++;
  1109. l--;
  1110. /* translate "**" internal call prefix to CTP value */
  1111. if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
  1112. s = "^SCTP=0\r";
  1113. pp += 2;
  1114. l -= 2;
  1115. } else {
  1116. s = "^SCTP=1\r";
  1117. }
  1118. commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
  1119. if (!commands[AT_TYPE])
  1120. goto oom;
  1121. commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
  1122. if (!commands[AT_DIAL])
  1123. goto oom;
  1124. snprintf(commands[AT_DIAL], l+3, "D%.*s\r", l, pp);
  1125. /* encode parameter: Calling party number */
  1126. pp = cmsg->CallingPartyNumber;
  1127. if (pp != NULL && *pp > 0) {
  1128. l = *pp++;
  1129. /* check type of number/numbering plan byte */
  1130. /* ToDo: allow for/handle Ext=1? */
  1131. switch (*pp) {
  1132. case 0x00: /* unknown type / unknown numbering plan */
  1133. case 0x01: /* unknown type / ISDN/Telephony num. plan */
  1134. break;
  1135. default:
  1136. dev_notice(cs->dev,
  1137. "%s: %s type/plan 0x%02x unsupported\n",
  1138. "CONNECT_REQ", "Calling party number", *pp);
  1139. }
  1140. pp++;
  1141. l--;
  1142. /* check presentation indicator */
  1143. if (!l) {
  1144. dev_notice(cs->dev, "%s: %s IE truncated\n",
  1145. "CONNECT_REQ", "Calling party number");
  1146. info = CapiIllMessageParmCoding;
  1147. goto error;
  1148. }
  1149. switch (*pp & 0xfc) { /* ignore Screening indicator */
  1150. case 0x80: /* Presentation allowed */
  1151. s = "^SCLIP=1\r";
  1152. break;
  1153. case 0xa0: /* Presentation restricted */
  1154. s = "^SCLIP=0\r";
  1155. break;
  1156. default:
  1157. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1158. "CONNECT_REQ",
  1159. "Presentation/Screening indicator",
  1160. *pp);
  1161. s = "^SCLIP=1\r";
  1162. }
  1163. commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
  1164. if (!commands[AT_CLIP])
  1165. goto oom;
  1166. pp++;
  1167. l--;
  1168. if (l) {
  1169. /* number */
  1170. commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
  1171. if (!commands[AT_MSN])
  1172. goto oom;
  1173. snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
  1174. }
  1175. }
  1176. /* check parameter: CIP Value */
  1177. if (cmsg->CIPValue >= ARRAY_SIZE(cip2bchlc) ||
  1178. (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
  1179. dev_notice(cs->dev, "%s: unknown CIP value %d\n",
  1180. "CONNECT_REQ", cmsg->CIPValue);
  1181. info = CapiCipValueUnknown;
  1182. goto error;
  1183. }
  1184. /* check/encode parameter: BC */
  1185. if (cmsg->BC && cmsg->BC[0]) {
  1186. /* explicit BC overrides CIP */
  1187. l = 2*cmsg->BC[0] + 7;
  1188. commands[AT_BC] = kmalloc(l, GFP_KERNEL);
  1189. if (!commands[AT_BC])
  1190. goto oom;
  1191. strcpy(commands[AT_BC], "^SBC=");
  1192. decode_ie(cmsg->BC, commands[AT_BC]+5);
  1193. strcpy(commands[AT_BC] + l - 2, "\r");
  1194. } else if (cip2bchlc[cmsg->CIPValue].bc) {
  1195. l = strlen(cip2bchlc[cmsg->CIPValue].bc) + 7;
  1196. commands[AT_BC] = kmalloc(l, GFP_KERNEL);
  1197. if (!commands[AT_BC])
  1198. goto oom;
  1199. snprintf(commands[AT_BC], l, "^SBC=%s\r",
  1200. cip2bchlc[cmsg->CIPValue].bc);
  1201. }
  1202. /* check/encode parameter: HLC */
  1203. if (cmsg->HLC && cmsg->HLC[0]) {
  1204. /* explicit HLC overrides CIP */
  1205. l = 2*cmsg->HLC[0] + 7;
  1206. commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
  1207. if (!commands[AT_HLC])
  1208. goto oom;
  1209. strcpy(commands[AT_HLC], "^SHLC=");
  1210. decode_ie(cmsg->HLC, commands[AT_HLC]+5);
  1211. strcpy(commands[AT_HLC] + l - 2, "\r");
  1212. } else if (cip2bchlc[cmsg->CIPValue].hlc) {
  1213. l = strlen(cip2bchlc[cmsg->CIPValue].hlc) + 7;
  1214. commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
  1215. if (!commands[AT_HLC])
  1216. goto oom;
  1217. snprintf(commands[AT_HLC], l, "^SHLC=%s\r",
  1218. cip2bchlc[cmsg->CIPValue].hlc);
  1219. }
  1220. /* check/encode parameter: B Protocol */
  1221. if (cmsg->BProtocol == CAPI_DEFAULT) {
  1222. bcs->proto2 = L2_HDLC;
  1223. dev_warn(cs->dev,
  1224. "B2 Protocol X.75 SLP unsupported, using Transparent\n");
  1225. } else {
  1226. switch (cmsg->B1protocol) {
  1227. case 0:
  1228. bcs->proto2 = L2_HDLC;
  1229. break;
  1230. case 1:
  1231. bcs->proto2 = L2_BITSYNC;
  1232. break;
  1233. default:
  1234. dev_warn(cs->dev,
  1235. "B1 Protocol %u unsupported, using Transparent\n",
  1236. cmsg->B1protocol);
  1237. bcs->proto2 = L2_BITSYNC;
  1238. }
  1239. if (cmsg->B2protocol != 1)
  1240. dev_warn(cs->dev,
  1241. "B2 Protocol %u unsupported, using Transparent\n",
  1242. cmsg->B2protocol);
  1243. if (cmsg->B3protocol != 0)
  1244. dev_warn(cs->dev,
  1245. "B3 Protocol %u unsupported, using Transparent\n",
  1246. cmsg->B3protocol);
  1247. ignore_cstruct_param(cs, cmsg->B1configuration,
  1248. "CONNECT_REQ", "B1 Configuration");
  1249. ignore_cstruct_param(cs, cmsg->B2configuration,
  1250. "CONNECT_REQ", "B2 Configuration");
  1251. ignore_cstruct_param(cs, cmsg->B3configuration,
  1252. "CONNECT_REQ", "B3 Configuration");
  1253. }
  1254. commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
  1255. if (!commands[AT_PROTO])
  1256. goto oom;
  1257. snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
  1258. /* ToDo: check/encode remaining parameters */
  1259. ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
  1260. "CONNECT_REQ", "Called pty subaddr");
  1261. ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
  1262. "CONNECT_REQ", "Calling pty subaddr");
  1263. ignore_cstruct_param(cs, cmsg->LLC,
  1264. "CONNECT_REQ", "LLC");
  1265. if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
  1266. ignore_cstruct_param(cs, cmsg->BChannelinformation,
  1267. "CONNECT_REQ", "B Channel Information");
  1268. ignore_cstruct_param(cs, cmsg->Keypadfacility,
  1269. "CONNECT_REQ", "Keypad Facility");
  1270. ignore_cstruct_param(cs, cmsg->Useruserdata,
  1271. "CONNECT_REQ", "User-User Data");
  1272. ignore_cstruct_param(cs, cmsg->Facilitydataarray,
  1273. "CONNECT_REQ", "Facility Data Array");
  1274. }
  1275. /* encode parameter: B channel to use */
  1276. commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
  1277. if (!commands[AT_ISO])
  1278. goto oom;
  1279. snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
  1280. (unsigned) bcs->channel + 1);
  1281. /* queue & schedule EV_DIAL event */
  1282. if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
  1283. bcs->at_state.seq_index, NULL)) {
  1284. info = CAPI_MSGOSRESOURCEERR;
  1285. goto error;
  1286. }
  1287. gigaset_schedule_event(cs);
  1288. ap->connected = APCONN_SETUP;
  1289. send_conf(iif, ap, skb, CapiSuccess);
  1290. return;
  1291. oom:
  1292. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1293. info = CAPI_MSGOSRESOURCEERR;
  1294. error:
  1295. if (commands)
  1296. for (i = 0; i < AT_NUM; i++)
  1297. kfree(commands[i]);
  1298. kfree(commands);
  1299. gigaset_free_channel(bcs);
  1300. send_conf(iif, ap, skb, info);
  1301. }
  1302. /*
  1303. * process CONNECT_RESP message
  1304. * checks protocol parameters and queues an ACCEPT or HUP event
  1305. */
  1306. static void do_connect_resp(struct gigaset_capi_ctr *iif,
  1307. struct gigaset_capi_appl *ap,
  1308. struct sk_buff *skb)
  1309. {
  1310. struct cardstate *cs = iif->ctr.driverdata;
  1311. _cmsg *cmsg = &iif->acmsg;
  1312. struct bc_state *bcs;
  1313. struct gigaset_capi_appl *oap;
  1314. int channel;
  1315. /* decode message */
  1316. capi_message2cmsg(cmsg, skb->data);
  1317. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1318. dev_kfree_skb_any(skb);
  1319. /* extract and check channel number from PLCI */
  1320. channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
  1321. if (!channel || channel > cs->channels) {
  1322. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1323. "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
  1324. return;
  1325. }
  1326. bcs = cs->bcs + channel - 1;
  1327. switch (cmsg->Reject) {
  1328. case 0: /* Accept */
  1329. /* drop all competing applications, keep only this one */
  1330. for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
  1331. if (oap != ap)
  1332. send_disconnect_ind(bcs, oap,
  1333. CapiCallGivenToOtherApplication);
  1334. ap->bcnext = NULL;
  1335. bcs->ap = ap;
  1336. bcs->chstate |= CHS_NOTIFY_LL;
  1337. /* check/encode B channel protocol */
  1338. if (cmsg->BProtocol == CAPI_DEFAULT) {
  1339. bcs->proto2 = L2_HDLC;
  1340. dev_warn(cs->dev,
  1341. "B2 Protocol X.75 SLP unsupported, using Transparent\n");
  1342. } else {
  1343. switch (cmsg->B1protocol) {
  1344. case 0:
  1345. bcs->proto2 = L2_HDLC;
  1346. break;
  1347. case 1:
  1348. bcs->proto2 = L2_BITSYNC;
  1349. break;
  1350. default:
  1351. dev_warn(cs->dev,
  1352. "B1 Protocol %u unsupported, using Transparent\n",
  1353. cmsg->B1protocol);
  1354. bcs->proto2 = L2_BITSYNC;
  1355. }
  1356. if (cmsg->B2protocol != 1)
  1357. dev_warn(cs->dev,
  1358. "B2 Protocol %u unsupported, using Transparent\n",
  1359. cmsg->B2protocol);
  1360. if (cmsg->B3protocol != 0)
  1361. dev_warn(cs->dev,
  1362. "B3 Protocol %u unsupported, using Transparent\n",
  1363. cmsg->B3protocol);
  1364. ignore_cstruct_param(cs, cmsg->B1configuration,
  1365. "CONNECT_RESP", "B1 Configuration");
  1366. ignore_cstruct_param(cs, cmsg->B2configuration,
  1367. "CONNECT_RESP", "B2 Configuration");
  1368. ignore_cstruct_param(cs, cmsg->B3configuration,
  1369. "CONNECT_RESP", "B3 Configuration");
  1370. }
  1371. /* ToDo: check/encode remaining parameters */
  1372. ignore_cstruct_param(cs, cmsg->ConnectedNumber,
  1373. "CONNECT_RESP", "Connected Number");
  1374. ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
  1375. "CONNECT_RESP", "Connected Subaddress");
  1376. ignore_cstruct_param(cs, cmsg->LLC,
  1377. "CONNECT_RESP", "LLC");
  1378. if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
  1379. ignore_cstruct_param(cs, cmsg->BChannelinformation,
  1380. "CONNECT_RESP", "BChannel Information");
  1381. ignore_cstruct_param(cs, cmsg->Keypadfacility,
  1382. "CONNECT_RESP", "Keypad Facility");
  1383. ignore_cstruct_param(cs, cmsg->Useruserdata,
  1384. "CONNECT_RESP", "User-User Data");
  1385. ignore_cstruct_param(cs, cmsg->Facilitydataarray,
  1386. "CONNECT_RESP", "Facility Data Array");
  1387. }
  1388. /* Accept call */
  1389. if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
  1390. EV_ACCEPT, NULL, 0, NULL))
  1391. return;
  1392. gigaset_schedule_event(cs);
  1393. return;
  1394. case 1: /* Ignore */
  1395. /* send DISCONNECT_IND to this application */
  1396. send_disconnect_ind(bcs, ap, 0);
  1397. /* remove it from the list of listening apps */
  1398. if (bcs->ap == ap) {
  1399. bcs->ap = ap->bcnext;
  1400. if (bcs->ap == NULL)
  1401. /* last one: stop ev-layer hupD notifications */
  1402. bcs->chstate &= ~CHS_NOTIFY_LL;
  1403. return;
  1404. }
  1405. for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
  1406. if (oap->bcnext == ap) {
  1407. oap->bcnext = oap->bcnext->bcnext;
  1408. return;
  1409. }
  1410. }
  1411. dev_err(cs->dev, "%s: application %u not found\n",
  1412. __func__, ap->id);
  1413. return;
  1414. default: /* Reject */
  1415. /* drop all competing applications, keep only this one */
  1416. for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
  1417. if (oap != ap)
  1418. send_disconnect_ind(bcs, oap,
  1419. CapiCallGivenToOtherApplication);
  1420. ap->bcnext = NULL;
  1421. bcs->ap = ap;
  1422. /* reject call - will trigger DISCONNECT_IND for this app */
  1423. dev_info(cs->dev, "%s: Reject=%x\n",
  1424. "CONNECT_RESP", cmsg->Reject);
  1425. if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
  1426. EV_HUP, NULL, 0, NULL))
  1427. return;
  1428. gigaset_schedule_event(cs);
  1429. return;
  1430. }
  1431. }
  1432. /*
  1433. * process CONNECT_B3_REQ message
  1434. * build NCCI and emit CONNECT_B3_CONF reply
  1435. */
  1436. static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
  1437. struct gigaset_capi_appl *ap,
  1438. struct sk_buff *skb)
  1439. {
  1440. struct cardstate *cs = iif->ctr.driverdata;
  1441. _cmsg *cmsg = &iif->acmsg;
  1442. int channel;
  1443. /* decode message */
  1444. capi_message2cmsg(cmsg, skb->data);
  1445. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1446. /* extract and check channel number from PLCI */
  1447. channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
  1448. if (!channel || channel > cs->channels) {
  1449. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1450. "CONNECT_B3_REQ", "PLCI", cmsg->adr.adrPLCI);
  1451. send_conf(iif, ap, skb, CapiIllContrPlciNcci);
  1452. return;
  1453. }
  1454. /* mark logical connection active */
  1455. ap->connected = APCONN_ACTIVE;
  1456. /* build NCCI: always 1 (one B3 connection only) */
  1457. cmsg->adr.adrNCCI |= 1 << 16;
  1458. /* NCPI parameter: not applicable for B3 Transparent */
  1459. ignore_cstruct_param(cs, cmsg->NCPI, "CONNECT_B3_REQ", "NCPI");
  1460. send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
  1461. CapiNcpiNotSupportedByProtocol : CapiSuccess);
  1462. }
  1463. /*
  1464. * process CONNECT_B3_RESP message
  1465. * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
  1466. * or queue EV_HUP and emit DISCONNECT_B3_IND.
  1467. * The emitted message is always shorter than the received one,
  1468. * allowing to reuse the skb.
  1469. */
  1470. static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
  1471. struct gigaset_capi_appl *ap,
  1472. struct sk_buff *skb)
  1473. {
  1474. struct cardstate *cs = iif->ctr.driverdata;
  1475. _cmsg *cmsg = &iif->acmsg;
  1476. struct bc_state *bcs;
  1477. int channel;
  1478. unsigned int msgsize;
  1479. u8 command;
  1480. /* decode message */
  1481. capi_message2cmsg(cmsg, skb->data);
  1482. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1483. /* extract and check channel number and NCCI */
  1484. channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
  1485. if (!channel || channel > cs->channels ||
  1486. ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
  1487. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1488. "CONNECT_B3_RESP", "NCCI", cmsg->adr.adrNCCI);
  1489. dev_kfree_skb_any(skb);
  1490. return;
  1491. }
  1492. bcs = &cs->bcs[channel-1];
  1493. if (cmsg->Reject) {
  1494. /* Reject: clear B3 connect received flag */
  1495. ap->connected = APCONN_SETUP;
  1496. /* trigger hangup, causing eventual DISCONNECT_IND */
  1497. if (!gigaset_add_event(cs, &bcs->at_state,
  1498. EV_HUP, NULL, 0, NULL)) {
  1499. dev_kfree_skb_any(skb);
  1500. return;
  1501. }
  1502. gigaset_schedule_event(cs);
  1503. /* emit DISCONNECT_B3_IND */
  1504. command = CAPI_DISCONNECT_B3;
  1505. msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
  1506. } else {
  1507. /*
  1508. * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
  1509. * we only send CONNECT_B3_IND if the B channel is up
  1510. */
  1511. command = CAPI_CONNECT_B3_ACTIVE;
  1512. msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
  1513. }
  1514. capi_cmsg_header(cmsg, ap->id, command, CAPI_IND,
  1515. ap->nextMessageNumber++, cmsg->adr.adrNCCI);
  1516. __skb_trim(skb, msgsize);
  1517. capi_cmsg2message(cmsg, skb->data);
  1518. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1519. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  1520. }
  1521. /*
  1522. * process DISCONNECT_REQ message
  1523. * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
  1524. * emit DISCONNECT_CONF reply
  1525. */
  1526. static void do_disconnect_req(struct gigaset_capi_ctr *iif,
  1527. struct gigaset_capi_appl *ap,
  1528. struct sk_buff *skb)
  1529. {
  1530. struct cardstate *cs = iif->ctr.driverdata;
  1531. _cmsg *cmsg = &iif->acmsg;
  1532. struct bc_state *bcs;
  1533. _cmsg *b3cmsg;
  1534. struct sk_buff *b3skb;
  1535. int channel;
  1536. /* decode message */
  1537. capi_message2cmsg(cmsg, skb->data);
  1538. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1539. /* extract and check channel number from PLCI */
  1540. channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
  1541. if (!channel || channel > cs->channels) {
  1542. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1543. "DISCONNECT_REQ", "PLCI", cmsg->adr.adrPLCI);
  1544. send_conf(iif, ap, skb, CapiIllContrPlciNcci);
  1545. return;
  1546. }
  1547. bcs = cs->bcs + channel - 1;
  1548. /* ToDo: process parameter: Additional info */
  1549. if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
  1550. ignore_cstruct_param(cs, cmsg->BChannelinformation,
  1551. "DISCONNECT_REQ", "B Channel Information");
  1552. ignore_cstruct_param(cs, cmsg->Keypadfacility,
  1553. "DISCONNECT_REQ", "Keypad Facility");
  1554. ignore_cstruct_param(cs, cmsg->Useruserdata,
  1555. "DISCONNECT_REQ", "User-User Data");
  1556. ignore_cstruct_param(cs, cmsg->Facilitydataarray,
  1557. "DISCONNECT_REQ", "Facility Data Array");
  1558. }
  1559. /* skip if DISCONNECT_IND already sent */
  1560. if (!ap->connected)
  1561. return;
  1562. /* check for active logical connection */
  1563. if (ap->connected >= APCONN_ACTIVE) {
  1564. /*
  1565. * emit DISCONNECT_B3_IND with cause 0x3301
  1566. * use separate cmsg structure, as the content of iif->acmsg
  1567. * is still needed for creating the _CONF message
  1568. */
  1569. b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
  1570. if (!b3cmsg) {
  1571. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1572. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1573. return;
  1574. }
  1575. capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
  1576. ap->nextMessageNumber++,
  1577. cmsg->adr.adrPLCI | (1 << 16));
  1578. b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
  1579. b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
  1580. if (b3skb == NULL) {
  1581. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1582. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1583. return;
  1584. }
  1585. capi_cmsg2message(b3cmsg,
  1586. __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
  1587. kfree(b3cmsg);
  1588. capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
  1589. }
  1590. /* trigger hangup, causing eventual DISCONNECT_IND */
  1591. if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
  1592. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1593. return;
  1594. }
  1595. gigaset_schedule_event(cs);
  1596. /* emit reply */
  1597. send_conf(iif, ap, skb, CapiSuccess);
  1598. }
  1599. /*
  1600. * process DISCONNECT_B3_REQ message
  1601. * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
  1602. */
  1603. static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
  1604. struct gigaset_capi_appl *ap,
  1605. struct sk_buff *skb)
  1606. {
  1607. struct cardstate *cs = iif->ctr.driverdata;
  1608. _cmsg *cmsg = &iif->acmsg;
  1609. int channel;
  1610. /* decode message */
  1611. capi_message2cmsg(cmsg, skb->data);
  1612. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1613. /* extract and check channel number and NCCI */
  1614. channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
  1615. if (!channel || channel > cs->channels ||
  1616. ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
  1617. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1618. "DISCONNECT_B3_REQ", "NCCI", cmsg->adr.adrNCCI);
  1619. send_conf(iif, ap, skb, CapiIllContrPlciNcci);
  1620. return;
  1621. }
  1622. /* reject if logical connection not active */
  1623. if (ap->connected < APCONN_ACTIVE) {
  1624. send_conf(iif, ap, skb,
  1625. CapiMessageNotSupportedInCurrentState);
  1626. return;
  1627. }
  1628. /* trigger hangup, causing eventual DISCONNECT_B3_IND */
  1629. if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
  1630. EV_HUP, NULL, 0, NULL)) {
  1631. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1632. return;
  1633. }
  1634. gigaset_schedule_event(cs);
  1635. /* NCPI parameter: not applicable for B3 Transparent */
  1636. ignore_cstruct_param(cs, cmsg->NCPI,
  1637. "DISCONNECT_B3_REQ", "NCPI");
  1638. send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
  1639. CapiNcpiNotSupportedByProtocol : CapiSuccess);
  1640. }
  1641. /*
  1642. * process DATA_B3_REQ message
  1643. */
  1644. static void do_data_b3_req(struct gigaset_capi_ctr *iif,
  1645. struct gigaset_capi_appl *ap,
  1646. struct sk_buff *skb)
  1647. {
  1648. struct cardstate *cs = iif->ctr.driverdata;
  1649. int channel = CAPIMSG_PLCI_PART(skb->data);
  1650. u16 ncci = CAPIMSG_NCCI_PART(skb->data);
  1651. u16 msglen = CAPIMSG_LEN(skb->data);
  1652. u16 datalen = CAPIMSG_DATALEN(skb->data);
  1653. u16 flags = CAPIMSG_FLAGS(skb->data);
  1654. /* frequent message, avoid _cmsg overhead */
  1655. dump_rawmsg(DEBUG_LLDATA, "DATA_B3_REQ", skb->data);
  1656. gig_dbg(DEBUG_LLDATA,
  1657. "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
  1658. channel, flags, msglen, datalen);
  1659. /* check parameters */
  1660. if (channel == 0 || channel > cs->channels || ncci != 1) {
  1661. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1662. "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
  1663. send_conf(iif, ap, skb, CapiIllContrPlciNcci);
  1664. return;
  1665. }
  1666. if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
  1667. dev_notice(cs->dev, "%s: unexpected length %d\n",
  1668. "DATA_B3_REQ", msglen);
  1669. if (msglen + datalen != skb->len)
  1670. dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
  1671. "DATA_B3_REQ", msglen, datalen, skb->len);
  1672. if (msglen + datalen > skb->len) {
  1673. /* message too short for announced data length */
  1674. send_conf(iif, ap, skb, CapiIllMessageParmCoding); /* ? */
  1675. return;
  1676. }
  1677. if (flags & CAPI_FLAGS_RESERVED) {
  1678. dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
  1679. "DATA_B3_REQ", flags);
  1680. send_conf(iif, ap, skb, CapiIllMessageParmCoding);
  1681. return;
  1682. }
  1683. /* reject if logical connection not active */
  1684. if (ap->connected < APCONN_ACTIVE) {
  1685. send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
  1686. return;
  1687. }
  1688. /* pull CAPI message into link layer header */
  1689. skb_reset_mac_header(skb);
  1690. skb->mac_len = msglen;
  1691. skb_pull(skb, msglen);
  1692. /* pass to device-specific module */
  1693. if (cs->ops->send_skb(&cs->bcs[channel-1], skb) < 0) {
  1694. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1695. return;
  1696. }
  1697. /* DATA_B3_CONF reply will be sent by gigaset_skb_sent() */
  1698. /*
  1699. * ToDo: honor unset "delivery confirmation" bit
  1700. * (send DATA_B3_CONF immediately?)
  1701. */
  1702. }
  1703. /*
  1704. * process RESET_B3_REQ message
  1705. * just always reply "not supported by current protocol"
  1706. */
  1707. static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
  1708. struct gigaset_capi_appl *ap,
  1709. struct sk_buff *skb)
  1710. {
  1711. /* decode message */
  1712. capi_message2cmsg(&iif->acmsg, skb->data);
  1713. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1714. send_conf(iif, ap, skb,
  1715. CapiResetProcedureNotSupportedByCurrentProtocol);
  1716. }
  1717. /*
  1718. * dump unsupported/ignored messages at most twice per minute,
  1719. * some apps send those very frequently
  1720. */
  1721. static unsigned long ignored_msg_dump_time;
  1722. /*
  1723. * unsupported CAPI message handler
  1724. */
  1725. static void do_unsupported(struct gigaset_capi_ctr *iif,
  1726. struct gigaset_capi_appl *ap,
  1727. struct sk_buff *skb)
  1728. {
  1729. /* decode message */
  1730. capi_message2cmsg(&iif->acmsg, skb->data);
  1731. if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000))
  1732. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1733. send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
  1734. }
  1735. /*
  1736. * CAPI message handler: no-op
  1737. */
  1738. static void do_nothing(struct gigaset_capi_ctr *iif,
  1739. struct gigaset_capi_appl *ap,
  1740. struct sk_buff *skb)
  1741. {
  1742. if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000)) {
  1743. /* decode message */
  1744. capi_message2cmsg(&iif->acmsg, skb->data);
  1745. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1746. }
  1747. dev_kfree_skb_any(skb);
  1748. }
  1749. static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
  1750. struct gigaset_capi_appl *ap,
  1751. struct sk_buff *skb)
  1752. {
  1753. dump_rawmsg(DEBUG_LLDATA, __func__, skb->data);
  1754. dev_kfree_skb_any(skb);
  1755. }
  1756. /* table of outgoing CAPI message handlers with lookup function */
  1757. typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
  1758. struct gigaset_capi_appl *,
  1759. struct sk_buff *);
  1760. static struct {
  1761. u16 cmd;
  1762. capi_send_handler_t handler;
  1763. } capi_send_handler_table[] = {
  1764. /* most frequent messages first for faster lookup */
  1765. { CAPI_DATA_B3_REQ, do_data_b3_req },
  1766. { CAPI_DATA_B3_RESP, do_data_b3_resp },
  1767. { CAPI_ALERT_REQ, do_alert_req },
  1768. { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
  1769. { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
  1770. { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
  1771. { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
  1772. { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
  1773. { CAPI_CONNECT_REQ, do_connect_req },
  1774. { CAPI_CONNECT_RESP, do_connect_resp },
  1775. { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
  1776. { CAPI_DISCONNECT_B3_RESP, do_nothing },
  1777. { CAPI_DISCONNECT_REQ, do_disconnect_req },
  1778. { CAPI_DISCONNECT_RESP, do_nothing },
  1779. { CAPI_FACILITY_REQ, do_facility_req },
  1780. { CAPI_FACILITY_RESP, do_nothing },
  1781. { CAPI_LISTEN_REQ, do_listen_req },
  1782. { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
  1783. { CAPI_RESET_B3_REQ, do_reset_b3_req },
  1784. { CAPI_RESET_B3_RESP, do_nothing },
  1785. /*
  1786. * ToDo: support overlap sending (requires ev-layer state
  1787. * machine extension to generate additional ATD commands)
  1788. */
  1789. { CAPI_INFO_REQ, do_unsupported },
  1790. { CAPI_INFO_RESP, do_nothing },
  1791. /*
  1792. * ToDo: what's the proper response for these?
  1793. */
  1794. { CAPI_MANUFACTURER_REQ, do_nothing },
  1795. { CAPI_MANUFACTURER_RESP, do_nothing },
  1796. };
  1797. /* look up handler */
  1798. static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
  1799. {
  1800. size_t i;
  1801. for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
  1802. if (capi_send_handler_table[i].cmd == cmd)
  1803. return capi_send_handler_table[i].handler;
  1804. return NULL;
  1805. }
  1806. /**
  1807. * gigaset_send_message() - accept a CAPI message from an application
  1808. * @ctr: controller descriptor structure.
  1809. * @skb: CAPI message.
  1810. *
  1811. * Return value: CAPI error code
  1812. * Note: capidrv (and probably others, too) only uses the return value to
  1813. * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
  1814. */
  1815. static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
  1816. {
  1817. struct gigaset_capi_ctr *iif
  1818. = container_of(ctr, struct gigaset_capi_ctr, ctr);
  1819. struct cardstate *cs = ctr->driverdata;
  1820. struct gigaset_capi_appl *ap;
  1821. capi_send_handler_t handler;
  1822. /* can only handle linear sk_buffs */
  1823. if (skb_linearize(skb) < 0) {
  1824. dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
  1825. return CAPI_MSGOSRESOURCEERR;
  1826. }
  1827. /* retrieve application data structure */
  1828. ap = get_appl(iif, CAPIMSG_APPID(skb->data));
  1829. if (!ap) {
  1830. dev_notice(cs->dev, "%s: application %u not registered\n",
  1831. __func__, CAPIMSG_APPID(skb->data));
  1832. return CAPI_ILLAPPNR;
  1833. }
  1834. /* look up command */
  1835. handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
  1836. if (!handler) {
  1837. /* unknown/unsupported message type */
  1838. if (printk_ratelimit())
  1839. dev_notice(cs->dev, "%s: unsupported message %u\n",
  1840. __func__, CAPIMSG_CMD(skb->data));
  1841. return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
  1842. }
  1843. /* serialize */
  1844. if (atomic_add_return(1, &iif->sendqlen) > 1) {
  1845. /* queue behind other messages */
  1846. skb_queue_tail(&iif->sendqueue, skb);
  1847. return CAPI_NOERROR;
  1848. }
  1849. /* process message */
  1850. handler(iif, ap, skb);
  1851. /* process other messages arrived in the meantime */
  1852. while (atomic_sub_return(1, &iif->sendqlen) > 0) {
  1853. skb = skb_dequeue(&iif->sendqueue);
  1854. if (!skb) {
  1855. /* should never happen */
  1856. dev_err(cs->dev, "%s: send queue empty\n", __func__);
  1857. continue;
  1858. }
  1859. ap = get_appl(iif, CAPIMSG_APPID(skb->data));
  1860. if (!ap) {
  1861. /* could that happen? */
  1862. dev_warn(cs->dev, "%s: application %u vanished\n",
  1863. __func__, CAPIMSG_APPID(skb->data));
  1864. continue;
  1865. }
  1866. handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
  1867. if (!handler) {
  1868. /* should never happen */
  1869. dev_err(cs->dev, "%s: handler %x vanished\n",
  1870. __func__, CAPIMSG_CMD(skb->data));
  1871. continue;
  1872. }
  1873. handler(iif, ap, skb);
  1874. }
  1875. return CAPI_NOERROR;
  1876. }
  1877. /**
  1878. * gigaset_procinfo() - build single line description for controller
  1879. * @ctr: controller descriptor structure.
  1880. *
  1881. * Return value: pointer to generated string (null terminated)
  1882. */
  1883. static char *gigaset_procinfo(struct capi_ctr *ctr)
  1884. {
  1885. return ctr->name; /* ToDo: more? */
  1886. }
  1887. static int gigaset_proc_show(struct seq_file *m, void *v)
  1888. {
  1889. struct capi_ctr *ctr = m->private;
  1890. struct cardstate *cs = ctr->driverdata;
  1891. char *s;
  1892. int i;
  1893. seq_printf(m, "%-16s %s\n", "name", ctr->name);
  1894. seq_printf(m, "%-16s %s %s\n", "dev",
  1895. dev_driver_string(cs->dev), dev_name(cs->dev));
  1896. seq_printf(m, "%-16s %d\n", "id", cs->myid);
  1897. if (cs->gotfwver)
  1898. seq_printf(m, "%-16s %d.%d.%d.%d\n", "firmware",
  1899. cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
  1900. seq_printf(m, "%-16s %d\n", "channels", cs->channels);
  1901. seq_printf(m, "%-16s %s\n", "onechannel", cs->onechannel ? "yes" : "no");
  1902. switch (cs->mode) {
  1903. case M_UNKNOWN:
  1904. s = "unknown";
  1905. break;
  1906. case M_CONFIG:
  1907. s = "config";
  1908. break;
  1909. case M_UNIMODEM:
  1910. s = "Unimodem";
  1911. break;
  1912. case M_CID:
  1913. s = "CID";
  1914. break;
  1915. default:
  1916. s = "??";
  1917. }
  1918. seq_printf(m, "%-16s %s\n", "mode", s);
  1919. switch (cs->mstate) {
  1920. case MS_UNINITIALIZED:
  1921. s = "uninitialized";
  1922. break;
  1923. case MS_INIT:
  1924. s = "init";
  1925. break;
  1926. case MS_LOCKED:
  1927. s = "locked";
  1928. break;
  1929. case MS_SHUTDOWN:
  1930. s = "shutdown";
  1931. break;
  1932. case MS_RECOVER:
  1933. s = "recover";
  1934. break;
  1935. case MS_READY:
  1936. s = "ready";
  1937. break;
  1938. default:
  1939. s = "??";
  1940. }
  1941. seq_printf(m, "%-16s %s\n", "mstate", s);
  1942. seq_printf(m, "%-16s %s\n", "running", cs->running ? "yes" : "no");
  1943. seq_printf(m, "%-16s %s\n", "connected", cs->connected ? "yes" : "no");
  1944. seq_printf(m, "%-16s %s\n", "isdn_up", cs->isdn_up ? "yes" : "no");
  1945. seq_printf(m, "%-16s %s\n", "cidmode", cs->cidmode ? "yes" : "no");
  1946. for (i = 0; i < cs->channels; i++) {
  1947. seq_printf(m, "[%d]%-13s %d\n", i, "corrupted",
  1948. cs->bcs[i].corrupted);
  1949. seq_printf(m, "[%d]%-13s %d\n", i, "trans_down",
  1950. cs->bcs[i].trans_down);
  1951. seq_printf(m, "[%d]%-13s %d\n", i, "trans_up",
  1952. cs->bcs[i].trans_up);
  1953. seq_printf(m, "[%d]%-13s %d\n", i, "chstate",
  1954. cs->bcs[i].chstate);
  1955. switch (cs->bcs[i].proto2) {
  1956. case L2_BITSYNC:
  1957. s = "bitsync";
  1958. break;
  1959. case L2_HDLC:
  1960. s = "HDLC";
  1961. break;
  1962. case L2_VOICE:
  1963. s = "voice";
  1964. break;
  1965. default:
  1966. s = "??";
  1967. }
  1968. seq_printf(m, "[%d]%-13s %s\n", i, "proto2", s);
  1969. }
  1970. return 0;
  1971. }
  1972. static int gigaset_proc_open(struct inode *inode, struct file *file)
  1973. {
  1974. return single_open(file, gigaset_proc_show, PDE(inode)->data);
  1975. }
  1976. static const struct file_operations gigaset_proc_fops = {
  1977. .owner = THIS_MODULE,
  1978. .open = gigaset_proc_open,
  1979. .read = seq_read,
  1980. .llseek = seq_lseek,
  1981. .release = single_release,
  1982. };
  1983. /**
  1984. * gigaset_isdn_regdev() - register device to LL
  1985. * @cs: device descriptor structure.
  1986. * @isdnid: device name.
  1987. *
  1988. * Return value: 1 for success, 0 for failure
  1989. */
  1990. int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
  1991. {
  1992. struct gigaset_capi_ctr *iif;
  1993. int rc;
  1994. iif = kmalloc(sizeof(*iif), GFP_KERNEL);
  1995. if (!iif) {
  1996. pr_err("%s: out of memory\n", __func__);
  1997. return 0;
  1998. }
  1999. /* prepare controller structure */
  2000. iif->ctr.owner = THIS_MODULE;
  2001. iif->ctr.driverdata = cs;
  2002. strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
  2003. iif->ctr.driver_name = "gigaset";
  2004. iif->ctr.load_firmware = gigaset_load_firmware;
  2005. iif->ctr.reset_ctr = gigaset_reset_ctr;
  2006. iif->ctr.register_appl = gigaset_register_appl;
  2007. iif->ctr.release_appl = gigaset_release_appl;
  2008. iif->ctr.send_message = gigaset_send_message;
  2009. iif->ctr.procinfo = gigaset_procinfo;
  2010. iif->ctr.proc_fops = &gigaset_proc_fops;
  2011. INIT_LIST_HEAD(&iif->appls);
  2012. skb_queue_head_init(&iif->sendqueue);
  2013. atomic_set(&iif->sendqlen, 0);
  2014. /* register controller with CAPI */
  2015. rc = attach_capi_ctr(&iif->ctr);
  2016. if (rc) {
  2017. pr_err("attach_capi_ctr failed (%d)\n", rc);
  2018. kfree(iif);
  2019. return 0;
  2020. }
  2021. cs->iif = iif;
  2022. cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
  2023. return 1;
  2024. }
  2025. /**
  2026. * gigaset_isdn_unregdev() - unregister device from LL
  2027. * @cs: device descriptor structure.
  2028. */
  2029. void gigaset_isdn_unregdev(struct cardstate *cs)
  2030. {
  2031. struct gigaset_capi_ctr *iif = cs->iif;
  2032. detach_capi_ctr(&iif->ctr);
  2033. kfree(iif);
  2034. cs->iif = NULL;
  2035. }
  2036. static struct capi_driver capi_driver_gigaset = {
  2037. .name = "gigaset",
  2038. .revision = "1.0",
  2039. };
  2040. /**
  2041. * gigaset_isdn_regdrv() - register driver to LL
  2042. */
  2043. void gigaset_isdn_regdrv(void)
  2044. {
  2045. pr_info("Kernel CAPI interface\n");
  2046. register_capi_driver(&capi_driver_gigaset);
  2047. }
  2048. /**
  2049. * gigaset_isdn_unregdrv() - unregister driver from LL
  2050. */
  2051. void gigaset_isdn_unregdrv(void)
  2052. {
  2053. unregister_capi_driver(&capi_driver_gigaset);
  2054. }