isdn_tty.c 95 KB

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