isdn_tty.c 94 KB

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