isdn_tty.c 89 KB

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