isdn_tty.c 92 KB

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