isdn_tty.c 89 KB

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