isdn_tty.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771
  1. /*
  2. * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
  3. *
  4. * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
  5. * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #undef ISDN_TTY_STAT_DEBUG
  12. #include <linux/isdn.h>
  13. #include <linux/serial.h> /* ASYNC_* flags */
  14. #include <linux/slab.h>
  15. #include <linux/delay.h>
  16. #include <linux/mutex.h>
  17. #include <linux/sched/signal.h>
  18. #include "isdn_common.h"
  19. #include "isdn_tty.h"
  20. #ifdef CONFIG_ISDN_AUDIO
  21. #include "isdn_audio.h"
  22. #define VBUF 0x3e0
  23. #define VBUFX (VBUF/16)
  24. #endif
  25. #define FIX_FILE_TRANSFER
  26. #define DUMMY_HAYES_AT
  27. /* Prototypes */
  28. static DEFINE_MUTEX(modem_info_mutex);
  29. static int isdn_tty_edit_at(const char *, int, modem_info *);
  30. static void isdn_tty_check_esc(const u_char *, u_char, int, int *, u_long *);
  31. static void isdn_tty_modem_reset_regs(modem_info *, int);
  32. static void isdn_tty_cmd_ATA(modem_info *);
  33. static void isdn_tty_flush_buffer(struct tty_struct *);
  34. static void isdn_tty_modem_result(int, modem_info *);
  35. #ifdef CONFIG_ISDN_AUDIO
  36. static int isdn_tty_countDLE(unsigned char *, int);
  37. #endif
  38. /* Leave this unchanged unless you know what you do! */
  39. #define MODEM_PARANOIA_CHECK
  40. #define MODEM_DO_RESTART
  41. static int bit2si[8] =
  42. {1, 5, 7, 7, 7, 7, 7, 7};
  43. static int si2bit[8] =
  44. {4, 1, 4, 4, 4, 4, 4, 4};
  45. /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
  46. * to stuff incoming data directly into a tty's flip-buffer. This
  47. * is done to speed up tty-receiving if the receive-queue is empty.
  48. * This routine MUST be called with interrupts off.
  49. * Return:
  50. * 1 = Success
  51. * 0 = Failure, data has to be buffered and later processed by
  52. * isdn_tty_readmodem().
  53. */
  54. static int
  55. isdn_tty_try_read(modem_info *info, struct sk_buff *skb)
  56. {
  57. struct tty_port *port = &info->port;
  58. int c;
  59. int len;
  60. char last;
  61. if (!info->online)
  62. return 0;
  63. if (!(info->mcr & UART_MCR_RTS))
  64. return 0;
  65. len = skb->len
  66. #ifdef CONFIG_ISDN_AUDIO
  67. + ISDN_AUDIO_SKB_DLECOUNT(skb)
  68. #endif
  69. ;
  70. c = tty_buffer_request_room(port, len);
  71. if (c < len)
  72. return 0;
  73. #ifdef CONFIG_ISDN_AUDIO
  74. if (ISDN_AUDIO_SKB_DLECOUNT(skb)) {
  75. int l = skb->len;
  76. unsigned char *dp = skb->data;
  77. while (--l) {
  78. if (*dp == DLE)
  79. tty_insert_flip_char(port, DLE, 0);
  80. tty_insert_flip_char(port, *dp++, 0);
  81. }
  82. if (*dp == DLE)
  83. tty_insert_flip_char(port, DLE, 0);
  84. last = *dp;
  85. } else {
  86. #endif
  87. if (len > 1)
  88. tty_insert_flip_string(port, skb->data, len - 1);
  89. last = skb->data[len - 1];
  90. #ifdef CONFIG_ISDN_AUDIO
  91. }
  92. #endif
  93. if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP)
  94. tty_insert_flip_char(port, last, 0xFF);
  95. else
  96. tty_insert_flip_char(port, last, TTY_NORMAL);
  97. tty_flip_buffer_push(port);
  98. kfree_skb(skb);
  99. return 1;
  100. }
  101. /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
  102. * It tries getting received data from the receive queue an stuff it into
  103. * the tty's flip-buffer.
  104. */
  105. void
  106. isdn_tty_readmodem(void)
  107. {
  108. int resched = 0;
  109. int midx;
  110. int i;
  111. int r;
  112. modem_info *info;
  113. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  114. midx = dev->m_idx[i];
  115. if (midx < 0)
  116. continue;
  117. info = &dev->mdm.info[midx];
  118. if (!info->online)
  119. continue;
  120. r = 0;
  121. #ifdef CONFIG_ISDN_AUDIO
  122. isdn_audio_eval_dtmf(info);
  123. if ((info->vonline & 1) && (info->emu.vpar[1]))
  124. isdn_audio_eval_silence(info);
  125. #endif
  126. if (info->mcr & UART_MCR_RTS) {
  127. /* CISCO AsyncPPP Hack */
  128. if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
  129. r = isdn_readbchan_tty(info->isdn_driver,
  130. info->isdn_channel,
  131. &info->port, 0);
  132. else
  133. r = isdn_readbchan_tty(info->isdn_driver,
  134. info->isdn_channel,
  135. &info->port, 1);
  136. if (r)
  137. tty_flip_buffer_push(&info->port);
  138. } else
  139. r = 1;
  140. if (r) {
  141. info->rcvsched = 0;
  142. resched = 1;
  143. } else
  144. info->rcvsched = 1;
  145. }
  146. if (!resched)
  147. isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0);
  148. }
  149. int
  150. isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb)
  151. {
  152. ulong flags;
  153. int midx;
  154. #ifdef CONFIG_ISDN_AUDIO
  155. int ifmt;
  156. #endif
  157. modem_info *info;
  158. if ((midx = dev->m_idx[i]) < 0) {
  159. /* if midx is invalid, packet is not for tty */
  160. return 0;
  161. }
  162. info = &dev->mdm.info[midx];
  163. #ifdef CONFIG_ISDN_AUDIO
  164. ifmt = 1;
  165. if ((info->vonline) && (!info->emu.vpar[4]))
  166. isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt);
  167. if ((info->vonline & 1) && (info->emu.vpar[1]))
  168. isdn_audio_calc_silence(info, skb->data, skb->len, ifmt);
  169. #endif
  170. if ((info->online < 2)
  171. #ifdef CONFIG_ISDN_AUDIO
  172. && (!(info->vonline & 1))
  173. #endif
  174. ) {
  175. /* If Modem not listening, drop data */
  176. kfree_skb(skb);
  177. return 1;
  178. }
  179. if (info->emu.mdmreg[REG_T70] & BIT_T70) {
  180. if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) {
  181. /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
  182. if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */
  183. skb_pull(skb, 4);
  184. else
  185. if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */
  186. skb_pull(skb, 2);
  187. } else
  188. /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
  189. if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1)))
  190. skb_pull(skb, 4);
  191. }
  192. #ifdef CONFIG_ISDN_AUDIO
  193. ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
  194. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  195. if (info->vonline & 1) {
  196. /* voice conversion/compression */
  197. switch (info->emu.vpar[3]) {
  198. case 2:
  199. case 3:
  200. case 4:
  201. /* adpcm
  202. * Since compressed data takes less
  203. * space, we can overwrite the buffer.
  204. */
  205. skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr,
  206. ifmt,
  207. skb->data,
  208. skb->data,
  209. skb->len));
  210. break;
  211. case 5:
  212. /* a-law */
  213. if (!ifmt)
  214. isdn_audio_ulaw2alaw(skb->data, skb->len);
  215. break;
  216. case 6:
  217. /* u-law */
  218. if (ifmt)
  219. isdn_audio_alaw2ulaw(skb->data, skb->len);
  220. break;
  221. }
  222. ISDN_AUDIO_SKB_DLECOUNT(skb) =
  223. isdn_tty_countDLE(skb->data, skb->len);
  224. }
  225. #ifdef CONFIG_ISDN_TTY_FAX
  226. else {
  227. if (info->faxonline & 2) {
  228. isdn_tty_fax_bitorder(info, skb);
  229. ISDN_AUDIO_SKB_DLECOUNT(skb) =
  230. isdn_tty_countDLE(skb->data, skb->len);
  231. }
  232. }
  233. #endif
  234. #endif
  235. /* Try to deliver directly via tty-buf if queue is empty */
  236. spin_lock_irqsave(&info->readlock, flags);
  237. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
  238. if (isdn_tty_try_read(info, skb)) {
  239. spin_unlock_irqrestore(&info->readlock, flags);
  240. return 1;
  241. }
  242. /* Direct deliver failed or queue wasn't empty.
  243. * Queue up for later dequeueing via timer-irq.
  244. */
  245. __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb);
  246. dev->drv[di]->rcvcount[channel] +=
  247. (skb->len
  248. #ifdef CONFIG_ISDN_AUDIO
  249. + ISDN_AUDIO_SKB_DLECOUNT(skb)
  250. #endif
  251. );
  252. spin_unlock_irqrestore(&info->readlock, flags);
  253. /* Schedule dequeuing */
  254. if ((dev->modempoll) && (info->rcvsched))
  255. isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
  256. return 1;
  257. }
  258. static void
  259. isdn_tty_cleanup_xmit(modem_info *info)
  260. {
  261. skb_queue_purge(&info->xmit_queue);
  262. #ifdef CONFIG_ISDN_AUDIO
  263. skb_queue_purge(&info->dtmf_queue);
  264. #endif
  265. }
  266. static void
  267. isdn_tty_tint(modem_info *info)
  268. {
  269. struct sk_buff *skb = skb_dequeue(&info->xmit_queue);
  270. int len, slen;
  271. if (!skb)
  272. return;
  273. len = skb->len;
  274. if ((slen = isdn_writebuf_skb_stub(info->isdn_driver,
  275. info->isdn_channel, 1, skb)) == len) {
  276. struct tty_struct *tty = info->port.tty;
  277. info->send_outstanding++;
  278. info->msr &= ~UART_MSR_CTS;
  279. info->lsr &= ~UART_LSR_TEMT;
  280. tty_wakeup(tty);
  281. return;
  282. }
  283. if (slen < 0) {
  284. /* Error: no channel, already shutdown, or wrong parameter */
  285. dev_kfree_skb(skb);
  286. return;
  287. }
  288. skb_queue_head(&info->xmit_queue, skb);
  289. }
  290. #ifdef CONFIG_ISDN_AUDIO
  291. static int
  292. isdn_tty_countDLE(unsigned char *buf, int len)
  293. {
  294. int count = 0;
  295. while (len--)
  296. if (*buf++ == DLE)
  297. count++;
  298. return count;
  299. }
  300. /* This routine is called from within isdn_tty_write() to perform
  301. * DLE-decoding when sending audio-data.
  302. */
  303. static int
  304. isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len)
  305. {
  306. unsigned char *p = &info->port.xmit_buf[info->xmit_count];
  307. int count = 0;
  308. while (len > 0) {
  309. if (m->lastDLE) {
  310. m->lastDLE = 0;
  311. switch (*p) {
  312. case DLE:
  313. /* Escape code */
  314. if (len > 1)
  315. memmove(p, p + 1, len - 1);
  316. p--;
  317. count++;
  318. break;
  319. case ETX:
  320. /* End of data */
  321. info->vonline |= 4;
  322. return count;
  323. case DC4:
  324. /* Abort RX */
  325. info->vonline &= ~1;
  326. #ifdef ISDN_DEBUG_MODEM_VOICE
  327. printk(KERN_DEBUG
  328. "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
  329. info->line);
  330. #endif
  331. isdn_tty_at_cout("\020\003", info);
  332. if (!info->vonline) {
  333. #ifdef ISDN_DEBUG_MODEM_VOICE
  334. printk(KERN_DEBUG
  335. "DLEdown: send VCON on ttyI%d\n",
  336. info->line);
  337. #endif
  338. isdn_tty_at_cout("\r\nVCON\r\n", info);
  339. }
  340. /* Fall through */
  341. case 'q':
  342. case 's':
  343. /* Silence */
  344. if (len > 1)
  345. memmove(p, p + 1, len - 1);
  346. p--;
  347. break;
  348. }
  349. } else {
  350. if (*p == DLE)
  351. m->lastDLE = 1;
  352. else
  353. count++;
  354. }
  355. p++;
  356. len--;
  357. }
  358. if (len < 0) {
  359. printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n");
  360. return 0;
  361. }
  362. return count;
  363. }
  364. /* This routine is called from within isdn_tty_write() when receiving
  365. * audio-data. It interrupts receiving, if an character other than
  366. * ^S or ^Q is sent.
  367. */
  368. static int
  369. isdn_tty_end_vrx(const char *buf, int c)
  370. {
  371. char ch;
  372. while (c--) {
  373. ch = *buf;
  374. if ((ch != 0x11) && (ch != 0x13))
  375. return 1;
  376. buf++;
  377. }
  378. return 0;
  379. }
  380. static int voice_cf[7] =
  381. {0, 0, 4, 3, 2, 0, 0};
  382. #endif /* CONFIG_ISDN_AUDIO */
  383. /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
  384. * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
  385. * outgoing data from the tty's xmit-buffer, handles voice-decompression or
  386. * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
  387. */
  388. static void
  389. isdn_tty_senddown(modem_info *info)
  390. {
  391. int buflen;
  392. int skb_res;
  393. #ifdef CONFIG_ISDN_AUDIO
  394. int audio_len;
  395. #endif
  396. struct sk_buff *skb;
  397. #ifdef CONFIG_ISDN_AUDIO
  398. if (info->vonline & 4) {
  399. info->vonline &= ~6;
  400. if (!info->vonline) {
  401. #ifdef ISDN_DEBUG_MODEM_VOICE
  402. printk(KERN_DEBUG
  403. "senddown: send VCON on ttyI%d\n",
  404. info->line);
  405. #endif
  406. isdn_tty_at_cout("\r\nVCON\r\n", info);
  407. }
  408. }
  409. #endif
  410. if (!(buflen = info->xmit_count))
  411. return;
  412. if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0)
  413. info->msr &= ~UART_MSR_CTS;
  414. info->lsr &= ~UART_LSR_TEMT;
  415. /* info->xmit_count is modified here and in isdn_tty_write().
  416. * So we return here if isdn_tty_write() is in the
  417. * critical section.
  418. */
  419. atomic_inc(&info->xmit_lock);
  420. if (!(atomic_dec_and_test(&info->xmit_lock)))
  421. return;
  422. if (info->isdn_driver < 0) {
  423. info->xmit_count = 0;
  424. return;
  425. }
  426. skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4;
  427. #ifdef CONFIG_ISDN_AUDIO
  428. if (info->vonline & 2)
  429. audio_len = buflen * voice_cf[info->emu.vpar[3]];
  430. else
  431. audio_len = 0;
  432. skb = dev_alloc_skb(skb_res + buflen + audio_len);
  433. #else
  434. skb = dev_alloc_skb(skb_res + buflen);
  435. #endif
  436. if (!skb) {
  437. printk(KERN_WARNING
  438. "isdn_tty: Out of memory in ttyI%d senddown\n",
  439. info->line);
  440. return;
  441. }
  442. skb_reserve(skb, skb_res);
  443. skb_put_data(skb, info->port.xmit_buf, buflen);
  444. info->xmit_count = 0;
  445. #ifdef CONFIG_ISDN_AUDIO
  446. if (info->vonline & 2) {
  447. /* For now, ifmt is fixed to 1 (alaw), since this
  448. * is used with ISDN everywhere in the world, except
  449. * US, Canada and Japan.
  450. * Later, when US-ISDN protocols are implemented,
  451. * this setting will depend on the D-channel protocol.
  452. */
  453. int ifmt = 1;
  454. /* voice conversion/decompression */
  455. switch (info->emu.vpar[3]) {
  456. case 2:
  457. case 3:
  458. case 4:
  459. /* adpcm, compatible to ZyXel 1496 modem
  460. * with ROM revision 6.01
  461. */
  462. audio_len = isdn_audio_adpcm2xlaw(info->adpcms,
  463. ifmt,
  464. skb->data,
  465. skb_put(skb, audio_len),
  466. buflen);
  467. skb_pull(skb, buflen);
  468. skb_trim(skb, audio_len);
  469. break;
  470. case 5:
  471. /* a-law */
  472. if (!ifmt)
  473. isdn_audio_alaw2ulaw(skb->data,
  474. buflen);
  475. break;
  476. case 6:
  477. /* u-law */
  478. if (ifmt)
  479. isdn_audio_ulaw2alaw(skb->data,
  480. buflen);
  481. break;
  482. }
  483. }
  484. #endif /* CONFIG_ISDN_AUDIO */
  485. if (info->emu.mdmreg[REG_T70] & BIT_T70) {
  486. /* Add T.70 simplified header */
  487. if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT)
  488. memcpy(skb_push(skb, 2), "\1\0", 2);
  489. else
  490. memcpy(skb_push(skb, 4), "\1\0\1\0", 4);
  491. }
  492. skb_queue_tail(&info->xmit_queue, skb);
  493. }
  494. /************************************************************
  495. *
  496. * Modem-functions
  497. *
  498. * mostly "stolen" from original Linux-serial.c and friends.
  499. *
  500. ************************************************************/
  501. /* The next routine is called once from within timer-interrupt
  502. * triggered within isdn_tty_modem_ncarrier(). It calls
  503. * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
  504. * into the tty's buffer.
  505. */
  506. static void
  507. isdn_tty_modem_do_ncarrier(struct timer_list *t)
  508. {
  509. modem_info *info = from_timer(info, t, nc_timer);
  510. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  511. }
  512. /* Next routine is called, whenever the DTR-signal is raised.
  513. * It checks the ncarrier-flag, and triggers the above routine
  514. * when necessary. The ncarrier-flag is set, whenever DTR goes
  515. * low.
  516. */
  517. static void
  518. isdn_tty_modem_ncarrier(modem_info *info)
  519. {
  520. if (info->ncarrier) {
  521. info->nc_timer.expires = jiffies + HZ;
  522. add_timer(&info->nc_timer);
  523. }
  524. }
  525. /*
  526. * return the usage calculated by si and layer 2 protocol
  527. */
  528. static int
  529. isdn_calc_usage(int si, int l2)
  530. {
  531. int usg = ISDN_USAGE_MODEM;
  532. #ifdef CONFIG_ISDN_AUDIO
  533. if (si == 1) {
  534. switch (l2) {
  535. case ISDN_PROTO_L2_MODEM:
  536. usg = ISDN_USAGE_MODEM;
  537. break;
  538. #ifdef CONFIG_ISDN_TTY_FAX
  539. case ISDN_PROTO_L2_FAX:
  540. usg = ISDN_USAGE_FAX;
  541. break;
  542. #endif
  543. case ISDN_PROTO_L2_TRANS:
  544. default:
  545. usg = ISDN_USAGE_VOICE;
  546. break;
  547. }
  548. }
  549. #endif
  550. return (usg);
  551. }
  552. /* isdn_tty_dial() performs dialing of a tty an the necessary
  553. * setup of the lower levels before that.
  554. */
  555. static void
  556. isdn_tty_dial(char *n, modem_info *info, atemu *m)
  557. {
  558. int usg = ISDN_USAGE_MODEM;
  559. int si = 7;
  560. int l2 = m->mdmreg[REG_L2PROT];
  561. u_long flags;
  562. isdn_ctrl cmd;
  563. int i;
  564. int j;
  565. for (j = 7; j >= 0; j--)
  566. if (m->mdmreg[REG_SI1] & (1 << j)) {
  567. si = bit2si[j];
  568. break;
  569. }
  570. usg = isdn_calc_usage(si, l2);
  571. #ifdef CONFIG_ISDN_AUDIO
  572. if ((si == 1) &&
  573. (l2 != ISDN_PROTO_L2_MODEM)
  574. #ifdef CONFIG_ISDN_TTY_FAX
  575. && (l2 != ISDN_PROTO_L2_FAX)
  576. #endif
  577. ) {
  578. l2 = ISDN_PROTO_L2_TRANS;
  579. usg = ISDN_USAGE_VOICE;
  580. }
  581. #endif
  582. m->mdmreg[REG_SI1I] = si2bit[si];
  583. spin_lock_irqsave(&dev->lock, flags);
  584. i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
  585. if (i < 0) {
  586. spin_unlock_irqrestore(&dev->lock, flags);
  587. isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
  588. } else {
  589. info->isdn_driver = dev->drvmap[i];
  590. info->isdn_channel = dev->chanmap[i];
  591. info->drv_index = i;
  592. dev->m_idx[i] = info->line;
  593. dev->usage[i] |= ISDN_USAGE_OUTGOING;
  594. info->last_dir = 1;
  595. strcpy(info->last_num, n);
  596. isdn_info_update();
  597. spin_unlock_irqrestore(&dev->lock, flags);
  598. cmd.driver = info->isdn_driver;
  599. cmd.arg = info->isdn_channel;
  600. cmd.command = ISDN_CMD_CLREAZ;
  601. isdn_command(&cmd);
  602. strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
  603. cmd.driver = info->isdn_driver;
  604. cmd.command = ISDN_CMD_SETEAZ;
  605. isdn_command(&cmd);
  606. cmd.driver = info->isdn_driver;
  607. cmd.command = ISDN_CMD_SETL2;
  608. info->last_l2 = l2;
  609. cmd.arg = info->isdn_channel + (l2 << 8);
  610. isdn_command(&cmd);
  611. cmd.driver = info->isdn_driver;
  612. cmd.command = ISDN_CMD_SETL3;
  613. cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
  614. #ifdef CONFIG_ISDN_TTY_FAX
  615. if (l2 == ISDN_PROTO_L2_FAX) {
  616. cmd.parm.fax = info->fax;
  617. info->fax->direction = ISDN_TTY_FAX_CONN_OUT;
  618. }
  619. #endif
  620. isdn_command(&cmd);
  621. cmd.driver = info->isdn_driver;
  622. cmd.arg = info->isdn_channel;
  623. sprintf(cmd.parm.setup.phone, "%s", n);
  624. sprintf(cmd.parm.setup.eazmsn, "%s",
  625. isdn_map_eaz2msn(m->msn, info->isdn_driver));
  626. cmd.parm.setup.si1 = si;
  627. cmd.parm.setup.si2 = m->mdmreg[REG_SI2];
  628. cmd.command = ISDN_CMD_DIAL;
  629. info->dialing = 1;
  630. info->emu.carrierwait = 0;
  631. strcpy(dev->num[i], n);
  632. isdn_info_update();
  633. isdn_command(&cmd);
  634. isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
  635. }
  636. }
  637. /* isdn_tty_hangup() disassociates a tty from the real
  638. * ISDN-line (hangup). The usage-status is cleared
  639. * and some cleanup is done also.
  640. */
  641. void
  642. isdn_tty_modem_hup(modem_info *info, int local)
  643. {
  644. isdn_ctrl cmd;
  645. int di, ch;
  646. if (!info)
  647. return;
  648. di = info->isdn_driver;
  649. ch = info->isdn_channel;
  650. if (di < 0 || ch < 0)
  651. return;
  652. info->isdn_driver = -1;
  653. info->isdn_channel = -1;
  654. #ifdef ISDN_DEBUG_MODEM_HUP
  655. printk(KERN_DEBUG "Mhup ttyI%d\n", info->line);
  656. #endif
  657. info->rcvsched = 0;
  658. isdn_tty_flush_buffer(info->port.tty);
  659. if (info->online) {
  660. info->last_lhup = local;
  661. info->online = 0;
  662. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  663. }
  664. #ifdef CONFIG_ISDN_AUDIO
  665. info->vonline = 0;
  666. #ifdef CONFIG_ISDN_TTY_FAX
  667. info->faxonline = 0;
  668. info->fax->phase = ISDN_FAX_PHASE_IDLE;
  669. #endif
  670. info->emu.vpar[4] = 0;
  671. info->emu.vpar[5] = 8;
  672. kfree(info->dtmf_state);
  673. info->dtmf_state = NULL;
  674. kfree(info->silence_state);
  675. info->silence_state = NULL;
  676. kfree(info->adpcms);
  677. info->adpcms = NULL;
  678. kfree(info->adpcmr);
  679. info->adpcmr = NULL;
  680. #endif
  681. if ((info->msr & UART_MSR_RI) &&
  682. (info->emu.mdmreg[REG_RUNG] & BIT_RUNG))
  683. isdn_tty_modem_result(RESULT_RUNG, info);
  684. info->msr &= ~(UART_MSR_DCD | UART_MSR_RI);
  685. info->lsr |= UART_LSR_TEMT;
  686. if (local) {
  687. cmd.driver = di;
  688. cmd.command = ISDN_CMD_HANGUP;
  689. cmd.arg = ch;
  690. isdn_command(&cmd);
  691. }
  692. isdn_all_eaz(di, ch);
  693. info->emu.mdmreg[REG_RINGCNT] = 0;
  694. isdn_free_channel(di, ch, 0);
  695. if (info->drv_index >= 0) {
  696. dev->m_idx[info->drv_index] = -1;
  697. info->drv_index = -1;
  698. }
  699. }
  700. /*
  701. * Begin of a CAPI like interface, currently used only for
  702. * supplementary service (CAPI 2.0 part III)
  703. */
  704. #include <linux/isdn/capicmd.h>
  705. #include <linux/module.h>
  706. int
  707. isdn_tty_capi_facility(capi_msg *cm) {
  708. return (-1); /* dummy */
  709. }
  710. /* isdn_tty_suspend() tries to suspend the current tty connection
  711. */
  712. static void
  713. isdn_tty_suspend(char *id, modem_info *info, atemu *m)
  714. {
  715. isdn_ctrl cmd;
  716. int l;
  717. if (!info)
  718. return;
  719. #ifdef ISDN_DEBUG_MODEM_SERVICES
  720. printk(KERN_DEBUG "Msusp ttyI%d\n", info->line);
  721. #endif
  722. l = strlen(id);
  723. if ((info->isdn_driver >= 0)) {
  724. cmd.parm.cmsg.Length = l + 18;
  725. cmd.parm.cmsg.Command = CAPI_FACILITY;
  726. cmd.parm.cmsg.Subcommand = CAPI_REQ;
  727. cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
  728. cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
  729. cmd.parm.cmsg.para[1] = 0;
  730. cmd.parm.cmsg.para[2] = l + 3;
  731. cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */
  732. cmd.parm.cmsg.para[4] = 0;
  733. cmd.parm.cmsg.para[5] = l;
  734. strncpy(&cmd.parm.cmsg.para[6], id, l);
  735. cmd.command = CAPI_PUT_MESSAGE;
  736. cmd.driver = info->isdn_driver;
  737. cmd.arg = info->isdn_channel;
  738. isdn_command(&cmd);
  739. }
  740. }
  741. /* isdn_tty_resume() tries to resume a suspended call
  742. * setup of the lower levels before that. unfortunately here is no
  743. * checking for compatibility of used protocols implemented by Q931
  744. * It does the same things like isdn_tty_dial, the last command
  745. * is different, may be we can merge it.
  746. */
  747. static void
  748. isdn_tty_resume(char *id, modem_info *info, atemu *m)
  749. {
  750. int usg = ISDN_USAGE_MODEM;
  751. int si = 7;
  752. int l2 = m->mdmreg[REG_L2PROT];
  753. isdn_ctrl cmd;
  754. ulong flags;
  755. int i;
  756. int j;
  757. int l;
  758. l = strlen(id);
  759. for (j = 7; j >= 0; j--)
  760. if (m->mdmreg[REG_SI1] & (1 << j)) {
  761. si = bit2si[j];
  762. break;
  763. }
  764. usg = isdn_calc_usage(si, l2);
  765. #ifdef CONFIG_ISDN_AUDIO
  766. if ((si == 1) &&
  767. (l2 != ISDN_PROTO_L2_MODEM)
  768. #ifdef CONFIG_ISDN_TTY_FAX
  769. && (l2 != ISDN_PROTO_L2_FAX)
  770. #endif
  771. ) {
  772. l2 = ISDN_PROTO_L2_TRANS;
  773. usg = ISDN_USAGE_VOICE;
  774. }
  775. #endif
  776. m->mdmreg[REG_SI1I] = si2bit[si];
  777. spin_lock_irqsave(&dev->lock, flags);
  778. i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
  779. if (i < 0) {
  780. spin_unlock_irqrestore(&dev->lock, flags);
  781. isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
  782. } else {
  783. info->isdn_driver = dev->drvmap[i];
  784. info->isdn_channel = dev->chanmap[i];
  785. info->drv_index = i;
  786. dev->m_idx[i] = info->line;
  787. dev->usage[i] |= ISDN_USAGE_OUTGOING;
  788. info->last_dir = 1;
  789. // strcpy(info->last_num, n);
  790. isdn_info_update();
  791. spin_unlock_irqrestore(&dev->lock, flags);
  792. cmd.driver = info->isdn_driver;
  793. cmd.arg = info->isdn_channel;
  794. cmd.command = ISDN_CMD_CLREAZ;
  795. isdn_command(&cmd);
  796. strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
  797. cmd.driver = info->isdn_driver;
  798. cmd.command = ISDN_CMD_SETEAZ;
  799. isdn_command(&cmd);
  800. cmd.driver = info->isdn_driver;
  801. cmd.command = ISDN_CMD_SETL2;
  802. info->last_l2 = l2;
  803. cmd.arg = info->isdn_channel + (l2 << 8);
  804. isdn_command(&cmd);
  805. cmd.driver = info->isdn_driver;
  806. cmd.command = ISDN_CMD_SETL3;
  807. cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
  808. isdn_command(&cmd);
  809. cmd.driver = info->isdn_driver;
  810. cmd.arg = info->isdn_channel;
  811. cmd.parm.cmsg.Length = l + 18;
  812. cmd.parm.cmsg.Command = CAPI_FACILITY;
  813. cmd.parm.cmsg.Subcommand = CAPI_REQ;
  814. cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
  815. cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
  816. cmd.parm.cmsg.para[1] = 0;
  817. cmd.parm.cmsg.para[2] = l + 3;
  818. cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */
  819. cmd.parm.cmsg.para[4] = 0;
  820. cmd.parm.cmsg.para[5] = l;
  821. strncpy(&cmd.parm.cmsg.para[6], id, l);
  822. cmd.command = CAPI_PUT_MESSAGE;
  823. info->dialing = 1;
  824. // strcpy(dev->num[i], n);
  825. isdn_info_update();
  826. isdn_command(&cmd);
  827. isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
  828. }
  829. }
  830. /* isdn_tty_send_msg() sends a message to a HL driver
  831. * This is used for hybrid modem cards to send AT commands to it
  832. */
  833. static void
  834. isdn_tty_send_msg(modem_info *info, atemu *m, char *msg)
  835. {
  836. int usg = ISDN_USAGE_MODEM;
  837. int si = 7;
  838. int l2 = m->mdmreg[REG_L2PROT];
  839. isdn_ctrl cmd;
  840. ulong flags;
  841. int i;
  842. int j;
  843. int l;
  844. l = min(strlen(msg), sizeof(cmd.parm) - sizeof(cmd.parm.cmsg)
  845. + sizeof(cmd.parm.cmsg.para) - 2);
  846. if (!l) {
  847. isdn_tty_modem_result(RESULT_ERROR, info);
  848. return;
  849. }
  850. for (j = 7; j >= 0; j--)
  851. if (m->mdmreg[REG_SI1] & (1 << j)) {
  852. si = bit2si[j];
  853. break;
  854. }
  855. usg = isdn_calc_usage(si, l2);
  856. #ifdef CONFIG_ISDN_AUDIO
  857. if ((si == 1) &&
  858. (l2 != ISDN_PROTO_L2_MODEM)
  859. #ifdef CONFIG_ISDN_TTY_FAX
  860. && (l2 != ISDN_PROTO_L2_FAX)
  861. #endif
  862. ) {
  863. l2 = ISDN_PROTO_L2_TRANS;
  864. usg = ISDN_USAGE_VOICE;
  865. }
  866. #endif
  867. m->mdmreg[REG_SI1I] = si2bit[si];
  868. spin_lock_irqsave(&dev->lock, flags);
  869. i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
  870. if (i < 0) {
  871. spin_unlock_irqrestore(&dev->lock, flags);
  872. isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
  873. } else {
  874. info->isdn_driver = dev->drvmap[i];
  875. info->isdn_channel = dev->chanmap[i];
  876. info->drv_index = i;
  877. dev->m_idx[i] = info->line;
  878. dev->usage[i] |= ISDN_USAGE_OUTGOING;
  879. info->last_dir = 1;
  880. isdn_info_update();
  881. spin_unlock_irqrestore(&dev->lock, flags);
  882. cmd.driver = info->isdn_driver;
  883. cmd.arg = info->isdn_channel;
  884. cmd.command = ISDN_CMD_CLREAZ;
  885. isdn_command(&cmd);
  886. strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
  887. cmd.driver = info->isdn_driver;
  888. cmd.command = ISDN_CMD_SETEAZ;
  889. isdn_command(&cmd);
  890. cmd.driver = info->isdn_driver;
  891. cmd.command = ISDN_CMD_SETL2;
  892. info->last_l2 = l2;
  893. cmd.arg = info->isdn_channel + (l2 << 8);
  894. isdn_command(&cmd);
  895. cmd.driver = info->isdn_driver;
  896. cmd.command = ISDN_CMD_SETL3;
  897. cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
  898. isdn_command(&cmd);
  899. cmd.driver = info->isdn_driver;
  900. cmd.arg = info->isdn_channel;
  901. cmd.parm.cmsg.Length = l + 14;
  902. cmd.parm.cmsg.Command = CAPI_MANUFACTURER;
  903. cmd.parm.cmsg.Subcommand = CAPI_REQ;
  904. cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
  905. cmd.parm.cmsg.para[0] = l + 1;
  906. strncpy(&cmd.parm.cmsg.para[1], msg, l);
  907. cmd.parm.cmsg.para[l + 1] = 0xd;
  908. cmd.command = CAPI_PUT_MESSAGE;
  909. /* info->dialing = 1;
  910. strcpy(dev->num[i], n);
  911. isdn_info_update();
  912. */
  913. isdn_command(&cmd);
  914. }
  915. }
  916. static inline int
  917. isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine)
  918. {
  919. #ifdef MODEM_PARANOIA_CHECK
  920. if (!info) {
  921. printk(KERN_WARNING "isdn_tty: null info_struct for %s in %s\n",
  922. name, routine);
  923. return 1;
  924. }
  925. if (info->magic != ISDN_ASYNC_MAGIC) {
  926. printk(KERN_WARNING "isdn_tty: bad magic for modem struct %s in %s\n",
  927. name, routine);
  928. return 1;
  929. }
  930. #endif
  931. return 0;
  932. }
  933. /*
  934. * This routine is called to set the UART divisor registers to match
  935. * the specified baud rate for a serial port.
  936. */
  937. static void
  938. isdn_tty_change_speed(modem_info *info)
  939. {
  940. struct tty_port *port = &info->port;
  941. uint cflag,
  942. cval,
  943. quot;
  944. int i;
  945. if (!port->tty)
  946. return;
  947. cflag = port->tty->termios.c_cflag;
  948. quot = i = cflag & CBAUD;
  949. if (i & CBAUDEX) {
  950. i &= ~CBAUDEX;
  951. if (i < 1 || i > 2)
  952. port->tty->termios.c_cflag &= ~CBAUDEX;
  953. else
  954. i += 15;
  955. }
  956. if (quot) {
  957. info->mcr |= UART_MCR_DTR;
  958. isdn_tty_modem_ncarrier(info);
  959. } else {
  960. info->mcr &= ~UART_MCR_DTR;
  961. if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
  962. #ifdef ISDN_DEBUG_MODEM_HUP
  963. printk(KERN_DEBUG "Mhup in changespeed\n");
  964. #endif
  965. if (info->online)
  966. info->ncarrier = 1;
  967. isdn_tty_modem_reset_regs(info, 0);
  968. isdn_tty_modem_hup(info, 1);
  969. }
  970. return;
  971. }
  972. /* byte size and parity */
  973. cval = cflag & (CSIZE | CSTOPB);
  974. cval >>= 4;
  975. if (cflag & PARENB)
  976. cval |= UART_LCR_PARITY;
  977. if (!(cflag & PARODD))
  978. cval |= UART_LCR_EPAR;
  979. tty_port_set_check_carrier(port, ~cflag & CLOCAL);
  980. }
  981. static int
  982. isdn_tty_startup(modem_info *info)
  983. {
  984. if (tty_port_initialized(&info->port))
  985. return 0;
  986. isdn_lock_drivers();
  987. #ifdef ISDN_DEBUG_MODEM_OPEN
  988. printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line);
  989. #endif
  990. /*
  991. * Now, initialize the UART
  992. */
  993. info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
  994. if (info->port.tty)
  995. clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
  996. /*
  997. * and set the speed of the serial port
  998. */
  999. isdn_tty_change_speed(info);
  1000. tty_port_set_initialized(&info->port, 1);
  1001. info->msr |= (UART_MSR_DSR | UART_MSR_CTS);
  1002. info->send_outstanding = 0;
  1003. return 0;
  1004. }
  1005. /*
  1006. * This routine will shutdown a serial port; interrupts are disabled, and
  1007. * DTR is dropped if the hangup on close termio flag is on.
  1008. */
  1009. static void
  1010. isdn_tty_shutdown(modem_info *info)
  1011. {
  1012. if (!tty_port_initialized(&info->port))
  1013. return;
  1014. #ifdef ISDN_DEBUG_MODEM_OPEN
  1015. printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line);
  1016. #endif
  1017. isdn_unlock_drivers();
  1018. info->msr &= ~UART_MSR_RI;
  1019. if (!info->port.tty || (info->port.tty->termios.c_cflag & HUPCL)) {
  1020. info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
  1021. if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
  1022. isdn_tty_modem_reset_regs(info, 0);
  1023. #ifdef ISDN_DEBUG_MODEM_HUP
  1024. printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n");
  1025. #endif
  1026. isdn_tty_modem_hup(info, 1);
  1027. }
  1028. }
  1029. if (info->port.tty)
  1030. set_bit(TTY_IO_ERROR, &info->port.tty->flags);
  1031. tty_port_set_initialized(&info->port, 0);
  1032. }
  1033. /* isdn_tty_write() is the main send-routine. It is called from the upper
  1034. * levels within the kernel to perform sending data. Depending on the
  1035. * online-flag it either directs output to the at-command-interpreter or
  1036. * to the lower level. Additional tasks done here:
  1037. * - If online, check for escape-sequence (+++)
  1038. * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
  1039. * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
  1040. * - If dialing, abort dial.
  1041. */
  1042. static int
  1043. isdn_tty_write(struct tty_struct *tty, const u_char *buf, int count)
  1044. {
  1045. int c;
  1046. int total = 0;
  1047. modem_info *info = (modem_info *) tty->driver_data;
  1048. atemu *m = &info->emu;
  1049. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write"))
  1050. return 0;
  1051. /* See isdn_tty_senddown() */
  1052. atomic_inc(&info->xmit_lock);
  1053. while (1) {
  1054. c = count;
  1055. if (c > info->xmit_size - info->xmit_count)
  1056. c = info->xmit_size - info->xmit_count;
  1057. if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize)
  1058. c = dev->drv[info->isdn_driver]->maxbufsize;
  1059. if (c <= 0)
  1060. break;
  1061. if ((info->online > 1)
  1062. #ifdef CONFIG_ISDN_AUDIO
  1063. || (info->vonline & 3)
  1064. #endif
  1065. ) {
  1066. #ifdef CONFIG_ISDN_AUDIO
  1067. if (!info->vonline)
  1068. #endif
  1069. isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c,
  1070. &(m->pluscount),
  1071. &(m->lastplus));
  1072. memcpy(&info->port.xmit_buf[info->xmit_count], buf, c);
  1073. #ifdef CONFIG_ISDN_AUDIO
  1074. if (info->vonline) {
  1075. int cc = isdn_tty_handleDLEdown(info, m, c);
  1076. if (info->vonline & 2) {
  1077. if (!cc) {
  1078. /* If DLE decoding results in zero-transmit, but
  1079. * c originally was non-zero, do a wakeup.
  1080. */
  1081. tty_wakeup(tty);
  1082. info->msr |= UART_MSR_CTS;
  1083. info->lsr |= UART_LSR_TEMT;
  1084. }
  1085. info->xmit_count += cc;
  1086. }
  1087. if ((info->vonline & 3) == 1) {
  1088. /* Do NOT handle Ctrl-Q or Ctrl-S
  1089. * when in full-duplex audio mode.
  1090. */
  1091. if (isdn_tty_end_vrx(buf, c)) {
  1092. info->vonline &= ~1;
  1093. #ifdef ISDN_DEBUG_MODEM_VOICE
  1094. printk(KERN_DEBUG
  1095. "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
  1096. info->line);
  1097. #endif
  1098. isdn_tty_at_cout("\020\003\r\nVCON\r\n", info);
  1099. }
  1100. }
  1101. } else
  1102. if (TTY_IS_FCLASS1(info)) {
  1103. int cc = isdn_tty_handleDLEdown(info, m, c);
  1104. if (info->vonline & 4) { /* ETX seen */
  1105. isdn_ctrl c;
  1106. c.command = ISDN_CMD_FAXCMD;
  1107. c.driver = info->isdn_driver;
  1108. c.arg = info->isdn_channel;
  1109. c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL;
  1110. c.parm.aux.subcmd = ETX;
  1111. isdn_command(&c);
  1112. }
  1113. info->vonline = 0;
  1114. #ifdef ISDN_DEBUG_MODEM_VOICE
  1115. printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c);
  1116. #endif
  1117. info->xmit_count += cc;
  1118. } else
  1119. #endif
  1120. info->xmit_count += c;
  1121. } else {
  1122. info->msr |= UART_MSR_CTS;
  1123. info->lsr |= UART_LSR_TEMT;
  1124. if (info->dialing) {
  1125. info->dialing = 0;
  1126. #ifdef ISDN_DEBUG_MODEM_HUP
  1127. printk(KERN_DEBUG "Mhup in isdn_tty_write\n");
  1128. #endif
  1129. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  1130. isdn_tty_modem_hup(info, 1);
  1131. } else
  1132. c = isdn_tty_edit_at(buf, c, info);
  1133. }
  1134. buf += c;
  1135. count -= c;
  1136. total += c;
  1137. }
  1138. atomic_dec(&info->xmit_lock);
  1139. if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) {
  1140. if (m->mdmreg[REG_DXMT] & BIT_DXMT) {
  1141. isdn_tty_senddown(info);
  1142. isdn_tty_tint(info);
  1143. }
  1144. isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
  1145. }
  1146. return total;
  1147. }
  1148. static int
  1149. isdn_tty_write_room(struct tty_struct *tty)
  1150. {
  1151. modem_info *info = (modem_info *) tty->driver_data;
  1152. int ret;
  1153. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write_room"))
  1154. return 0;
  1155. if (!info->online)
  1156. return info->xmit_size;
  1157. ret = info->xmit_size - info->xmit_count;
  1158. return (ret < 0) ? 0 : ret;
  1159. }
  1160. static int
  1161. isdn_tty_chars_in_buffer(struct tty_struct *tty)
  1162. {
  1163. modem_info *info = (modem_info *) tty->driver_data;
  1164. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_chars_in_buffer"))
  1165. return 0;
  1166. if (!info->online)
  1167. return 0;
  1168. return (info->xmit_count);
  1169. }
  1170. static void
  1171. isdn_tty_flush_buffer(struct tty_struct *tty)
  1172. {
  1173. modem_info *info;
  1174. if (!tty) {
  1175. return;
  1176. }
  1177. info = (modem_info *) tty->driver_data;
  1178. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_buffer")) {
  1179. return;
  1180. }
  1181. isdn_tty_cleanup_xmit(info);
  1182. info->xmit_count = 0;
  1183. tty_wakeup(tty);
  1184. }
  1185. static void
  1186. isdn_tty_flush_chars(struct tty_struct *tty)
  1187. {
  1188. modem_info *info = (modem_info *) tty->driver_data;
  1189. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars"))
  1190. return;
  1191. if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue))
  1192. isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
  1193. }
  1194. /*
  1195. * ------------------------------------------------------------
  1196. * isdn_tty_throttle()
  1197. *
  1198. * This routine is called by the upper-layer tty layer to signal that
  1199. * incoming characters should be throttled.
  1200. * ------------------------------------------------------------
  1201. */
  1202. static void
  1203. isdn_tty_throttle(struct tty_struct *tty)
  1204. {
  1205. modem_info *info = (modem_info *) tty->driver_data;
  1206. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_throttle"))
  1207. return;
  1208. if (I_IXOFF(tty))
  1209. info->x_char = STOP_CHAR(tty);
  1210. info->mcr &= ~UART_MCR_RTS;
  1211. }
  1212. static void
  1213. isdn_tty_unthrottle(struct tty_struct *tty)
  1214. {
  1215. modem_info *info = (modem_info *) tty->driver_data;
  1216. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_unthrottle"))
  1217. return;
  1218. if (I_IXOFF(tty)) {
  1219. if (info->x_char)
  1220. info->x_char = 0;
  1221. else
  1222. info->x_char = START_CHAR(tty);
  1223. }
  1224. info->mcr |= UART_MCR_RTS;
  1225. }
  1226. /*
  1227. * ------------------------------------------------------------
  1228. * isdn_tty_ioctl() and friends
  1229. * ------------------------------------------------------------
  1230. */
  1231. /*
  1232. * isdn_tty_get_lsr_info - get line status register info
  1233. *
  1234. * Purpose: Let user call ioctl() to get info when the UART physically
  1235. * is emptied. On bus types like RS485, the transmitter must
  1236. * release the bus after transmitting. This must be done when
  1237. * the transmit shift register is empty, not be done when the
  1238. * transmit holding register is empty. This functionality
  1239. * allows RS485 driver to be written in user space.
  1240. */
  1241. static int
  1242. isdn_tty_get_lsr_info(modem_info *info, uint __user *value)
  1243. {
  1244. u_char status;
  1245. uint result;
  1246. status = info->lsr;
  1247. result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
  1248. return put_user(result, value);
  1249. }
  1250. static int
  1251. isdn_tty_tiocmget(struct tty_struct *tty)
  1252. {
  1253. modem_info *info = (modem_info *) tty->driver_data;
  1254. u_char control, status;
  1255. if (isdn_tty_paranoia_check(info, tty->name, __func__))
  1256. return -ENODEV;
  1257. if (tty_io_error(tty))
  1258. return -EIO;
  1259. mutex_lock(&modem_info_mutex);
  1260. #ifdef ISDN_DEBUG_MODEM_IOCTL
  1261. printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line);
  1262. #endif
  1263. control = info->mcr;
  1264. status = info->msr;
  1265. mutex_unlock(&modem_info_mutex);
  1266. return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
  1267. | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
  1268. | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
  1269. | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
  1270. | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
  1271. | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
  1272. }
  1273. static int
  1274. isdn_tty_tiocmset(struct tty_struct *tty,
  1275. unsigned int set, unsigned int clear)
  1276. {
  1277. modem_info *info = (modem_info *) tty->driver_data;
  1278. if (isdn_tty_paranoia_check(info, tty->name, __func__))
  1279. return -ENODEV;
  1280. if (tty_io_error(tty))
  1281. return -EIO;
  1282. #ifdef ISDN_DEBUG_MODEM_IOCTL
  1283. printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear);
  1284. #endif
  1285. mutex_lock(&modem_info_mutex);
  1286. if (set & TIOCM_RTS)
  1287. info->mcr |= UART_MCR_RTS;
  1288. if (set & TIOCM_DTR) {
  1289. info->mcr |= UART_MCR_DTR;
  1290. isdn_tty_modem_ncarrier(info);
  1291. }
  1292. if (clear & TIOCM_RTS)
  1293. info->mcr &= ~UART_MCR_RTS;
  1294. if (clear & TIOCM_DTR) {
  1295. info->mcr &= ~UART_MCR_DTR;
  1296. if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
  1297. isdn_tty_modem_reset_regs(info, 0);
  1298. #ifdef ISDN_DEBUG_MODEM_HUP
  1299. printk(KERN_DEBUG "Mhup in TIOCMSET\n");
  1300. #endif
  1301. if (info->online)
  1302. info->ncarrier = 1;
  1303. isdn_tty_modem_hup(info, 1);
  1304. }
  1305. }
  1306. mutex_unlock(&modem_info_mutex);
  1307. return 0;
  1308. }
  1309. static int
  1310. isdn_tty_ioctl(struct tty_struct *tty, uint cmd, ulong arg)
  1311. {
  1312. modem_info *info = (modem_info *) tty->driver_data;
  1313. int retval;
  1314. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_ioctl"))
  1315. return -ENODEV;
  1316. if (tty_io_error(tty))
  1317. return -EIO;
  1318. switch (cmd) {
  1319. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1320. #ifdef ISDN_DEBUG_MODEM_IOCTL
  1321. printk(KERN_DEBUG "ttyI%d ioctl TCSBRK\n", info->line);
  1322. #endif
  1323. retval = tty_check_change(tty);
  1324. if (retval)
  1325. return retval;
  1326. tty_wait_until_sent(tty, 0);
  1327. return 0;
  1328. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1329. #ifdef ISDN_DEBUG_MODEM_IOCTL
  1330. printk(KERN_DEBUG "ttyI%d ioctl TCSBRKP\n", info->line);
  1331. #endif
  1332. retval = tty_check_change(tty);
  1333. if (retval)
  1334. return retval;
  1335. tty_wait_until_sent(tty, 0);
  1336. return 0;
  1337. case TIOCSERGETLSR: /* Get line status register */
  1338. #ifdef ISDN_DEBUG_MODEM_IOCTL
  1339. printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line);
  1340. #endif
  1341. return isdn_tty_get_lsr_info(info, (uint __user *) arg);
  1342. default:
  1343. #ifdef ISDN_DEBUG_MODEM_IOCTL
  1344. printk(KERN_DEBUG "UNKNOWN ioctl 0x%08x on ttyi%d\n", cmd, info->line);
  1345. #endif
  1346. return -ENOIOCTLCMD;
  1347. }
  1348. return 0;
  1349. }
  1350. static void
  1351. isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  1352. {
  1353. modem_info *info = (modem_info *) tty->driver_data;
  1354. if (!old_termios)
  1355. isdn_tty_change_speed(info);
  1356. else {
  1357. if (tty->termios.c_cflag == old_termios->c_cflag &&
  1358. tty->termios.c_ispeed == old_termios->c_ispeed &&
  1359. tty->termios.c_ospeed == old_termios->c_ospeed)
  1360. return;
  1361. isdn_tty_change_speed(info);
  1362. }
  1363. }
  1364. /*
  1365. * ------------------------------------------------------------
  1366. * isdn_tty_open() and friends
  1367. * ------------------------------------------------------------
  1368. */
  1369. static int isdn_tty_install(struct tty_driver *driver, struct tty_struct *tty)
  1370. {
  1371. modem_info *info = &dev->mdm.info[tty->index];
  1372. if (isdn_tty_paranoia_check(info, tty->name, __func__))
  1373. return -ENODEV;
  1374. tty->driver_data = info;
  1375. return tty_port_install(&info->port, driver, tty);
  1376. }
  1377. /*
  1378. * This routine is called whenever a serial port is opened. It
  1379. * enables interrupts for a serial port, linking in its async structure into
  1380. * the IRQ chain. It also performs the serial-specific
  1381. * initialization for the tty structure.
  1382. */
  1383. static int
  1384. isdn_tty_open(struct tty_struct *tty, struct file *filp)
  1385. {
  1386. modem_info *info = tty->driver_data;
  1387. struct tty_port *port = &info->port;
  1388. int retval;
  1389. #ifdef ISDN_DEBUG_MODEM_OPEN
  1390. printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
  1391. port->count);
  1392. #endif
  1393. port->count++;
  1394. port->tty = tty;
  1395. /*
  1396. * Start up serial port
  1397. */
  1398. retval = isdn_tty_startup(info);
  1399. if (retval) {
  1400. #ifdef ISDN_DEBUG_MODEM_OPEN
  1401. printk(KERN_DEBUG "isdn_tty_open return after startup\n");
  1402. #endif
  1403. return retval;
  1404. }
  1405. retval = tty_port_block_til_ready(port, tty, filp);
  1406. if (retval) {
  1407. #ifdef ISDN_DEBUG_MODEM_OPEN
  1408. printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n");
  1409. #endif
  1410. return retval;
  1411. }
  1412. #ifdef ISDN_DEBUG_MODEM_OPEN
  1413. printk(KERN_DEBUG "isdn_tty_open ttyi%d successful...\n", info->line);
  1414. #endif
  1415. dev->modempoll++;
  1416. #ifdef ISDN_DEBUG_MODEM_OPEN
  1417. printk(KERN_DEBUG "isdn_tty_open normal exit\n");
  1418. #endif
  1419. return 0;
  1420. }
  1421. static void
  1422. isdn_tty_close(struct tty_struct *tty, struct file *filp)
  1423. {
  1424. modem_info *info = (modem_info *) tty->driver_data;
  1425. struct tty_port *port = &info->port;
  1426. ulong timeout;
  1427. if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close"))
  1428. return;
  1429. if (tty_hung_up_p(filp)) {
  1430. #ifdef ISDN_DEBUG_MODEM_OPEN
  1431. printk(KERN_DEBUG "isdn_tty_close return after tty_hung_up_p\n");
  1432. #endif
  1433. return;
  1434. }
  1435. if ((tty->count == 1) && (port->count != 1)) {
  1436. /*
  1437. * Uh, oh. tty->count is 1, which means that the tty
  1438. * structure will be freed. Info->count should always
  1439. * be one in these conditions. If it's greater than
  1440. * one, we've got real problems, since it means the
  1441. * serial port won't be shutdown.
  1442. */
  1443. printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
  1444. "info->count is %d\n", port->count);
  1445. port->count = 1;
  1446. }
  1447. if (--port->count < 0) {
  1448. printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
  1449. info->line, port->count);
  1450. port->count = 0;
  1451. }
  1452. if (port->count) {
  1453. #ifdef ISDN_DEBUG_MODEM_OPEN
  1454. printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
  1455. #endif
  1456. return;
  1457. }
  1458. info->closing = 1;
  1459. tty->closing = 1;
  1460. /*
  1461. * At this point we stop accepting input. To do this, we
  1462. * disable the receive line status interrupts, and tell the
  1463. * interrupt driver to stop checking the data ready bit in the
  1464. * line status register.
  1465. */
  1466. if (tty_port_initialized(port)) {
  1467. tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
  1468. /*
  1469. * Before we drop DTR, make sure the UART transmitter
  1470. * has completely drained; this is especially
  1471. * important if there is a transmit FIFO!
  1472. */
  1473. timeout = jiffies + HZ;
  1474. while (!(info->lsr & UART_LSR_TEMT)) {
  1475. schedule_timeout_interruptible(20);
  1476. if (time_after(jiffies, timeout))
  1477. break;
  1478. }
  1479. }
  1480. dev->modempoll--;
  1481. isdn_tty_shutdown(info);
  1482. isdn_tty_flush_buffer(tty);
  1483. tty_ldisc_flush(tty);
  1484. port->tty = NULL;
  1485. info->ncarrier = 0;
  1486. tty_port_close_end(port, tty);
  1487. info->closing = 0;
  1488. #ifdef ISDN_DEBUG_MODEM_OPEN
  1489. printk(KERN_DEBUG "isdn_tty_close normal exit\n");
  1490. #endif
  1491. }
  1492. /*
  1493. * isdn_tty_hangup() --- called by tty_hangup() when a hangup is signaled.
  1494. */
  1495. static void
  1496. isdn_tty_hangup(struct tty_struct *tty)
  1497. {
  1498. modem_info *info = (modem_info *) tty->driver_data;
  1499. struct tty_port *port = &info->port;
  1500. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
  1501. return;
  1502. isdn_tty_shutdown(info);
  1503. port->count = 0;
  1504. tty_port_set_active(port, 0);
  1505. port->tty = NULL;
  1506. wake_up_interruptible(&port->open_wait);
  1507. }
  1508. /* This routine initializes all emulator-data.
  1509. */
  1510. static void
  1511. isdn_tty_reset_profile(atemu *m)
  1512. {
  1513. m->profile[0] = 0;
  1514. m->profile[1] = 0;
  1515. m->profile[2] = 43;
  1516. m->profile[3] = 13;
  1517. m->profile[4] = 10;
  1518. m->profile[5] = 8;
  1519. m->profile[6] = 3;
  1520. m->profile[7] = 60;
  1521. m->profile[8] = 2;
  1522. m->profile[9] = 6;
  1523. m->profile[10] = 7;
  1524. m->profile[11] = 70;
  1525. m->profile[12] = 0x45;
  1526. m->profile[13] = 4;
  1527. m->profile[14] = ISDN_PROTO_L2_X75I;
  1528. m->profile[15] = ISDN_PROTO_L3_TRANS;
  1529. m->profile[16] = ISDN_SERIAL_XMIT_SIZE / 16;
  1530. m->profile[17] = ISDN_MODEM_WINSIZE;
  1531. m->profile[18] = 4;
  1532. m->profile[19] = 0;
  1533. m->profile[20] = 0;
  1534. m->profile[23] = 0;
  1535. m->pmsn[0] = '\0';
  1536. m->plmsn[0] = '\0';
  1537. }
  1538. #ifdef CONFIG_ISDN_AUDIO
  1539. static void
  1540. isdn_tty_modem_reset_vpar(atemu *m)
  1541. {
  1542. m->vpar[0] = 2; /* Voice-device (2 = phone line) */
  1543. m->vpar[1] = 0; /* Silence detection level (0 = none ) */
  1544. m->vpar[2] = 70; /* Silence interval (7 sec. ) */
  1545. m->vpar[3] = 2; /* Compression type (1 = ADPCM-2 ) */
  1546. m->vpar[4] = 0; /* DTMF detection level (0 = softcode ) */
  1547. m->vpar[5] = 8; /* DTMF interval (8 * 5 ms. ) */
  1548. }
  1549. #endif
  1550. #ifdef CONFIG_ISDN_TTY_FAX
  1551. static void
  1552. isdn_tty_modem_reset_faxpar(modem_info *info)
  1553. {
  1554. T30_s *f = info->fax;
  1555. f->code = 0;
  1556. f->phase = ISDN_FAX_PHASE_IDLE;
  1557. f->direction = 0;
  1558. f->resolution = 1; /* fine */
  1559. f->rate = 5; /* 14400 bit/s */
  1560. f->width = 0;
  1561. f->length = 0;
  1562. f->compression = 0;
  1563. f->ecm = 0;
  1564. f->binary = 0;
  1565. f->scantime = 0;
  1566. memset(&f->id[0], 32, FAXIDLEN - 1);
  1567. f->id[FAXIDLEN - 1] = 0;
  1568. f->badlin = 0;
  1569. f->badmul = 0;
  1570. f->bor = 0;
  1571. f->nbc = 0;
  1572. f->cq = 0;
  1573. f->cr = 0;
  1574. f->ctcrty = 0;
  1575. f->minsp = 0;
  1576. f->phcto = 30;
  1577. f->rel = 0;
  1578. memset(&f->pollid[0], 32, FAXIDLEN - 1);
  1579. f->pollid[FAXIDLEN - 1] = 0;
  1580. }
  1581. #endif
  1582. static void
  1583. isdn_tty_modem_reset_regs(modem_info *info, int force)
  1584. {
  1585. atemu *m = &info->emu;
  1586. if ((m->mdmreg[REG_DTRR] & BIT_DTRR) || force) {
  1587. memcpy(m->mdmreg, m->profile, ISDN_MODEM_NUMREG);
  1588. memcpy(m->msn, m->pmsn, ISDN_MSNLEN);
  1589. memcpy(m->lmsn, m->plmsn, ISDN_LMSNLEN);
  1590. info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
  1591. }
  1592. #ifdef CONFIG_ISDN_AUDIO
  1593. isdn_tty_modem_reset_vpar(m);
  1594. #endif
  1595. #ifdef CONFIG_ISDN_TTY_FAX
  1596. isdn_tty_modem_reset_faxpar(info);
  1597. #endif
  1598. m->mdmcmdl = 0;
  1599. }
  1600. static void
  1601. modem_write_profile(atemu *m)
  1602. {
  1603. memcpy(m->profile, m->mdmreg, ISDN_MODEM_NUMREG);
  1604. memcpy(m->pmsn, m->msn, ISDN_MSNLEN);
  1605. memcpy(m->plmsn, m->lmsn, ISDN_LMSNLEN);
  1606. if (dev->profd)
  1607. send_sig(SIGIO, dev->profd, 1);
  1608. }
  1609. static const struct tty_operations modem_ops = {
  1610. .install = isdn_tty_install,
  1611. .open = isdn_tty_open,
  1612. .close = isdn_tty_close,
  1613. .write = isdn_tty_write,
  1614. .flush_chars = isdn_tty_flush_chars,
  1615. .write_room = isdn_tty_write_room,
  1616. .chars_in_buffer = isdn_tty_chars_in_buffer,
  1617. .flush_buffer = isdn_tty_flush_buffer,
  1618. .ioctl = isdn_tty_ioctl,
  1619. .throttle = isdn_tty_throttle,
  1620. .unthrottle = isdn_tty_unthrottle,
  1621. .set_termios = isdn_tty_set_termios,
  1622. .hangup = isdn_tty_hangup,
  1623. .tiocmget = isdn_tty_tiocmget,
  1624. .tiocmset = isdn_tty_tiocmset,
  1625. };
  1626. static int isdn_tty_carrier_raised(struct tty_port *port)
  1627. {
  1628. modem_info *info = container_of(port, modem_info, port);
  1629. return info->msr & UART_MSR_DCD;
  1630. }
  1631. static const struct tty_port_operations isdn_tty_port_ops = {
  1632. .carrier_raised = isdn_tty_carrier_raised,
  1633. };
  1634. int
  1635. isdn_tty_modem_init(void)
  1636. {
  1637. isdn_modem_t *m;
  1638. int i, retval;
  1639. modem_info *info;
  1640. m = &dev->mdm;
  1641. m->tty_modem = alloc_tty_driver(ISDN_MAX_CHANNELS);
  1642. if (!m->tty_modem)
  1643. return -ENOMEM;
  1644. m->tty_modem->name = "ttyI";
  1645. m->tty_modem->major = ISDN_TTY_MAJOR;
  1646. m->tty_modem->minor_start = 0;
  1647. m->tty_modem->type = TTY_DRIVER_TYPE_SERIAL;
  1648. m->tty_modem->subtype = SERIAL_TYPE_NORMAL;
  1649. m->tty_modem->init_termios = tty_std_termios;
  1650. m->tty_modem->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  1651. m->tty_modem->flags = TTY_DRIVER_REAL_RAW;
  1652. m->tty_modem->driver_name = "isdn_tty";
  1653. tty_set_operations(m->tty_modem, &modem_ops);
  1654. retval = tty_register_driver(m->tty_modem);
  1655. if (retval) {
  1656. printk(KERN_WARNING "isdn_tty: Couldn't register modem-device\n");
  1657. goto err;
  1658. }
  1659. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1660. info = &m->info[i];
  1661. #ifdef CONFIG_ISDN_TTY_FAX
  1662. if (!(info->fax = kmalloc(sizeof(T30_s), GFP_KERNEL))) {
  1663. printk(KERN_ERR "Could not allocate fax t30-buffer\n");
  1664. retval = -ENOMEM;
  1665. goto err_unregister;
  1666. }
  1667. #endif
  1668. tty_port_init(&info->port);
  1669. info->port.ops = &isdn_tty_port_ops;
  1670. spin_lock_init(&info->readlock);
  1671. sprintf(info->last_cause, "0000");
  1672. sprintf(info->last_num, "none");
  1673. info->last_dir = 0;
  1674. info->last_lhup = 1;
  1675. info->last_l2 = -1;
  1676. info->last_si = 0;
  1677. isdn_tty_reset_profile(&info->emu);
  1678. isdn_tty_modem_reset_regs(info, 1);
  1679. info->magic = ISDN_ASYNC_MAGIC;
  1680. info->line = i;
  1681. info->x_char = 0;
  1682. info->isdn_driver = -1;
  1683. info->isdn_channel = -1;
  1684. info->drv_index = -1;
  1685. info->xmit_size = ISDN_SERIAL_XMIT_SIZE;
  1686. timer_setup(&info->nc_timer, isdn_tty_modem_do_ncarrier, 0);
  1687. skb_queue_head_init(&info->xmit_queue);
  1688. #ifdef CONFIG_ISDN_AUDIO
  1689. skb_queue_head_init(&info->dtmf_queue);
  1690. #endif
  1691. info->port.xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5,
  1692. GFP_KERNEL);
  1693. if (!info->port.xmit_buf) {
  1694. printk(KERN_ERR "Could not allocate modem xmit-buffer\n");
  1695. retval = -ENOMEM;
  1696. goto err_unregister;
  1697. }
  1698. /* Make room for T.70 header */
  1699. info->port.xmit_buf += 4;
  1700. }
  1701. return 0;
  1702. err_unregister:
  1703. for (i--; i >= 0; i--) {
  1704. info = &m->info[i];
  1705. #ifdef CONFIG_ISDN_TTY_FAX
  1706. kfree(info->fax);
  1707. #endif
  1708. kfree(info->port.xmit_buf - 4);
  1709. info->port.xmit_buf = NULL;
  1710. tty_port_destroy(&info->port);
  1711. }
  1712. tty_unregister_driver(m->tty_modem);
  1713. err:
  1714. put_tty_driver(m->tty_modem);
  1715. m->tty_modem = NULL;
  1716. return retval;
  1717. }
  1718. void
  1719. isdn_tty_exit(void)
  1720. {
  1721. modem_info *info;
  1722. int i;
  1723. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1724. info = &dev->mdm.info[i];
  1725. isdn_tty_cleanup_xmit(info);
  1726. #ifdef CONFIG_ISDN_TTY_FAX
  1727. kfree(info->fax);
  1728. #endif
  1729. kfree(info->port.xmit_buf - 4);
  1730. info->port.xmit_buf = NULL;
  1731. tty_port_destroy(&info->port);
  1732. }
  1733. tty_unregister_driver(dev->mdm.tty_modem);
  1734. put_tty_driver(dev->mdm.tty_modem);
  1735. dev->mdm.tty_modem = NULL;
  1736. }
  1737. /*
  1738. * isdn_tty_match_icall(char *MSN, atemu *tty_emulator, int dev_idx)
  1739. * match the MSN against the MSNs (glob patterns) defined for tty_emulator,
  1740. * and return 0 for match, 1 for no match, 2 if MSN could match if longer.
  1741. */
  1742. static int
  1743. isdn_tty_match_icall(char *cid, atemu *emu, int di)
  1744. {
  1745. #ifdef ISDN_DEBUG_MODEM_ICALL
  1746. printk(KERN_DEBUG "m_fi: msn=%s lmsn=%s mmsn=%s mreg[SI1]=%d mreg[SI2]=%d\n",
  1747. emu->msn, emu->lmsn, isdn_map_eaz2msn(emu->msn, di),
  1748. emu->mdmreg[REG_SI1], emu->mdmreg[REG_SI2]);
  1749. #endif
  1750. if (strlen(emu->lmsn)) {
  1751. char *p = emu->lmsn;
  1752. char *q;
  1753. int tmp;
  1754. int ret = 0;
  1755. while (1) {
  1756. if ((q = strchr(p, ';')))
  1757. *q = '\0';
  1758. if ((tmp = isdn_msncmp(cid, isdn_map_eaz2msn(p, di))) > ret)
  1759. ret = tmp;
  1760. #ifdef ISDN_DEBUG_MODEM_ICALL
  1761. printk(KERN_DEBUG "m_fi: lmsnX=%s mmsn=%s -> tmp=%d\n",
  1762. p, isdn_map_eaz2msn(emu->msn, di), tmp);
  1763. #endif
  1764. if (q) {
  1765. *q = ';';
  1766. p = q;
  1767. p++;
  1768. }
  1769. if (!tmp)
  1770. return 0;
  1771. if (!q)
  1772. break;
  1773. }
  1774. return ret;
  1775. } else {
  1776. int tmp;
  1777. tmp = isdn_msncmp(cid, isdn_map_eaz2msn(emu->msn, di));
  1778. #ifdef ISDN_DEBUG_MODEM_ICALL
  1779. printk(KERN_DEBUG "m_fi: mmsn=%s -> tmp=%d\n",
  1780. isdn_map_eaz2msn(emu->msn, di), tmp);
  1781. #endif
  1782. return tmp;
  1783. }
  1784. }
  1785. /*
  1786. * An incoming call-request has arrived.
  1787. * Search the tty-devices for an appropriate device and bind
  1788. * it to the ISDN-Channel.
  1789. * Return:
  1790. *
  1791. * 0 = No matching device found.
  1792. * 1 = A matching device found.
  1793. * 3 = No match found, but eventually would match, if
  1794. * CID is longer.
  1795. */
  1796. int
  1797. isdn_tty_find_icall(int di, int ch, setup_parm *setup)
  1798. {
  1799. char *eaz;
  1800. int i;
  1801. int wret;
  1802. int idx;
  1803. int si1;
  1804. int si2;
  1805. char *nr;
  1806. ulong flags;
  1807. if (!setup->phone[0]) {
  1808. nr = "0";
  1809. printk(KERN_INFO "isdn_tty: Incoming call without OAD, assuming '0'\n");
  1810. } else
  1811. nr = setup->phone;
  1812. si1 = (int) setup->si1;
  1813. si2 = (int) setup->si2;
  1814. if (!setup->eazmsn[0]) {
  1815. printk(KERN_WARNING "isdn_tty: Incoming call without CPN, assuming '0'\n");
  1816. eaz = "0";
  1817. } else
  1818. eaz = setup->eazmsn;
  1819. #ifdef ISDN_DEBUG_MODEM_ICALL
  1820. printk(KERN_DEBUG "m_fi: eaz=%s si1=%d si2=%d\n", eaz, si1, si2);
  1821. #endif
  1822. wret = 0;
  1823. spin_lock_irqsave(&dev->lock, flags);
  1824. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  1825. modem_info *info = &dev->mdm.info[i];
  1826. if (info->port.count == 0)
  1827. continue;
  1828. if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
  1829. (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
  1830. idx = isdn_dc2minor(di, ch);
  1831. #ifdef ISDN_DEBUG_MODEM_ICALL
  1832. printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret);
  1833. printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx,
  1834. info->port.flags, info->isdn_driver,
  1835. info->isdn_channel, dev->usage[idx]);
  1836. #endif
  1837. if (
  1838. #ifndef FIX_FILE_TRANSFER
  1839. tty_port_active(&info->port) &&
  1840. #endif
  1841. (info->isdn_driver == -1) &&
  1842. (info->isdn_channel == -1) &&
  1843. (USG_NONE(dev->usage[idx]))) {
  1844. int matchret;
  1845. if ((matchret = isdn_tty_match_icall(eaz, &info->emu, di)) > wret)
  1846. wret = matchret;
  1847. if (!matchret) { /* EAZ is matching */
  1848. info->isdn_driver = di;
  1849. info->isdn_channel = ch;
  1850. info->drv_index = idx;
  1851. dev->m_idx[idx] = info->line;
  1852. dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
  1853. dev->usage[idx] |= isdn_calc_usage(si1, info->emu.mdmreg[REG_L2PROT]);
  1854. strcpy(dev->num[idx], nr);
  1855. strcpy(info->emu.cpn, eaz);
  1856. info->emu.mdmreg[REG_SI1I] = si2bit[si1];
  1857. info->emu.mdmreg[REG_PLAN] = setup->plan;
  1858. info->emu.mdmreg[REG_SCREEN] = setup->screen;
  1859. isdn_info_update();
  1860. spin_unlock_irqrestore(&dev->lock, flags);
  1861. printk(KERN_INFO "isdn_tty: call from %s, -> RING on ttyI%d\n", nr,
  1862. info->line);
  1863. info->msr |= UART_MSR_RI;
  1864. isdn_tty_modem_result(RESULT_RING, info);
  1865. isdn_timer_ctrl(ISDN_TIMER_MODEMRING, 1);
  1866. return 1;
  1867. }
  1868. }
  1869. }
  1870. }
  1871. spin_unlock_irqrestore(&dev->lock, flags);
  1872. printk(KERN_INFO "isdn_tty: call from %s -> %s %s\n", nr, eaz,
  1873. ((dev->drv[di]->flags & DRV_FLAG_REJBUS) && (wret != 2)) ? "rejected" : "ignored");
  1874. return (wret == 2) ? 3 : 0;
  1875. }
  1876. int
  1877. isdn_tty_stat_callback(int i, isdn_ctrl *c)
  1878. {
  1879. int mi;
  1880. modem_info *info;
  1881. char *e;
  1882. if (i < 0)
  1883. return 0;
  1884. if ((mi = dev->m_idx[i]) >= 0) {
  1885. info = &dev->mdm.info[mi];
  1886. switch (c->command) {
  1887. case ISDN_STAT_CINF:
  1888. printk(KERN_DEBUG "CHARGEINFO on ttyI%d: %ld %s\n", info->line, c->arg, c->parm.num);
  1889. info->emu.charge = (unsigned) simple_strtoul(c->parm.num, &e, 10);
  1890. if (e == (char *)c->parm.num)
  1891. info->emu.charge = 0;
  1892. break;
  1893. case ISDN_STAT_BSENT:
  1894. #ifdef ISDN_TTY_STAT_DEBUG
  1895. printk(KERN_DEBUG "tty_STAT_BSENT ttyI%d\n", info->line);
  1896. #endif
  1897. if ((info->isdn_driver == c->driver) &&
  1898. (info->isdn_channel == c->arg)) {
  1899. info->msr |= UART_MSR_CTS;
  1900. if (info->send_outstanding)
  1901. if (!(--info->send_outstanding))
  1902. info->lsr |= UART_LSR_TEMT;
  1903. isdn_tty_tint(info);
  1904. return 1;
  1905. }
  1906. break;
  1907. case ISDN_STAT_CAUSE:
  1908. #ifdef ISDN_TTY_STAT_DEBUG
  1909. printk(KERN_DEBUG "tty_STAT_CAUSE ttyI%d\n", info->line);
  1910. #endif
  1911. /* Signal cause to tty-device */
  1912. strncpy(info->last_cause, c->parm.num, 5);
  1913. return 1;
  1914. case ISDN_STAT_DISPLAY:
  1915. #ifdef ISDN_TTY_STAT_DEBUG
  1916. printk(KERN_DEBUG "tty_STAT_DISPLAY ttyI%d\n", info->line);
  1917. #endif
  1918. /* Signal display to tty-device */
  1919. if ((info->emu.mdmreg[REG_DISPLAY] & BIT_DISPLAY) &&
  1920. !(info->emu.mdmreg[REG_RESPNUM] & BIT_RESPNUM)) {
  1921. isdn_tty_at_cout("\r\n", info);
  1922. isdn_tty_at_cout("DISPLAY: ", info);
  1923. isdn_tty_at_cout(c->parm.display, info);
  1924. isdn_tty_at_cout("\r\n", info);
  1925. }
  1926. return 1;
  1927. case ISDN_STAT_DCONN:
  1928. #ifdef ISDN_TTY_STAT_DEBUG
  1929. printk(KERN_DEBUG "tty_STAT_DCONN ttyI%d\n", info->line);
  1930. #endif
  1931. if (tty_port_active(&info->port)) {
  1932. if (info->dialing == 1) {
  1933. info->dialing = 2;
  1934. return 1;
  1935. }
  1936. }
  1937. break;
  1938. case ISDN_STAT_DHUP:
  1939. #ifdef ISDN_TTY_STAT_DEBUG
  1940. printk(KERN_DEBUG "tty_STAT_DHUP ttyI%d\n", info->line);
  1941. #endif
  1942. if (tty_port_active(&info->port)) {
  1943. if (info->dialing == 1)
  1944. isdn_tty_modem_result(RESULT_BUSY, info);
  1945. if (info->dialing > 1)
  1946. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  1947. info->dialing = 0;
  1948. #ifdef ISDN_DEBUG_MODEM_HUP
  1949. printk(KERN_DEBUG "Mhup in ISDN_STAT_DHUP\n");
  1950. #endif
  1951. isdn_tty_modem_hup(info, 0);
  1952. return 1;
  1953. }
  1954. break;
  1955. case ISDN_STAT_BCONN:
  1956. #ifdef ISDN_TTY_STAT_DEBUG
  1957. printk(KERN_DEBUG "tty_STAT_BCONN ttyI%d\n", info->line);
  1958. #endif
  1959. /* Wake up any processes waiting
  1960. * for incoming call of this device when
  1961. * DCD follow the state of incoming carrier
  1962. */
  1963. if (info->port.blocked_open &&
  1964. (info->emu.mdmreg[REG_DCD] & BIT_DCD)) {
  1965. wake_up_interruptible(&info->port.open_wait);
  1966. }
  1967. /* Schedule CONNECT-Message to any tty
  1968. * waiting for it and
  1969. * set DCD-bit of its modem-status.
  1970. */
  1971. if (tty_port_active(&info->port) ||
  1972. (info->port.blocked_open &&
  1973. (info->emu.mdmreg[REG_DCD] & BIT_DCD))) {
  1974. info->msr |= UART_MSR_DCD;
  1975. info->emu.charge = 0;
  1976. if (info->dialing & 0xf)
  1977. info->last_dir = 1;
  1978. else
  1979. info->last_dir = 0;
  1980. info->dialing = 0;
  1981. info->rcvsched = 1;
  1982. if (USG_MODEM(dev->usage[i])) {
  1983. if (info->emu.mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) {
  1984. strcpy(info->emu.connmsg, c->parm.num);
  1985. isdn_tty_modem_result(RESULT_CONNECT, info);
  1986. } else
  1987. isdn_tty_modem_result(RESULT_CONNECT64000, info);
  1988. }
  1989. if (USG_VOICE(dev->usage[i]))
  1990. isdn_tty_modem_result(RESULT_VCON, info);
  1991. return 1;
  1992. }
  1993. break;
  1994. case ISDN_STAT_BHUP:
  1995. #ifdef ISDN_TTY_STAT_DEBUG
  1996. printk(KERN_DEBUG "tty_STAT_BHUP ttyI%d\n", info->line);
  1997. #endif
  1998. if (tty_port_active(&info->port)) {
  1999. #ifdef ISDN_DEBUG_MODEM_HUP
  2000. printk(KERN_DEBUG "Mhup in ISDN_STAT_BHUP\n");
  2001. #endif
  2002. isdn_tty_modem_hup(info, 0);
  2003. return 1;
  2004. }
  2005. break;
  2006. case ISDN_STAT_NODCH:
  2007. #ifdef ISDN_TTY_STAT_DEBUG
  2008. printk(KERN_DEBUG "tty_STAT_NODCH ttyI%d\n", info->line);
  2009. #endif
  2010. if (tty_port_active(&info->port)) {
  2011. if (info->dialing) {
  2012. info->dialing = 0;
  2013. info->last_l2 = -1;
  2014. info->last_si = 0;
  2015. sprintf(info->last_cause, "0000");
  2016. isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
  2017. }
  2018. isdn_tty_modem_hup(info, 0);
  2019. return 1;
  2020. }
  2021. break;
  2022. case ISDN_STAT_UNLOAD:
  2023. #ifdef ISDN_TTY_STAT_DEBUG
  2024. printk(KERN_DEBUG "tty_STAT_UNLOAD ttyI%d\n", info->line);
  2025. #endif
  2026. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  2027. info = &dev->mdm.info[i];
  2028. if (info->isdn_driver == c->driver) {
  2029. if (info->online)
  2030. isdn_tty_modem_hup(info, 1);
  2031. }
  2032. }
  2033. return 1;
  2034. #ifdef CONFIG_ISDN_TTY_FAX
  2035. case ISDN_STAT_FAXIND:
  2036. if (tty_port_active(&info->port)) {
  2037. isdn_tty_fax_command(info, c);
  2038. }
  2039. break;
  2040. #endif
  2041. #ifdef CONFIG_ISDN_AUDIO
  2042. case ISDN_STAT_AUDIO:
  2043. if (tty_port_active(&info->port)) {
  2044. switch (c->parm.num[0]) {
  2045. case ISDN_AUDIO_DTMF:
  2046. if (info->vonline) {
  2047. isdn_audio_put_dle_code(info,
  2048. c->parm.num[1]);
  2049. }
  2050. break;
  2051. }
  2052. }
  2053. break;
  2054. #endif
  2055. }
  2056. }
  2057. return 0;
  2058. }
  2059. /*********************************************************************
  2060. Modem-Emulator-Routines
  2061. *********************************************************************/
  2062. #define cmdchar(c) ((c >= ' ') && (c <= 0x7f))
  2063. /*
  2064. * Put a message from the AT-emulator into receive-buffer of tty,
  2065. * convert CR, LF, and BS to values in modem-registers 3, 4 and 5.
  2066. */
  2067. void
  2068. isdn_tty_at_cout(char *msg, modem_info *info)
  2069. {
  2070. struct tty_port *port = &info->port;
  2071. atemu *m = &info->emu;
  2072. char *p;
  2073. char c;
  2074. u_long flags;
  2075. struct sk_buff *skb = NULL;
  2076. char *sp = NULL;
  2077. int l;
  2078. if (!msg) {
  2079. printk(KERN_WARNING "isdn_tty: Null-Message in isdn_tty_at_cout\n");
  2080. return;
  2081. }
  2082. l = strlen(msg);
  2083. spin_lock_irqsave(&info->readlock, flags);
  2084. if (info->closing) {
  2085. spin_unlock_irqrestore(&info->readlock, flags);
  2086. return;
  2087. }
  2088. /* use queue instead of direct, if online and */
  2089. /* data is in queue or buffer is full */
  2090. if (info->online && ((tty_buffer_request_room(port, l) < l) ||
  2091. !skb_queue_empty(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel]))) {
  2092. skb = alloc_skb(l, GFP_ATOMIC);
  2093. if (!skb) {
  2094. spin_unlock_irqrestore(&info->readlock, flags);
  2095. return;
  2096. }
  2097. sp = skb_put(skb, l);
  2098. #ifdef CONFIG_ISDN_AUDIO
  2099. ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
  2100. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  2101. #endif
  2102. }
  2103. for (p = msg; *p; p++) {
  2104. switch (*p) {
  2105. case '\r':
  2106. c = m->mdmreg[REG_CR];
  2107. break;
  2108. case '\n':
  2109. c = m->mdmreg[REG_LF];
  2110. break;
  2111. case '\b':
  2112. c = m->mdmreg[REG_BS];
  2113. break;
  2114. default:
  2115. c = *p;
  2116. }
  2117. if (skb) {
  2118. *sp++ = c;
  2119. } else {
  2120. if (tty_insert_flip_char(port, c, TTY_NORMAL) == 0)
  2121. break;
  2122. }
  2123. }
  2124. if (skb) {
  2125. __skb_queue_tail(&dev->drv[info->isdn_driver]->rpqueue[info->isdn_channel], skb);
  2126. dev->drv[info->isdn_driver]->rcvcount[info->isdn_channel] += skb->len;
  2127. spin_unlock_irqrestore(&info->readlock, flags);
  2128. /* Schedule dequeuing */
  2129. if (dev->modempoll && info->rcvsched)
  2130. isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
  2131. } else {
  2132. spin_unlock_irqrestore(&info->readlock, flags);
  2133. tty_flip_buffer_push(port);
  2134. }
  2135. }
  2136. /*
  2137. * Perform ATH Hangup
  2138. */
  2139. static void
  2140. isdn_tty_on_hook(modem_info *info)
  2141. {
  2142. if (info->isdn_channel >= 0) {
  2143. #ifdef ISDN_DEBUG_MODEM_HUP
  2144. printk(KERN_DEBUG "Mhup in isdn_tty_on_hook\n");
  2145. #endif
  2146. isdn_tty_modem_hup(info, 1);
  2147. }
  2148. }
  2149. static void
  2150. isdn_tty_off_hook(void)
  2151. {
  2152. printk(KERN_DEBUG "isdn_tty_off_hook\n");
  2153. }
  2154. #define PLUSWAIT1 (HZ / 2) /* 0.5 sec. */
  2155. #define PLUSWAIT2 (HZ * 3 / 2) /* 1.5 sec */
  2156. /*
  2157. * Check Buffer for Modem-escape-sequence, activate timer-callback to
  2158. * isdn_tty_modem_escape() if sequence found.
  2159. *
  2160. * Parameters:
  2161. * p pointer to databuffer
  2162. * plus escape-character
  2163. * count length of buffer
  2164. * pluscount count of valid escape-characters so far
  2165. * lastplus timestamp of last character
  2166. */
  2167. static void
  2168. isdn_tty_check_esc(const u_char *p, u_char plus, int count, int *pluscount,
  2169. u_long *lastplus)
  2170. {
  2171. if (plus > 127)
  2172. return;
  2173. if (count > 3) {
  2174. p += count - 3;
  2175. count = 3;
  2176. *pluscount = 0;
  2177. }
  2178. while (count > 0) {
  2179. if (*(p++) == plus) {
  2180. if ((*pluscount)++) {
  2181. /* Time since last '+' > 0.5 sec. ? */
  2182. if (time_after(jiffies, *lastplus + PLUSWAIT1))
  2183. *pluscount = 1;
  2184. } else {
  2185. /* Time since last non-'+' < 1.5 sec. ? */
  2186. if (time_before(jiffies, *lastplus + PLUSWAIT2))
  2187. *pluscount = 0;
  2188. }
  2189. if ((*pluscount == 3) && (count == 1))
  2190. isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, 1);
  2191. if (*pluscount > 3)
  2192. *pluscount = 1;
  2193. } else
  2194. *pluscount = 0;
  2195. *lastplus = jiffies;
  2196. count--;
  2197. }
  2198. }
  2199. /*
  2200. * Return result of AT-emulator to tty-receive-buffer, depending on
  2201. * modem-register 12, bit 0 and 1.
  2202. * For CONNECT-messages also switch to online-mode.
  2203. * For RING-message handle auto-ATA if register 0 != 0
  2204. */
  2205. static void
  2206. isdn_tty_modem_result(int code, modem_info *info)
  2207. {
  2208. atemu *m = &info->emu;
  2209. static char *msg[] =
  2210. {"OK", "CONNECT", "RING", "NO CARRIER", "ERROR",
  2211. "CONNECT 64000", "NO DIALTONE", "BUSY", "NO ANSWER",
  2212. "RINGING", "NO MSN/EAZ", "VCON", "RUNG"};
  2213. char s[ISDN_MSNLEN + 10];
  2214. switch (code) {
  2215. case RESULT_RING:
  2216. m->mdmreg[REG_RINGCNT]++;
  2217. if (m->mdmreg[REG_RINGCNT] == m->mdmreg[REG_RINGATA])
  2218. /* Automatically accept incoming call */
  2219. isdn_tty_cmd_ATA(info);
  2220. break;
  2221. case RESULT_NO_CARRIER:
  2222. #ifdef ISDN_DEBUG_MODEM_HUP
  2223. printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n",
  2224. info->closing, !info->port.tty);
  2225. #endif
  2226. m->mdmreg[REG_RINGCNT] = 0;
  2227. del_timer(&info->nc_timer);
  2228. info->ncarrier = 0;
  2229. if (info->closing || !info->port.tty)
  2230. return;
  2231. #ifdef CONFIG_ISDN_AUDIO
  2232. if (info->vonline & 1) {
  2233. #ifdef ISDN_DEBUG_MODEM_VOICE
  2234. printk(KERN_DEBUG "res3: send DLE-ETX on ttyI%d\n",
  2235. info->line);
  2236. #endif
  2237. /* voice-recording, add DLE-ETX */
  2238. isdn_tty_at_cout("\020\003", info);
  2239. }
  2240. if (info->vonline & 2) {
  2241. #ifdef ISDN_DEBUG_MODEM_VOICE
  2242. printk(KERN_DEBUG "res3: send DLE-DC4 on ttyI%d\n",
  2243. info->line);
  2244. #endif
  2245. /* voice-playing, add DLE-DC4 */
  2246. isdn_tty_at_cout("\020\024", info);
  2247. }
  2248. #endif
  2249. break;
  2250. case RESULT_CONNECT:
  2251. case RESULT_CONNECT64000:
  2252. sprintf(info->last_cause, "0000");
  2253. if (!info->online)
  2254. info->online = 2;
  2255. break;
  2256. case RESULT_VCON:
  2257. #ifdef ISDN_DEBUG_MODEM_VOICE
  2258. printk(KERN_DEBUG "res3: send VCON on ttyI%d\n",
  2259. info->line);
  2260. #endif
  2261. sprintf(info->last_cause, "0000");
  2262. if (!info->online)
  2263. info->online = 1;
  2264. break;
  2265. } /* switch (code) */
  2266. if (m->mdmreg[REG_RESP] & BIT_RESP) {
  2267. /* Show results */
  2268. if (m->mdmreg[REG_RESPNUM] & BIT_RESPNUM) {
  2269. /* Show numeric results only */
  2270. sprintf(s, "\r\n%d\r\n", code);
  2271. isdn_tty_at_cout(s, info);
  2272. } else {
  2273. if (code == RESULT_RING) {
  2274. /* return if "show RUNG" and ringcounter>1 */
  2275. if ((m->mdmreg[REG_RUNG] & BIT_RUNG) &&
  2276. (m->mdmreg[REG_RINGCNT] > 1))
  2277. return;
  2278. /* print CID, _before_ _every_ ring */
  2279. if (!(m->mdmreg[REG_CIDONCE] & BIT_CIDONCE)) {
  2280. isdn_tty_at_cout("\r\nCALLER NUMBER: ", info);
  2281. isdn_tty_at_cout(dev->num[info->drv_index], info);
  2282. if (m->mdmreg[REG_CDN] & BIT_CDN) {
  2283. isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
  2284. isdn_tty_at_cout(info->emu.cpn, info);
  2285. }
  2286. }
  2287. }
  2288. isdn_tty_at_cout("\r\n", info);
  2289. isdn_tty_at_cout(msg[code], info);
  2290. switch (code) {
  2291. case RESULT_CONNECT:
  2292. switch (m->mdmreg[REG_L2PROT]) {
  2293. case ISDN_PROTO_L2_MODEM:
  2294. isdn_tty_at_cout(" ", info);
  2295. isdn_tty_at_cout(m->connmsg, info);
  2296. break;
  2297. }
  2298. break;
  2299. case RESULT_RING:
  2300. /* Append CPN, if enabled */
  2301. if ((m->mdmreg[REG_CPN] & BIT_CPN)) {
  2302. sprintf(s, "/%s", m->cpn);
  2303. isdn_tty_at_cout(s, info);
  2304. }
  2305. /* Print CID only once, _after_ 1st RING */
  2306. if ((m->mdmreg[REG_CIDONCE] & BIT_CIDONCE) &&
  2307. (m->mdmreg[REG_RINGCNT] == 1)) {
  2308. isdn_tty_at_cout("\r\n", info);
  2309. isdn_tty_at_cout("CALLER NUMBER: ", info);
  2310. isdn_tty_at_cout(dev->num[info->drv_index], info);
  2311. if (m->mdmreg[REG_CDN] & BIT_CDN) {
  2312. isdn_tty_at_cout("\r\nCALLED NUMBER: ", info);
  2313. isdn_tty_at_cout(info->emu.cpn, info);
  2314. }
  2315. }
  2316. break;
  2317. case RESULT_NO_CARRIER:
  2318. case RESULT_NO_DIALTONE:
  2319. case RESULT_BUSY:
  2320. case RESULT_NO_ANSWER:
  2321. m->mdmreg[REG_RINGCNT] = 0;
  2322. /* Append Cause-Message if enabled */
  2323. if (m->mdmreg[REG_RESPXT] & BIT_RESPXT) {
  2324. sprintf(s, "/%s", info->last_cause);
  2325. isdn_tty_at_cout(s, info);
  2326. }
  2327. break;
  2328. case RESULT_CONNECT64000:
  2329. /* Append Protocol to CONNECT message */
  2330. switch (m->mdmreg[REG_L2PROT]) {
  2331. case ISDN_PROTO_L2_X75I:
  2332. case ISDN_PROTO_L2_X75UI:
  2333. case ISDN_PROTO_L2_X75BUI:
  2334. isdn_tty_at_cout("/X.75", info);
  2335. break;
  2336. case ISDN_PROTO_L2_HDLC:
  2337. isdn_tty_at_cout("/HDLC", info);
  2338. break;
  2339. case ISDN_PROTO_L2_V11096:
  2340. isdn_tty_at_cout("/V110/9600", info);
  2341. break;
  2342. case ISDN_PROTO_L2_V11019:
  2343. isdn_tty_at_cout("/V110/19200", info);
  2344. break;
  2345. case ISDN_PROTO_L2_V11038:
  2346. isdn_tty_at_cout("/V110/38400", info);
  2347. break;
  2348. }
  2349. if (m->mdmreg[REG_T70] & BIT_T70) {
  2350. isdn_tty_at_cout("/T.70", info);
  2351. if (m->mdmreg[REG_T70] & BIT_T70_EXT)
  2352. isdn_tty_at_cout("+", info);
  2353. }
  2354. break;
  2355. }
  2356. isdn_tty_at_cout("\r\n", info);
  2357. }
  2358. }
  2359. if (code == RESULT_NO_CARRIER) {
  2360. if (info->closing || (!info->port.tty))
  2361. return;
  2362. if (tty_port_check_carrier(&info->port))
  2363. tty_hangup(info->port.tty);
  2364. }
  2365. }
  2366. /*
  2367. * Display a modem-register-value.
  2368. */
  2369. static void
  2370. isdn_tty_show_profile(int ridx, modem_info *info)
  2371. {
  2372. char v[6];
  2373. sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]);
  2374. isdn_tty_at_cout(v, info);
  2375. }
  2376. /*
  2377. * Get MSN-string from char-pointer, set pointer to end of number
  2378. */
  2379. static void
  2380. isdn_tty_get_msnstr(char *n, char **p)
  2381. {
  2382. int limit = ISDN_MSNLEN - 1;
  2383. while (((*p[0] >= '0' && *p[0] <= '9') ||
  2384. /* Why a comma ??? */
  2385. (*p[0] == ',') || (*p[0] == ':')) &&
  2386. (limit--))
  2387. *n++ = *p[0]++;
  2388. *n = '\0';
  2389. }
  2390. /*
  2391. * Get phone-number from modem-commandbuffer
  2392. */
  2393. static void
  2394. isdn_tty_getdial(char *p, char *q, int cnt)
  2395. {
  2396. int first = 1;
  2397. int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid
  2398. buffer overflow */
  2399. while (strchr(" 0123456789,#.*WPTSR-", *p) && *p && --cnt > 0) {
  2400. if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) ||
  2401. ((*p == 'R') && first) ||
  2402. (*p == '*') || (*p == '#')) {
  2403. *q++ = *p;
  2404. limit--;
  2405. }
  2406. if (!limit)
  2407. break;
  2408. p++;
  2409. first = 0;
  2410. }
  2411. *q = 0;
  2412. }
  2413. #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
  2414. #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
  2415. static void
  2416. isdn_tty_report(modem_info *info)
  2417. {
  2418. atemu *m = &info->emu;
  2419. char s[80];
  2420. isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info);
  2421. sprintf(s, " Remote Number: %s\r\n", info->last_num);
  2422. isdn_tty_at_cout(s, info);
  2423. sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming");
  2424. isdn_tty_at_cout(s, info);
  2425. isdn_tty_at_cout(" Layer-2 Protocol: ", info);
  2426. switch (info->last_l2) {
  2427. case ISDN_PROTO_L2_X75I:
  2428. isdn_tty_at_cout("X.75i", info);
  2429. break;
  2430. case ISDN_PROTO_L2_X75UI:
  2431. isdn_tty_at_cout("X.75ui", info);
  2432. break;
  2433. case ISDN_PROTO_L2_X75BUI:
  2434. isdn_tty_at_cout("X.75bui", info);
  2435. break;
  2436. case ISDN_PROTO_L2_HDLC:
  2437. isdn_tty_at_cout("HDLC", info);
  2438. break;
  2439. case ISDN_PROTO_L2_V11096:
  2440. isdn_tty_at_cout("V.110 9600 Baud", info);
  2441. break;
  2442. case ISDN_PROTO_L2_V11019:
  2443. isdn_tty_at_cout("V.110 19200 Baud", info);
  2444. break;
  2445. case ISDN_PROTO_L2_V11038:
  2446. isdn_tty_at_cout("V.110 38400 Baud", info);
  2447. break;
  2448. case ISDN_PROTO_L2_TRANS:
  2449. isdn_tty_at_cout("transparent", info);
  2450. break;
  2451. case ISDN_PROTO_L2_MODEM:
  2452. isdn_tty_at_cout("modem", info);
  2453. break;
  2454. case ISDN_PROTO_L2_FAX:
  2455. isdn_tty_at_cout("fax", info);
  2456. break;
  2457. default:
  2458. isdn_tty_at_cout("unknown", info);
  2459. break;
  2460. }
  2461. if (m->mdmreg[REG_T70] & BIT_T70) {
  2462. isdn_tty_at_cout("/T.70", info);
  2463. if (m->mdmreg[REG_T70] & BIT_T70_EXT)
  2464. isdn_tty_at_cout("+", info);
  2465. }
  2466. isdn_tty_at_cout("\r\n", info);
  2467. isdn_tty_at_cout(" Service: ", info);
  2468. switch (info->last_si) {
  2469. case 1:
  2470. isdn_tty_at_cout("audio\r\n", info);
  2471. break;
  2472. case 5:
  2473. isdn_tty_at_cout("btx\r\n", info);
  2474. break;
  2475. case 7:
  2476. isdn_tty_at_cout("data\r\n", info);
  2477. break;
  2478. default:
  2479. sprintf(s, "%d\r\n", info->last_si);
  2480. isdn_tty_at_cout(s, info);
  2481. break;
  2482. }
  2483. sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote");
  2484. isdn_tty_at_cout(s, info);
  2485. sprintf(s, " Last cause: %s\r\n", info->last_cause);
  2486. isdn_tty_at_cout(s, info);
  2487. }
  2488. /*
  2489. * Parse AT&.. commands.
  2490. */
  2491. static int
  2492. isdn_tty_cmd_ATand(char **p, modem_info *info)
  2493. {
  2494. atemu *m = &info->emu;
  2495. int i;
  2496. char rb[100];
  2497. #define MAXRB (sizeof(rb) - 1)
  2498. switch (*p[0]) {
  2499. case 'B':
  2500. /* &B - Set Buffersize */
  2501. p[0]++;
  2502. i = isdn_getnum(p);
  2503. if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX))
  2504. PARSE_ERROR1;
  2505. #ifdef CONFIG_ISDN_AUDIO
  2506. if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF))
  2507. PARSE_ERROR1;
  2508. #endif
  2509. m->mdmreg[REG_PSIZE] = i / 16;
  2510. info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
  2511. switch (m->mdmreg[REG_L2PROT]) {
  2512. case ISDN_PROTO_L2_V11096:
  2513. case ISDN_PROTO_L2_V11019:
  2514. case ISDN_PROTO_L2_V11038:
  2515. info->xmit_size /= 10;
  2516. }
  2517. break;
  2518. case 'C':
  2519. /* &C - DCD Status */
  2520. p[0]++;
  2521. switch (isdn_getnum(p)) {
  2522. case 0:
  2523. m->mdmreg[REG_DCD] &= ~BIT_DCD;
  2524. break;
  2525. case 1:
  2526. m->mdmreg[REG_DCD] |= BIT_DCD;
  2527. break;
  2528. default:
  2529. PARSE_ERROR1
  2530. }
  2531. break;
  2532. case 'D':
  2533. /* &D - Set DTR-Low-behavior */
  2534. p[0]++;
  2535. switch (isdn_getnum(p)) {
  2536. case 0:
  2537. m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP;
  2538. m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
  2539. break;
  2540. case 2:
  2541. m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
  2542. m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
  2543. break;
  2544. case 3:
  2545. m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
  2546. m->mdmreg[REG_DTRR] |= BIT_DTRR;
  2547. break;
  2548. default:
  2549. PARSE_ERROR1
  2550. }
  2551. break;
  2552. case 'E':
  2553. /* &E -Set EAZ/MSN */
  2554. p[0]++;
  2555. isdn_tty_get_msnstr(m->msn, p);
  2556. break;
  2557. case 'F':
  2558. /* &F -Set Factory-Defaults */
  2559. p[0]++;
  2560. if (info->msr & UART_MSR_DCD)
  2561. PARSE_ERROR1;
  2562. isdn_tty_reset_profile(m);
  2563. isdn_tty_modem_reset_regs(info, 1);
  2564. break;
  2565. #ifdef DUMMY_HAYES_AT
  2566. case 'K':
  2567. /* only for be compilant with common scripts */
  2568. /* &K Flowcontrol - no function */
  2569. p[0]++;
  2570. isdn_getnum(p);
  2571. break;
  2572. #endif
  2573. case 'L':
  2574. /* &L -Set Numbers to listen on */
  2575. p[0]++;
  2576. i = 0;
  2577. while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) &&
  2578. (i < ISDN_LMSNLEN - 1))
  2579. m->lmsn[i++] = *p[0]++;
  2580. m->lmsn[i] = '\0';
  2581. break;
  2582. case 'R':
  2583. /* &R - Set V.110 bitrate adaption */
  2584. p[0]++;
  2585. i = isdn_getnum(p);
  2586. switch (i) {
  2587. case 0:
  2588. /* Switch off V.110, back to X.75 */
  2589. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2590. m->mdmreg[REG_SI2] = 0;
  2591. info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
  2592. break;
  2593. case 9600:
  2594. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096;
  2595. m->mdmreg[REG_SI2] = 197;
  2596. info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
  2597. break;
  2598. case 19200:
  2599. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019;
  2600. m->mdmreg[REG_SI2] = 199;
  2601. info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
  2602. break;
  2603. case 38400:
  2604. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038;
  2605. m->mdmreg[REG_SI2] = 198; /* no existing standard for this */
  2606. info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
  2607. break;
  2608. default:
  2609. PARSE_ERROR1;
  2610. }
  2611. /* Switch off T.70 */
  2612. m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
  2613. /* Set Service 7 */
  2614. m->mdmreg[REG_SI1] |= 4;
  2615. break;
  2616. case 'S':
  2617. /* &S - Set Windowsize */
  2618. p[0]++;
  2619. i = isdn_getnum(p);
  2620. if ((i > 0) && (i < 9))
  2621. m->mdmreg[REG_WSIZE] = i;
  2622. else
  2623. PARSE_ERROR1;
  2624. break;
  2625. case 'V':
  2626. /* &V - Show registers */
  2627. p[0]++;
  2628. isdn_tty_at_cout("\r\n", info);
  2629. for (i = 0; i < ISDN_MODEM_NUMREG; i++) {
  2630. sprintf(rb, "S%02d=%03d%s", i,
  2631. m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n");
  2632. isdn_tty_at_cout(rb, info);
  2633. }
  2634. sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n",
  2635. strlen(m->msn) ? m->msn : "None");
  2636. isdn_tty_at_cout(rb, info);
  2637. if (strlen(m->lmsn)) {
  2638. isdn_tty_at_cout("\r\nListen: ", info);
  2639. isdn_tty_at_cout(m->lmsn, info);
  2640. isdn_tty_at_cout("\r\n", info);
  2641. }
  2642. break;
  2643. case 'W':
  2644. /* &W - Write Profile */
  2645. p[0]++;
  2646. switch (*p[0]) {
  2647. case '0':
  2648. p[0]++;
  2649. modem_write_profile(m);
  2650. break;
  2651. default:
  2652. PARSE_ERROR1;
  2653. }
  2654. break;
  2655. case 'X':
  2656. /* &X - Switch to BTX-Mode and T.70 */
  2657. p[0]++;
  2658. switch (isdn_getnum(p)) {
  2659. case 0:
  2660. m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
  2661. info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
  2662. break;
  2663. case 1:
  2664. m->mdmreg[REG_T70] |= BIT_T70;
  2665. m->mdmreg[REG_T70] &= ~BIT_T70_EXT;
  2666. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2667. info->xmit_size = 112;
  2668. m->mdmreg[REG_SI1] = 4;
  2669. m->mdmreg[REG_SI2] = 0;
  2670. break;
  2671. case 2:
  2672. m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT);
  2673. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2674. info->xmit_size = 112;
  2675. m->mdmreg[REG_SI1] = 4;
  2676. m->mdmreg[REG_SI2] = 0;
  2677. break;
  2678. default:
  2679. PARSE_ERROR1;
  2680. }
  2681. break;
  2682. default:
  2683. PARSE_ERROR1;
  2684. }
  2685. return 0;
  2686. }
  2687. static int
  2688. isdn_tty_check_ats(int mreg, int mval, modem_info *info, atemu *m)
  2689. {
  2690. /* Some plausibility checks */
  2691. switch (mreg) {
  2692. case REG_L2PROT:
  2693. if (mval > ISDN_PROTO_L2_MAX)
  2694. return 1;
  2695. break;
  2696. case REG_PSIZE:
  2697. if ((mval * 16) > ISDN_SERIAL_XMIT_MAX)
  2698. return 1;
  2699. #ifdef CONFIG_ISDN_AUDIO
  2700. if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX))
  2701. return 1;
  2702. #endif
  2703. info->xmit_size = mval * 16;
  2704. switch (m->mdmreg[REG_L2PROT]) {
  2705. case ISDN_PROTO_L2_V11096:
  2706. case ISDN_PROTO_L2_V11019:
  2707. case ISDN_PROTO_L2_V11038:
  2708. info->xmit_size /= 10;
  2709. }
  2710. break;
  2711. case REG_SI1I:
  2712. case REG_PLAN:
  2713. case REG_SCREEN:
  2714. /* readonly registers */
  2715. return 1;
  2716. }
  2717. return 0;
  2718. }
  2719. /*
  2720. * Perform ATS command
  2721. */
  2722. static int
  2723. isdn_tty_cmd_ATS(char **p, modem_info *info)
  2724. {
  2725. atemu *m = &info->emu;
  2726. int bitpos;
  2727. int mreg;
  2728. int mval;
  2729. int bval;
  2730. mreg = isdn_getnum(p);
  2731. if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG)
  2732. PARSE_ERROR1;
  2733. switch (*p[0]) {
  2734. case '=':
  2735. p[0]++;
  2736. mval = isdn_getnum(p);
  2737. if (mval < 0 || mval > 255)
  2738. PARSE_ERROR1;
  2739. if (isdn_tty_check_ats(mreg, mval, info, m))
  2740. PARSE_ERROR1;
  2741. m->mdmreg[mreg] = mval;
  2742. break;
  2743. case '.':
  2744. /* Set/Clear a single bit */
  2745. p[0]++;
  2746. bitpos = isdn_getnum(p);
  2747. if ((bitpos < 0) || (bitpos > 7))
  2748. PARSE_ERROR1;
  2749. switch (*p[0]) {
  2750. case '=':
  2751. p[0]++;
  2752. bval = isdn_getnum(p);
  2753. if (bval < 0 || bval > 1)
  2754. PARSE_ERROR1;
  2755. if (bval)
  2756. mval = m->mdmreg[mreg] | (1 << bitpos);
  2757. else
  2758. mval = m->mdmreg[mreg] & ~(1 << bitpos);
  2759. if (isdn_tty_check_ats(mreg, mval, info, m))
  2760. PARSE_ERROR1;
  2761. m->mdmreg[mreg] = mval;
  2762. break;
  2763. case '?':
  2764. p[0]++;
  2765. isdn_tty_at_cout("\r\n", info);
  2766. isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0",
  2767. info);
  2768. break;
  2769. default:
  2770. PARSE_ERROR1;
  2771. }
  2772. break;
  2773. case '?':
  2774. p[0]++;
  2775. isdn_tty_show_profile(mreg, info);
  2776. break;
  2777. default:
  2778. PARSE_ERROR1;
  2779. break;
  2780. }
  2781. return 0;
  2782. }
  2783. /*
  2784. * Perform ATA command
  2785. */
  2786. static void
  2787. isdn_tty_cmd_ATA(modem_info *info)
  2788. {
  2789. atemu *m = &info->emu;
  2790. isdn_ctrl cmd;
  2791. int l2;
  2792. if (info->msr & UART_MSR_RI) {
  2793. /* Accept incoming call */
  2794. info->last_dir = 0;
  2795. strcpy(info->last_num, dev->num[info->drv_index]);
  2796. m->mdmreg[REG_RINGCNT] = 0;
  2797. info->msr &= ~UART_MSR_RI;
  2798. l2 = m->mdmreg[REG_L2PROT];
  2799. #ifdef CONFIG_ISDN_AUDIO
  2800. /* If more than one bit set in reg18, autoselect Layer2 */
  2801. if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) {
  2802. if (m->mdmreg[REG_SI1I] == 1) {
  2803. if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX))
  2804. l2 = ISDN_PROTO_L2_TRANS;
  2805. } else
  2806. l2 = ISDN_PROTO_L2_X75I;
  2807. }
  2808. #endif
  2809. cmd.driver = info->isdn_driver;
  2810. cmd.command = ISDN_CMD_SETL2;
  2811. cmd.arg = info->isdn_channel + (l2 << 8);
  2812. info->last_l2 = l2;
  2813. isdn_command(&cmd);
  2814. cmd.driver = info->isdn_driver;
  2815. cmd.command = ISDN_CMD_SETL3;
  2816. cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
  2817. #ifdef CONFIG_ISDN_TTY_FAX
  2818. if (l2 == ISDN_PROTO_L2_FAX) {
  2819. cmd.parm.fax = info->fax;
  2820. info->fax->direction = ISDN_TTY_FAX_CONN_IN;
  2821. }
  2822. #endif
  2823. isdn_command(&cmd);
  2824. cmd.driver = info->isdn_driver;
  2825. cmd.arg = info->isdn_channel;
  2826. cmd.command = ISDN_CMD_ACCEPTD;
  2827. info->dialing = 16;
  2828. info->emu.carrierwait = 0;
  2829. isdn_command(&cmd);
  2830. isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
  2831. } else
  2832. isdn_tty_modem_result(RESULT_NO_ANSWER, info);
  2833. }
  2834. #ifdef CONFIG_ISDN_AUDIO
  2835. /*
  2836. * Parse AT+F.. commands
  2837. */
  2838. static int
  2839. isdn_tty_cmd_PLUSF(char **p, modem_info *info)
  2840. {
  2841. atemu *m = &info->emu;
  2842. char rs[20];
  2843. if (!strncmp(p[0], "CLASS", 5)) {
  2844. p[0] += 5;
  2845. switch (*p[0]) {
  2846. case '?':
  2847. p[0]++;
  2848. sprintf(rs, "\r\n%d",
  2849. (m->mdmreg[REG_SI1] & 1) ? 8 : 0);
  2850. #ifdef CONFIG_ISDN_TTY_FAX
  2851. if (TTY_IS_FCLASS2(info))
  2852. sprintf(rs, "\r\n2");
  2853. else if (TTY_IS_FCLASS1(info))
  2854. sprintf(rs, "\r\n1");
  2855. #endif
  2856. isdn_tty_at_cout(rs, info);
  2857. break;
  2858. case '=':
  2859. p[0]++;
  2860. switch (*p[0]) {
  2861. case '0':
  2862. p[0]++;
  2863. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2864. m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
  2865. m->mdmreg[REG_SI1] = 4;
  2866. info->xmit_size =
  2867. m->mdmreg[REG_PSIZE] * 16;
  2868. break;
  2869. #ifdef CONFIG_ISDN_TTY_FAX
  2870. case '1':
  2871. p[0]++;
  2872. if (!(dev->global_features &
  2873. ISDN_FEATURE_L3_FCLASS1))
  2874. PARSE_ERROR1;
  2875. m->mdmreg[REG_SI1] = 1;
  2876. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
  2877. m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1;
  2878. info->xmit_size =
  2879. m->mdmreg[REG_PSIZE] * 16;
  2880. break;
  2881. case '2':
  2882. p[0]++;
  2883. if (!(dev->global_features &
  2884. ISDN_FEATURE_L3_FCLASS2))
  2885. PARSE_ERROR1;
  2886. m->mdmreg[REG_SI1] = 1;
  2887. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
  2888. m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2;
  2889. info->xmit_size =
  2890. m->mdmreg[REG_PSIZE] * 16;
  2891. break;
  2892. #endif
  2893. case '8':
  2894. p[0]++;
  2895. /* L2 will change on dialout with si=1 */
  2896. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2897. m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
  2898. m->mdmreg[REG_SI1] = 5;
  2899. info->xmit_size = VBUF;
  2900. break;
  2901. case '?':
  2902. p[0]++;
  2903. strcpy(rs, "\r\n0,");
  2904. #ifdef CONFIG_ISDN_TTY_FAX
  2905. if (dev->global_features &
  2906. ISDN_FEATURE_L3_FCLASS1)
  2907. strcat(rs, "1,");
  2908. if (dev->global_features &
  2909. ISDN_FEATURE_L3_FCLASS2)
  2910. strcat(rs, "2,");
  2911. #endif
  2912. strcat(rs, "8");
  2913. isdn_tty_at_cout(rs, info);
  2914. break;
  2915. default:
  2916. PARSE_ERROR1;
  2917. }
  2918. break;
  2919. default:
  2920. PARSE_ERROR1;
  2921. }
  2922. return 0;
  2923. }
  2924. #ifdef CONFIG_ISDN_TTY_FAX
  2925. return (isdn_tty_cmd_PLUSF_FAX(p, info));
  2926. #else
  2927. PARSE_ERROR1;
  2928. #endif
  2929. }
  2930. /*
  2931. * Parse AT+V.. commands
  2932. */
  2933. static int
  2934. isdn_tty_cmd_PLUSV(char **p, modem_info *info)
  2935. {
  2936. atemu *m = &info->emu;
  2937. isdn_ctrl cmd;
  2938. static char *vcmd[] =
  2939. {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL};
  2940. int i;
  2941. int par1;
  2942. int par2;
  2943. char rs[20];
  2944. i = 0;
  2945. while (vcmd[i]) {
  2946. if (!strncmp(vcmd[i], p[0], 2)) {
  2947. p[0] += 2;
  2948. break;
  2949. }
  2950. i++;
  2951. }
  2952. switch (i) {
  2953. case 0:
  2954. /* AT+VNH - Auto hangup feature */
  2955. switch (*p[0]) {
  2956. case '?':
  2957. p[0]++;
  2958. isdn_tty_at_cout("\r\n1", info);
  2959. break;
  2960. case '=':
  2961. p[0]++;
  2962. switch (*p[0]) {
  2963. case '1':
  2964. p[0]++;
  2965. break;
  2966. case '?':
  2967. p[0]++;
  2968. isdn_tty_at_cout("\r\n1", info);
  2969. break;
  2970. default:
  2971. PARSE_ERROR1;
  2972. }
  2973. break;
  2974. default:
  2975. PARSE_ERROR1;
  2976. }
  2977. break;
  2978. case 1:
  2979. /* AT+VIP - Reset all voice parameters */
  2980. isdn_tty_modem_reset_vpar(m);
  2981. break;
  2982. case 2:
  2983. /* AT+VLS - Select device, accept incoming call */
  2984. switch (*p[0]) {
  2985. case '?':
  2986. p[0]++;
  2987. sprintf(rs, "\r\n%d", m->vpar[0]);
  2988. isdn_tty_at_cout(rs, info);
  2989. break;
  2990. case '=':
  2991. p[0]++;
  2992. switch (*p[0]) {
  2993. case '0':
  2994. p[0]++;
  2995. m->vpar[0] = 0;
  2996. break;
  2997. case '2':
  2998. p[0]++;
  2999. m->vpar[0] = 2;
  3000. break;
  3001. case '?':
  3002. p[0]++;
  3003. isdn_tty_at_cout("\r\n0,2", info);
  3004. break;
  3005. default:
  3006. PARSE_ERROR1;
  3007. }
  3008. break;
  3009. default:
  3010. PARSE_ERROR1;
  3011. }
  3012. break;
  3013. case 3:
  3014. /* AT+VRX - Start recording */
  3015. if (!m->vpar[0])
  3016. PARSE_ERROR1;
  3017. if (info->online != 1) {
  3018. isdn_tty_modem_result(RESULT_NO_ANSWER, info);
  3019. return 1;
  3020. }
  3021. info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
  3022. if (!info->dtmf_state) {
  3023. printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
  3024. PARSE_ERROR1;
  3025. }
  3026. info->silence_state = isdn_audio_silence_init(info->silence_state);
  3027. if (!info->silence_state) {
  3028. printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n");
  3029. PARSE_ERROR1;
  3030. }
  3031. if (m->vpar[3] < 5) {
  3032. info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]);
  3033. if (!info->adpcmr) {
  3034. printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
  3035. PARSE_ERROR1;
  3036. }
  3037. }
  3038. #ifdef ISDN_DEBUG_AT
  3039. printk(KERN_DEBUG "AT: +VRX\n");
  3040. #endif
  3041. info->vonline |= 1;
  3042. isdn_tty_modem_result(RESULT_CONNECT, info);
  3043. return 0;
  3044. break;
  3045. case 4:
  3046. /* AT+VSD - Silence detection */
  3047. switch (*p[0]) {
  3048. case '?':
  3049. p[0]++;
  3050. sprintf(rs, "\r\n<%d>,<%d>",
  3051. m->vpar[1],
  3052. m->vpar[2]);
  3053. isdn_tty_at_cout(rs, info);
  3054. break;
  3055. case '=':
  3056. p[0]++;
  3057. if ((*p[0] >= '0') && (*p[0] <= '9')) {
  3058. par1 = isdn_getnum(p);
  3059. if ((par1 < 0) || (par1 > 31))
  3060. PARSE_ERROR1;
  3061. if (*p[0] != ',')
  3062. PARSE_ERROR1;
  3063. p[0]++;
  3064. par2 = isdn_getnum(p);
  3065. if ((par2 < 0) || (par2 > 255))
  3066. PARSE_ERROR1;
  3067. m->vpar[1] = par1;
  3068. m->vpar[2] = par2;
  3069. break;
  3070. } else
  3071. if (*p[0] == '?') {
  3072. p[0]++;
  3073. isdn_tty_at_cout("\r\n<0-31>,<0-255>",
  3074. info);
  3075. break;
  3076. } else
  3077. PARSE_ERROR1;
  3078. break;
  3079. default:
  3080. PARSE_ERROR1;
  3081. }
  3082. break;
  3083. case 5:
  3084. /* AT+VSM - Select compression */
  3085. switch (*p[0]) {
  3086. case '?':
  3087. p[0]++;
  3088. sprintf(rs, "\r\n<%d>,<%d><8000>",
  3089. m->vpar[3],
  3090. m->vpar[1]);
  3091. isdn_tty_at_cout(rs, info);
  3092. break;
  3093. case '=':
  3094. p[0]++;
  3095. switch (*p[0]) {
  3096. case '2':
  3097. case '3':
  3098. case '4':
  3099. case '5':
  3100. case '6':
  3101. par1 = isdn_getnum(p);
  3102. if ((par1 < 2) || (par1 > 6))
  3103. PARSE_ERROR1;
  3104. m->vpar[3] = par1;
  3105. break;
  3106. case '?':
  3107. p[0]++;
  3108. isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
  3109. info);
  3110. isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
  3111. info);
  3112. isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
  3113. info);
  3114. isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
  3115. info);
  3116. isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
  3117. info);
  3118. break;
  3119. default:
  3120. PARSE_ERROR1;
  3121. }
  3122. break;
  3123. default:
  3124. PARSE_ERROR1;
  3125. }
  3126. break;
  3127. case 6:
  3128. /* AT+VTX - Start sending */
  3129. if (!m->vpar[0])
  3130. PARSE_ERROR1;
  3131. if (info->online != 1) {
  3132. isdn_tty_modem_result(RESULT_NO_ANSWER, info);
  3133. return 1;
  3134. }
  3135. info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
  3136. if (!info->dtmf_state) {
  3137. printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
  3138. PARSE_ERROR1;
  3139. }
  3140. if (m->vpar[3] < 5) {
  3141. info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]);
  3142. if (!info->adpcms) {
  3143. printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
  3144. PARSE_ERROR1;
  3145. }
  3146. }
  3147. #ifdef ISDN_DEBUG_AT
  3148. printk(KERN_DEBUG "AT: +VTX\n");
  3149. #endif
  3150. m->lastDLE = 0;
  3151. info->vonline |= 2;
  3152. isdn_tty_modem_result(RESULT_CONNECT, info);
  3153. return 0;
  3154. break;
  3155. case 7:
  3156. /* AT+VDD - DTMF detection */
  3157. switch (*p[0]) {
  3158. case '?':
  3159. p[0]++;
  3160. sprintf(rs, "\r\n<%d>,<%d>",
  3161. m->vpar[4],
  3162. m->vpar[5]);
  3163. isdn_tty_at_cout(rs, info);
  3164. break;
  3165. case '=':
  3166. p[0]++;
  3167. if ((*p[0] >= '0') && (*p[0] <= '9')) {
  3168. if (info->online != 1)
  3169. PARSE_ERROR1;
  3170. par1 = isdn_getnum(p);
  3171. if ((par1 < 0) || (par1 > 15))
  3172. PARSE_ERROR1;
  3173. if (*p[0] != ',')
  3174. PARSE_ERROR1;
  3175. p[0]++;
  3176. par2 = isdn_getnum(p);
  3177. if ((par2 < 0) || (par2 > 255))
  3178. PARSE_ERROR1;
  3179. m->vpar[4] = par1;
  3180. m->vpar[5] = par2;
  3181. cmd.driver = info->isdn_driver;
  3182. cmd.command = ISDN_CMD_AUDIO;
  3183. cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8);
  3184. cmd.parm.num[0] = par1;
  3185. cmd.parm.num[1] = par2;
  3186. isdn_command(&cmd);
  3187. break;
  3188. } else
  3189. if (*p[0] == '?') {
  3190. p[0]++;
  3191. isdn_tty_at_cout("\r\n<0-15>,<0-255>",
  3192. info);
  3193. break;
  3194. } else
  3195. PARSE_ERROR1;
  3196. break;
  3197. default:
  3198. PARSE_ERROR1;
  3199. }
  3200. break;
  3201. default:
  3202. PARSE_ERROR1;
  3203. }
  3204. return 0;
  3205. }
  3206. #endif /* CONFIG_ISDN_AUDIO */
  3207. /*
  3208. * Parse and perform an AT-command-line.
  3209. */
  3210. static void
  3211. isdn_tty_parse_at(modem_info *info)
  3212. {
  3213. atemu *m = &info->emu;
  3214. char *p;
  3215. char ds[ISDN_MSNLEN];
  3216. #ifdef ISDN_DEBUG_AT
  3217. printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd);
  3218. #endif
  3219. for (p = &m->mdmcmd[2]; *p;) {
  3220. switch (*p) {
  3221. case ' ':
  3222. p++;
  3223. break;
  3224. case 'A':
  3225. /* A - Accept incoming call */
  3226. p++;
  3227. isdn_tty_cmd_ATA(info);
  3228. return;
  3229. case 'D':
  3230. /* D - Dial */
  3231. if (info->msr & UART_MSR_DCD)
  3232. PARSE_ERROR;
  3233. if (info->msr & UART_MSR_RI) {
  3234. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  3235. return;
  3236. }
  3237. isdn_tty_getdial(++p, ds, sizeof ds);
  3238. p += strlen(p);
  3239. if (!strlen(m->msn))
  3240. isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info);
  3241. else if (strlen(ds))
  3242. isdn_tty_dial(ds, info, m);
  3243. else
  3244. PARSE_ERROR;
  3245. return;
  3246. case 'E':
  3247. /* E - Turn Echo on/off */
  3248. p++;
  3249. switch (isdn_getnum(&p)) {
  3250. case 0:
  3251. m->mdmreg[REG_ECHO] &= ~BIT_ECHO;
  3252. break;
  3253. case 1:
  3254. m->mdmreg[REG_ECHO] |= BIT_ECHO;
  3255. break;
  3256. default:
  3257. PARSE_ERROR;
  3258. }
  3259. break;
  3260. case 'H':
  3261. /* H - On/Off-hook */
  3262. p++;
  3263. switch (*p) {
  3264. case '0':
  3265. p++;
  3266. isdn_tty_on_hook(info);
  3267. break;
  3268. case '1':
  3269. p++;
  3270. isdn_tty_off_hook();
  3271. break;
  3272. default:
  3273. isdn_tty_on_hook(info);
  3274. break;
  3275. }
  3276. break;
  3277. case 'I':
  3278. /* I - Information */
  3279. p++;
  3280. isdn_tty_at_cout("\r\nLinux ISDN", info);
  3281. switch (*p) {
  3282. case '0':
  3283. case '1':
  3284. p++;
  3285. break;
  3286. case '2':
  3287. p++;
  3288. isdn_tty_report(info);
  3289. break;
  3290. case '3':
  3291. p++;
  3292. snprintf(ds, sizeof(ds), "\r\n%d", info->emu.charge);
  3293. isdn_tty_at_cout(ds, info);
  3294. break;
  3295. default:;
  3296. }
  3297. break;
  3298. #ifdef DUMMY_HAYES_AT
  3299. case 'L':
  3300. case 'M':
  3301. /* only for be compilant with common scripts */
  3302. /* no function */
  3303. p++;
  3304. isdn_getnum(&p);
  3305. break;
  3306. #endif
  3307. case 'O':
  3308. /* O - Go online */
  3309. p++;
  3310. if (info->msr & UART_MSR_DCD)
  3311. /* if B-Channel is up */
  3312. isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT : RESULT_CONNECT64000, info);
  3313. else
  3314. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  3315. return;
  3316. case 'Q':
  3317. /* Q - Turn Emulator messages on/off */
  3318. p++;
  3319. switch (isdn_getnum(&p)) {
  3320. case 0:
  3321. m->mdmreg[REG_RESP] |= BIT_RESP;
  3322. break;
  3323. case 1:
  3324. m->mdmreg[REG_RESP] &= ~BIT_RESP;
  3325. break;
  3326. default:
  3327. PARSE_ERROR;
  3328. }
  3329. break;
  3330. case 'S':
  3331. /* S - Set/Get Register */
  3332. p++;
  3333. if (isdn_tty_cmd_ATS(&p, info))
  3334. return;
  3335. break;
  3336. case 'V':
  3337. /* V - Numeric or ASCII Emulator-messages */
  3338. p++;
  3339. switch (isdn_getnum(&p)) {
  3340. case 0:
  3341. m->mdmreg[REG_RESP] |= BIT_RESPNUM;
  3342. break;
  3343. case 1:
  3344. m->mdmreg[REG_RESP] &= ~BIT_RESPNUM;
  3345. break;
  3346. default:
  3347. PARSE_ERROR;
  3348. }
  3349. break;
  3350. case 'Z':
  3351. /* Z - Load Registers from Profile */
  3352. p++;
  3353. if (info->msr & UART_MSR_DCD) {
  3354. info->online = 0;
  3355. isdn_tty_on_hook(info);
  3356. }
  3357. isdn_tty_modem_reset_regs(info, 1);
  3358. break;
  3359. case '+':
  3360. p++;
  3361. switch (*p) {
  3362. #ifdef CONFIG_ISDN_AUDIO
  3363. case 'F':
  3364. p++;
  3365. if (isdn_tty_cmd_PLUSF(&p, info))
  3366. return;
  3367. break;
  3368. case 'V':
  3369. if ((!(m->mdmreg[REG_SI1] & 1)) ||
  3370. (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM))
  3371. PARSE_ERROR;
  3372. p++;
  3373. if (isdn_tty_cmd_PLUSV(&p, info))
  3374. return;
  3375. break;
  3376. #endif /* CONFIG_ISDN_AUDIO */
  3377. case 'S': /* SUSPEND */
  3378. p++;
  3379. isdn_tty_get_msnstr(ds, &p);
  3380. isdn_tty_suspend(ds, info, m);
  3381. break;
  3382. case 'R': /* RESUME */
  3383. p++;
  3384. isdn_tty_get_msnstr(ds, &p);
  3385. isdn_tty_resume(ds, info, m);
  3386. break;
  3387. case 'M': /* MESSAGE */
  3388. p++;
  3389. isdn_tty_send_msg(info, m, p);
  3390. break;
  3391. default:
  3392. PARSE_ERROR;
  3393. }
  3394. break;
  3395. case '&':
  3396. p++;
  3397. if (isdn_tty_cmd_ATand(&p, info))
  3398. return;
  3399. break;
  3400. default:
  3401. PARSE_ERROR;
  3402. }
  3403. }
  3404. #ifdef CONFIG_ISDN_AUDIO
  3405. if (!info->vonline)
  3406. #endif
  3407. isdn_tty_modem_result(RESULT_OK, info);
  3408. }
  3409. /* Need own toupper() because standard-toupper is not available
  3410. * within modules.
  3411. */
  3412. #define my_toupper(c) (((c >= 'a') && (c <= 'z')) ? (c & 0xdf) : c)
  3413. /*
  3414. * Perform line-editing of AT-commands
  3415. *
  3416. * Parameters:
  3417. * p inputbuffer
  3418. * count length of buffer
  3419. * channel index to line (minor-device)
  3420. */
  3421. static int
  3422. isdn_tty_edit_at(const char *p, int count, modem_info *info)
  3423. {
  3424. atemu *m = &info->emu;
  3425. int total = 0;
  3426. u_char c;
  3427. char eb[2];
  3428. int cnt;
  3429. for (cnt = count; cnt > 0; p++, cnt--) {
  3430. c = *p;
  3431. total++;
  3432. if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) {
  3433. /* Separator (CR or LF) */
  3434. m->mdmcmd[m->mdmcmdl] = 0;
  3435. if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
  3436. eb[0] = c;
  3437. eb[1] = 0;
  3438. isdn_tty_at_cout(eb, info);
  3439. }
  3440. if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2))))
  3441. isdn_tty_parse_at(info);
  3442. m->mdmcmdl = 0;
  3443. continue;
  3444. }
  3445. if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) {
  3446. /* Backspace-Function */
  3447. if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) {
  3448. if (m->mdmcmdl)
  3449. m->mdmcmdl--;
  3450. if (m->mdmreg[REG_ECHO] & BIT_ECHO)
  3451. isdn_tty_at_cout("\b", info);
  3452. }
  3453. continue;
  3454. }
  3455. if (cmdchar(c)) {
  3456. if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
  3457. eb[0] = c;
  3458. eb[1] = 0;
  3459. isdn_tty_at_cout(eb, info);
  3460. }
  3461. if (m->mdmcmdl < 255) {
  3462. c = my_toupper(c);
  3463. switch (m->mdmcmdl) {
  3464. case 1:
  3465. if (c == 'T') {
  3466. m->mdmcmd[m->mdmcmdl] = c;
  3467. m->mdmcmd[++m->mdmcmdl] = 0;
  3468. break;
  3469. } else
  3470. m->mdmcmdl = 0;
  3471. /* Fall through, check for 'A' */
  3472. case 0:
  3473. if (c == 'A') {
  3474. m->mdmcmd[m->mdmcmdl] = c;
  3475. m->mdmcmd[++m->mdmcmdl] = 0;
  3476. }
  3477. break;
  3478. default:
  3479. m->mdmcmd[m->mdmcmdl] = c;
  3480. m->mdmcmd[++m->mdmcmdl] = 0;
  3481. }
  3482. }
  3483. }
  3484. }
  3485. return total;
  3486. }
  3487. /*
  3488. * Switch all modem-channels who are online and got a valid
  3489. * escape-sequence 1.5 seconds ago, to command-mode.
  3490. * This function is called every second via timer-interrupt from within
  3491. * timer-dispatcher isdn_timer_function()
  3492. */
  3493. void
  3494. isdn_tty_modem_escape(void)
  3495. {
  3496. int ton = 0;
  3497. int i;
  3498. int midx;
  3499. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  3500. if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) {
  3501. modem_info *info = &dev->mdm.info[midx];
  3502. if (info->online) {
  3503. ton = 1;
  3504. if ((info->emu.pluscount == 3) &&
  3505. time_after(jiffies,
  3506. info->emu.lastplus + PLUSWAIT2)) {
  3507. info->emu.pluscount = 0;
  3508. info->online = 0;
  3509. isdn_tty_modem_result(RESULT_OK, info);
  3510. }
  3511. }
  3512. }
  3513. isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton);
  3514. }
  3515. /*
  3516. * Put a RING-message to all modem-channels who have the RI-bit set.
  3517. * This function is called every second via timer-interrupt from within
  3518. * timer-dispatcher isdn_timer_function()
  3519. */
  3520. void
  3521. isdn_tty_modem_ring(void)
  3522. {
  3523. int ton = 0;
  3524. int i;
  3525. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  3526. modem_info *info = &dev->mdm.info[i];
  3527. if (info->msr & UART_MSR_RI) {
  3528. ton = 1;
  3529. isdn_tty_modem_result(RESULT_RING, info);
  3530. }
  3531. }
  3532. isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton);
  3533. }
  3534. /*
  3535. * For all online tty's, try sending data to
  3536. * the lower levels.
  3537. */
  3538. void
  3539. isdn_tty_modem_xmit(void)
  3540. {
  3541. int ton = 1;
  3542. int i;
  3543. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  3544. modem_info *info = &dev->mdm.info[i];
  3545. if (info->online) {
  3546. ton = 1;
  3547. isdn_tty_senddown(info);
  3548. isdn_tty_tint(info);
  3549. }
  3550. }
  3551. isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton);
  3552. }
  3553. /*
  3554. * Check all channels if we have a 'no carrier' timeout.
  3555. * Timeout value is set by Register S7.
  3556. */
  3557. void
  3558. isdn_tty_carrier_timeout(void)
  3559. {
  3560. int ton = 0;
  3561. int i;
  3562. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  3563. modem_info *info = &dev->mdm.info[i];
  3564. if (!info->dialing)
  3565. continue;
  3566. if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) {
  3567. info->dialing = 0;
  3568. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  3569. isdn_tty_modem_hup(info, 1);
  3570. } else
  3571. ton = 1;
  3572. }
  3573. isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton);
  3574. }