isdn_tty.c 91 KB

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