isdn_tty.c 91 KB

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