isdn_tty.c 88 KB

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