isdn_tty.c 89 KB

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