isdn_tty.c 89 KB

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