isdn_tty.c 92 KB

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