isdn_tty.c 92 KB

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