capi.c 63 KB

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