isdn_tty.c 95 KB

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