isdn_tty.c 89 KB

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