isdn_tty.c 95 KB

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