isdn_tty.c 94 KB

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