isdn_tty.c 94 KB

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