isdn_tty.c 94 KB

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