isdn_tty.c 91 KB

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