isdn_tty.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890
  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/slab.h>
  15. #include <linux/delay.h>
  16. #include <linux/mutex.h>
  17. #include "isdn_common.h"
  18. #include "isdn_tty.h"
  19. #ifdef CONFIG_ISDN_AUDIO
  20. #include "isdn_audio.h"
  21. #define VBUF 0x3e0
  22. #define VBUFX (VBUF/16)
  23. #endif
  24. #define FIX_FILE_TRANSFER
  25. #define DUMMY_HAYES_AT
  26. /* Prototypes */
  27. static DEFINE_MUTEX(modem_info_mutex);
  28. static int isdn_tty_edit_at(const char *, int, modem_info *);
  29. static void isdn_tty_check_esc(const u_char *, u_char, int, int *, u_long *);
  30. static void isdn_tty_modem_reset_regs(modem_info *, int);
  31. static void isdn_tty_cmd_ATA(modem_info *);
  32. static void isdn_tty_flush_buffer(struct tty_struct *);
  33. static void isdn_tty_modem_result(int, modem_info *);
  34. #ifdef CONFIG_ISDN_AUDIO
  35. static int isdn_tty_countDLE(unsigned char *, int);
  36. #endif
  37. /* Leave this unchanged unless you know what you do! */
  38. #define MODEM_PARANOIA_CHECK
  39. #define MODEM_DO_RESTART
  40. static int bit2si[8] =
  41. {1, 5, 7, 7, 7, 7, 7, 7};
  42. static int si2bit[8] =
  43. {4, 1, 4, 4, 4, 4, 4, 4};
  44. char *isdn_tty_revision = "$Revision: 1.1.2.3 $";
  45. /* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
  46. * to stuff incoming data directly into a tty's flip-buffer. This
  47. * is done to speed up tty-receiving if the receive-queue is empty.
  48. * This routine MUST be called with interrupts off.
  49. * Return:
  50. * 1 = Success
  51. * 0 = Failure, data has to be buffered and later processed by
  52. * isdn_tty_readmodem().
  53. */
  54. static int
  55. isdn_tty_try_read(modem_info * info, struct sk_buff *skb)
  56. {
  57. int c;
  58. int len;
  59. struct tty_struct *tty;
  60. char last;
  61. if (info->online) {
  62. if ((tty = info->tty)) {
  63. if (info->mcr & UART_MCR_RTS) {
  64. len = skb->len
  65. #ifdef CONFIG_ISDN_AUDIO
  66. + ISDN_AUDIO_SKB_DLECOUNT(skb)
  67. #endif
  68. ;
  69. c = tty_buffer_request_room(tty, len);
  70. if (c >= len) {
  71. #ifdef CONFIG_ISDN_AUDIO
  72. if (ISDN_AUDIO_SKB_DLECOUNT(skb)) {
  73. int l = skb->len;
  74. unsigned char *dp = skb->data;
  75. while (--l) {
  76. if (*dp == DLE)
  77. tty_insert_flip_char(tty, DLE, 0);
  78. tty_insert_flip_char(tty, *dp++, 0);
  79. }
  80. if (*dp == DLE)
  81. tty_insert_flip_char(tty, DLE, 0);
  82. last = *dp;
  83. } else {
  84. #endif
  85. if(len > 1)
  86. tty_insert_flip_string(tty, skb->data, len - 1);
  87. last = skb->data[len - 1];
  88. #ifdef CONFIG_ISDN_AUDIO
  89. }
  90. #endif
  91. if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP)
  92. tty_insert_flip_char(tty, last, 0xFF);
  93. else
  94. tty_insert_flip_char(tty, last, TTY_NORMAL);
  95. tty_flip_buffer_push(tty);
  96. kfree_skb(skb);
  97. return 1;
  98. }
  99. }
  100. }
  101. }
  102. return 0;
  103. }
  104. /* isdn_tty_readmodem() is called periodically from within timer-interrupt.
  105. * It tries getting received data from the receive queue an stuff it into
  106. * the tty's flip-buffer.
  107. */
  108. void
  109. isdn_tty_readmodem(void)
  110. {
  111. int resched = 0;
  112. int midx;
  113. int i;
  114. int r;
  115. struct tty_struct *tty;
  116. modem_info *info;
  117. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  118. if ((midx = dev->m_idx[i]) >= 0) {
  119. info = &dev->mdm.info[midx];
  120. if (info->online) {
  121. r = 0;
  122. #ifdef CONFIG_ISDN_AUDIO
  123. isdn_audio_eval_dtmf(info);
  124. if ((info->vonline & 1) && (info->emu.vpar[1]))
  125. isdn_audio_eval_silence(info);
  126. #endif
  127. if ((tty = info->tty)) {
  128. if (info->mcr & UART_MCR_RTS) {
  129. /* CISCO AsyncPPP Hack */
  130. if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
  131. r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0);
  132. else
  133. r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1);
  134. if (r)
  135. tty_flip_buffer_push(tty);
  136. } else
  137. r = 1;
  138. } else
  139. r = 1;
  140. if (r) {
  141. info->rcvsched = 0;
  142. resched = 1;
  143. } else
  144. info->rcvsched = 1;
  145. }
  146. }
  147. }
  148. if (!resched)
  149. isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0);
  150. }
  151. int
  152. isdn_tty_rcv_skb(int i, int di, int channel, struct sk_buff *skb)
  153. {
  154. ulong flags;
  155. int midx;
  156. #ifdef CONFIG_ISDN_AUDIO
  157. int ifmt;
  158. #endif
  159. modem_info *info;
  160. if ((midx = dev->m_idx[i]) < 0) {
  161. /* if midx is invalid, packet is not for tty */
  162. return 0;
  163. }
  164. info = &dev->mdm.info[midx];
  165. #ifdef CONFIG_ISDN_AUDIO
  166. ifmt = 1;
  167. if ((info->vonline) && (!info->emu.vpar[4]))
  168. isdn_audio_calc_dtmf(info, skb->data, skb->len, ifmt);
  169. if ((info->vonline & 1) && (info->emu.vpar[1]))
  170. isdn_audio_calc_silence(info, skb->data, skb->len, ifmt);
  171. #endif
  172. if ((info->online < 2)
  173. #ifdef CONFIG_ISDN_AUDIO
  174. && (!(info->vonline & 1))
  175. #endif
  176. ) {
  177. /* If Modem not listening, drop data */
  178. kfree_skb(skb);
  179. return 1;
  180. }
  181. if (info->emu.mdmreg[REG_T70] & BIT_T70) {
  182. if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT) {
  183. /* T.70 decoding: throw away the T.70 header (2 or 4 bytes) */
  184. if (skb->data[0] == 3) /* pure data packet -> 4 byte headers */
  185. skb_pull(skb, 4);
  186. else
  187. if (skb->data[0] == 1) /* keepalive packet -> 2 byte hdr */
  188. skb_pull(skb, 2);
  189. } else
  190. /* T.70 decoding: Simply throw away the T.70 header (4 bytes) */
  191. if ((skb->data[0] == 1) && ((skb->data[1] == 0) || (skb->data[1] == 1)))
  192. skb_pull(skb, 4);
  193. }
  194. #ifdef CONFIG_ISDN_AUDIO
  195. ISDN_AUDIO_SKB_DLECOUNT(skb) = 0;
  196. ISDN_AUDIO_SKB_LOCK(skb) = 0;
  197. if (info->vonline & 1) {
  198. /* voice conversion/compression */
  199. switch (info->emu.vpar[3]) {
  200. case 2:
  201. case 3:
  202. case 4:
  203. /* adpcm
  204. * Since compressed data takes less
  205. * space, we can overwrite the buffer.
  206. */
  207. skb_trim(skb, isdn_audio_xlaw2adpcm(info->adpcmr,
  208. ifmt,
  209. skb->data,
  210. skb->data,
  211. skb->len));
  212. break;
  213. case 5:
  214. /* a-law */
  215. if (!ifmt)
  216. isdn_audio_ulaw2alaw(skb->data, skb->len);
  217. break;
  218. case 6:
  219. /* u-law */
  220. if (ifmt)
  221. isdn_audio_alaw2ulaw(skb->data, skb->len);
  222. break;
  223. }
  224. ISDN_AUDIO_SKB_DLECOUNT(skb) =
  225. isdn_tty_countDLE(skb->data, skb->len);
  226. }
  227. #ifdef CONFIG_ISDN_TTY_FAX
  228. else {
  229. if (info->faxonline & 2) {
  230. isdn_tty_fax_bitorder(info, skb);
  231. ISDN_AUDIO_SKB_DLECOUNT(skb) =
  232. isdn_tty_countDLE(skb->data, skb->len);
  233. }
  234. }
  235. #endif
  236. #endif
  237. /* Try to deliver directly via tty-buf if queue is empty */
  238. spin_lock_irqsave(&info->readlock, flags);
  239. if (skb_queue_empty(&dev->drv[di]->rpqueue[channel]))
  240. if (isdn_tty_try_read(info, skb)) {
  241. spin_unlock_irqrestore(&info->readlock, flags);
  242. return 1;
  243. }
  244. /* Direct deliver failed or queue wasn't empty.
  245. * Queue up for later dequeueing via timer-irq.
  246. */
  247. __skb_queue_tail(&dev->drv[di]->rpqueue[channel], skb);
  248. dev->drv[di]->rcvcount[channel] +=
  249. (skb->len
  250. #ifdef CONFIG_ISDN_AUDIO
  251. + ISDN_AUDIO_SKB_DLECOUNT(skb)
  252. #endif
  253. );
  254. spin_unlock_irqrestore(&info->readlock, flags);
  255. /* Schedule dequeuing */
  256. if ((dev->modempoll) && (info->rcvsched))
  257. isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 1);
  258. return 1;
  259. }
  260. static void
  261. isdn_tty_cleanup_xmit(modem_info * info)
  262. {
  263. skb_queue_purge(&info->xmit_queue);
  264. #ifdef CONFIG_ISDN_AUDIO
  265. skb_queue_purge(&info->dtmf_queue);
  266. #endif
  267. }
  268. static void
  269. isdn_tty_tint(modem_info * info)
  270. {
  271. struct sk_buff *skb = skb_dequeue(&info->xmit_queue);
  272. int len, slen;
  273. if (!skb)
  274. return;
  275. len = skb->len;
  276. if ((slen = isdn_writebuf_skb_stub(info->isdn_driver,
  277. info->isdn_channel, 1, skb)) == len) {
  278. struct tty_struct *tty = info->tty;
  279. info->send_outstanding++;
  280. info->msr &= ~UART_MSR_CTS;
  281. info->lsr &= ~UART_LSR_TEMT;
  282. tty_wakeup(tty);
  283. return;
  284. }
  285. if (slen < 0) {
  286. /* Error: no channel, already shutdown, or wrong parameter */
  287. dev_kfree_skb(skb);
  288. return;
  289. }
  290. skb_queue_head(&info->xmit_queue, skb);
  291. }
  292. #ifdef CONFIG_ISDN_AUDIO
  293. static int
  294. isdn_tty_countDLE(unsigned char *buf, int len)
  295. {
  296. int count = 0;
  297. while (len--)
  298. if (*buf++ == DLE)
  299. count++;
  300. return count;
  301. }
  302. /* This routine is called from within isdn_tty_write() to perform
  303. * DLE-decoding when sending audio-data.
  304. */
  305. static int
  306. isdn_tty_handleDLEdown(modem_info * info, atemu * m, int len)
  307. {
  308. unsigned char *p = &info->xmit_buf[info->xmit_count];
  309. int count = 0;
  310. while (len > 0) {
  311. if (m->lastDLE) {
  312. m->lastDLE = 0;
  313. switch (*p) {
  314. case DLE:
  315. /* Escape code */
  316. if (len > 1)
  317. memmove(p, p + 1, len - 1);
  318. p--;
  319. count++;
  320. break;
  321. case ETX:
  322. /* End of data */
  323. info->vonline |= 4;
  324. return count;
  325. case DC4:
  326. /* Abort RX */
  327. info->vonline &= ~1;
  328. #ifdef ISDN_DEBUG_MODEM_VOICE
  329. printk(KERN_DEBUG
  330. "DLEdown: got DLE-DC4, send DLE-ETX on ttyI%d\n",
  331. info->line);
  332. #endif
  333. isdn_tty_at_cout("\020\003", info);
  334. if (!info->vonline) {
  335. #ifdef ISDN_DEBUG_MODEM_VOICE
  336. printk(KERN_DEBUG
  337. "DLEdown: send VCON on ttyI%d\n",
  338. info->line);
  339. #endif
  340. isdn_tty_at_cout("\r\nVCON\r\n", info);
  341. }
  342. /* Fall through */
  343. case 'q':
  344. case 's':
  345. /* Silence */
  346. if (len > 1)
  347. memmove(p, p + 1, len - 1);
  348. p--;
  349. break;
  350. }
  351. } else {
  352. if (*p == DLE)
  353. m->lastDLE = 1;
  354. else
  355. count++;
  356. }
  357. p++;
  358. len--;
  359. }
  360. if (len < 0) {
  361. printk(KERN_WARNING "isdn_tty: len<0 in DLEdown\n");
  362. return 0;
  363. }
  364. return count;
  365. }
  366. /* This routine is called from within isdn_tty_write() when receiving
  367. * audio-data. It interrupts receiving, if an character other than
  368. * ^S or ^Q is sent.
  369. */
  370. static int
  371. isdn_tty_end_vrx(const char *buf, int c)
  372. {
  373. char ch;
  374. while (c--) {
  375. ch = *buf;
  376. if ((ch != 0x11) && (ch != 0x13))
  377. return 1;
  378. buf++;
  379. }
  380. return 0;
  381. }
  382. static int voice_cf[7] =
  383. {0, 0, 4, 3, 2, 0, 0};
  384. #endif /* CONFIG_ISDN_AUDIO */
  385. /* isdn_tty_senddown() is called either directly from within isdn_tty_write()
  386. * or via timer-interrupt from within isdn_tty_modem_xmit(). It pulls
  387. * outgoing data from the tty's xmit-buffer, handles voice-decompression or
  388. * T.70 if necessary, and finally queues it up for sending via isdn_tty_tint.
  389. */
  390. static void
  391. isdn_tty_senddown(modem_info * info)
  392. {
  393. int buflen;
  394. int skb_res;
  395. #ifdef CONFIG_ISDN_AUDIO
  396. int audio_len;
  397. #endif
  398. struct sk_buff *skb;
  399. #ifdef CONFIG_ISDN_AUDIO
  400. if (info->vonline & 4) {
  401. info->vonline &= ~6;
  402. if (!info->vonline) {
  403. #ifdef ISDN_DEBUG_MODEM_VOICE
  404. printk(KERN_DEBUG
  405. "senddown: send VCON on ttyI%d\n",
  406. info->line);
  407. #endif
  408. isdn_tty_at_cout("\r\nVCON\r\n", info);
  409. }
  410. }
  411. #endif
  412. if (!(buflen = info->xmit_count))
  413. return;
  414. if ((info->emu.mdmreg[REG_CTS] & BIT_CTS) != 0)
  415. info->msr &= ~UART_MSR_CTS;
  416. info->lsr &= ~UART_LSR_TEMT;
  417. /* info->xmit_count is modified here and in isdn_tty_write().
  418. * So we return here if isdn_tty_write() is in the
  419. * critical section.
  420. */
  421. atomic_inc(&info->xmit_lock);
  422. if (!(atomic_dec_and_test(&info->xmit_lock)))
  423. return;
  424. if (info->isdn_driver < 0) {
  425. info->xmit_count = 0;
  426. return;
  427. }
  428. skb_res = dev->drv[info->isdn_driver]->interface->hl_hdrlen + 4;
  429. #ifdef CONFIG_ISDN_AUDIO
  430. if (info->vonline & 2)
  431. audio_len = buflen * voice_cf[info->emu.vpar[3]];
  432. else
  433. audio_len = 0;
  434. skb = dev_alloc_skb(skb_res + buflen + audio_len);
  435. #else
  436. skb = dev_alloc_skb(skb_res + buflen);
  437. #endif
  438. if (!skb) {
  439. printk(KERN_WARNING
  440. "isdn_tty: Out of memory in ttyI%d senddown\n",
  441. info->line);
  442. return;
  443. }
  444. skb_reserve(skb, skb_res);
  445. memcpy(skb_put(skb, buflen), info->xmit_buf, buflen);
  446. info->xmit_count = 0;
  447. #ifdef CONFIG_ISDN_AUDIO
  448. if (info->vonline & 2) {
  449. /* For now, ifmt is fixed to 1 (alaw), since this
  450. * is used with ISDN everywhere in the world, except
  451. * US, Canada and Japan.
  452. * Later, when US-ISDN protocols are implemented,
  453. * this setting will depend on the D-channel protocol.
  454. */
  455. int ifmt = 1;
  456. /* voice conversion/decompression */
  457. switch (info->emu.vpar[3]) {
  458. case 2:
  459. case 3:
  460. case 4:
  461. /* adpcm, compatible to ZyXel 1496 modem
  462. * with ROM revision 6.01
  463. */
  464. audio_len = isdn_audio_adpcm2xlaw(info->adpcms,
  465. ifmt,
  466. skb->data,
  467. skb_put(skb, audio_len),
  468. buflen);
  469. skb_pull(skb, buflen);
  470. skb_trim(skb, audio_len);
  471. break;
  472. case 5:
  473. /* a-law */
  474. if (!ifmt)
  475. isdn_audio_alaw2ulaw(skb->data,
  476. buflen);
  477. break;
  478. case 6:
  479. /* u-law */
  480. if (ifmt)
  481. isdn_audio_ulaw2alaw(skb->data,
  482. buflen);
  483. break;
  484. }
  485. }
  486. #endif /* CONFIG_ISDN_AUDIO */
  487. if (info->emu.mdmreg[REG_T70] & BIT_T70) {
  488. /* Add T.70 simplified header */
  489. if (info->emu.mdmreg[REG_T70] & BIT_T70_EXT)
  490. memcpy(skb_push(skb, 2), "\1\0", 2);
  491. else
  492. memcpy(skb_push(skb, 4), "\1\0\1\0", 4);
  493. }
  494. skb_queue_tail(&info->xmit_queue, skb);
  495. }
  496. /************************************************************
  497. *
  498. * Modem-functions
  499. *
  500. * mostly "stolen" from original Linux-serial.c and friends.
  501. *
  502. ************************************************************/
  503. /* The next routine is called once from within timer-interrupt
  504. * triggered within isdn_tty_modem_ncarrier(). It calls
  505. * isdn_tty_modem_result() to stuff a "NO CARRIER" Message
  506. * into the tty's buffer.
  507. */
  508. static void
  509. isdn_tty_modem_do_ncarrier(unsigned long data)
  510. {
  511. modem_info *info = (modem_info *) data;
  512. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  513. }
  514. /* Next routine is called, whenever the DTR-signal is raised.
  515. * It checks the ncarrier-flag, and triggers the above routine
  516. * when necessary. The ncarrier-flag is set, whenever DTR goes
  517. * low.
  518. */
  519. static void
  520. isdn_tty_modem_ncarrier(modem_info * info)
  521. {
  522. if (info->ncarrier) {
  523. info->nc_timer.expires = jiffies + HZ;
  524. add_timer(&info->nc_timer);
  525. }
  526. }
  527. /*
  528. * return the usage calculated by si and layer 2 protocol
  529. */
  530. static int
  531. isdn_calc_usage(int si, int l2)
  532. {
  533. int usg = ISDN_USAGE_MODEM;
  534. #ifdef CONFIG_ISDN_AUDIO
  535. if (si == 1) {
  536. switch(l2) {
  537. case ISDN_PROTO_L2_MODEM:
  538. usg = ISDN_USAGE_MODEM;
  539. break;
  540. #ifdef CONFIG_ISDN_TTY_FAX
  541. case ISDN_PROTO_L2_FAX:
  542. usg = ISDN_USAGE_FAX;
  543. break;
  544. #endif
  545. case ISDN_PROTO_L2_TRANS:
  546. default:
  547. usg = ISDN_USAGE_VOICE;
  548. break;
  549. }
  550. }
  551. #endif
  552. return(usg);
  553. }
  554. /* isdn_tty_dial() performs dialing of a tty an the necessary
  555. * setup of the lower levels before that.
  556. */
  557. static void
  558. isdn_tty_dial(char *n, modem_info * info, atemu * m)
  559. {
  560. int usg = ISDN_USAGE_MODEM;
  561. int si = 7;
  562. int l2 = m->mdmreg[REG_L2PROT];
  563. u_long flags;
  564. isdn_ctrl cmd;
  565. int i;
  566. int j;
  567. for (j = 7; j >= 0; j--)
  568. if (m->mdmreg[REG_SI1] & (1 << j)) {
  569. si = bit2si[j];
  570. break;
  571. }
  572. usg = isdn_calc_usage(si, l2);
  573. #ifdef CONFIG_ISDN_AUDIO
  574. if ((si == 1) &&
  575. (l2 != ISDN_PROTO_L2_MODEM)
  576. #ifdef CONFIG_ISDN_TTY_FAX
  577. && (l2 != ISDN_PROTO_L2_FAX)
  578. #endif
  579. ) {
  580. l2 = ISDN_PROTO_L2_TRANS;
  581. usg = ISDN_USAGE_VOICE;
  582. }
  583. #endif
  584. m->mdmreg[REG_SI1I] = si2bit[si];
  585. spin_lock_irqsave(&dev->lock, flags);
  586. i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
  587. if (i < 0) {
  588. spin_unlock_irqrestore(&dev->lock, flags);
  589. isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
  590. } else {
  591. info->isdn_driver = dev->drvmap[i];
  592. info->isdn_channel = dev->chanmap[i];
  593. info->drv_index = i;
  594. dev->m_idx[i] = info->line;
  595. dev->usage[i] |= ISDN_USAGE_OUTGOING;
  596. info->last_dir = 1;
  597. strcpy(info->last_num, n);
  598. isdn_info_update();
  599. spin_unlock_irqrestore(&dev->lock, flags);
  600. cmd.driver = info->isdn_driver;
  601. cmd.arg = info->isdn_channel;
  602. cmd.command = ISDN_CMD_CLREAZ;
  603. isdn_command(&cmd);
  604. strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
  605. cmd.driver = info->isdn_driver;
  606. cmd.command = ISDN_CMD_SETEAZ;
  607. isdn_command(&cmd);
  608. cmd.driver = info->isdn_driver;
  609. cmd.command = ISDN_CMD_SETL2;
  610. info->last_l2 = l2;
  611. cmd.arg = info->isdn_channel + (l2 << 8);
  612. isdn_command(&cmd);
  613. cmd.driver = info->isdn_driver;
  614. cmd.command = ISDN_CMD_SETL3;
  615. cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
  616. #ifdef CONFIG_ISDN_TTY_FAX
  617. if (l2 == ISDN_PROTO_L2_FAX) {
  618. cmd.parm.fax = info->fax;
  619. info->fax->direction = ISDN_TTY_FAX_CONN_OUT;
  620. }
  621. #endif
  622. isdn_command(&cmd);
  623. cmd.driver = info->isdn_driver;
  624. cmd.arg = info->isdn_channel;
  625. sprintf(cmd.parm.setup.phone, "%s", n);
  626. sprintf(cmd.parm.setup.eazmsn, "%s",
  627. isdn_map_eaz2msn(m->msn, info->isdn_driver));
  628. cmd.parm.setup.si1 = si;
  629. cmd.parm.setup.si2 = m->mdmreg[REG_SI2];
  630. cmd.command = ISDN_CMD_DIAL;
  631. info->dialing = 1;
  632. info->emu.carrierwait = 0;
  633. strcpy(dev->num[i], n);
  634. isdn_info_update();
  635. isdn_command(&cmd);
  636. isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
  637. }
  638. }
  639. /* isdn_tty_hangup() disassociates a tty from the real
  640. * ISDN-line (hangup). The usage-status is cleared
  641. * and some cleanup is done also.
  642. */
  643. void
  644. isdn_tty_modem_hup(modem_info * info, int local)
  645. {
  646. isdn_ctrl cmd;
  647. int di, ch;
  648. if (!info)
  649. return;
  650. di = info->isdn_driver;
  651. ch = info->isdn_channel;
  652. if (di < 0 || ch < 0)
  653. return;
  654. info->isdn_driver = -1;
  655. info->isdn_channel = -1;
  656. #ifdef ISDN_DEBUG_MODEM_HUP
  657. printk(KERN_DEBUG "Mhup ttyI%d\n", info->line);
  658. #endif
  659. info->rcvsched = 0;
  660. isdn_tty_flush_buffer(info->tty);
  661. if (info->online) {
  662. info->last_lhup = local;
  663. info->online = 0;
  664. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  665. }
  666. #ifdef CONFIG_ISDN_AUDIO
  667. info->vonline = 0;
  668. #ifdef CONFIG_ISDN_TTY_FAX
  669. info->faxonline = 0;
  670. info->fax->phase = ISDN_FAX_PHASE_IDLE;
  671. #endif
  672. info->emu.vpar[4] = 0;
  673. info->emu.vpar[5] = 8;
  674. kfree(info->dtmf_state);
  675. info->dtmf_state = NULL;
  676. kfree(info->silence_state);
  677. info->silence_state = NULL;
  678. kfree(info->adpcms);
  679. info->adpcms = NULL;
  680. kfree(info->adpcmr);
  681. info->adpcmr = NULL;
  682. #endif
  683. if ((info->msr & UART_MSR_RI) &&
  684. (info->emu.mdmreg[REG_RUNG] & BIT_RUNG))
  685. isdn_tty_modem_result(RESULT_RUNG, info);
  686. info->msr &= ~(UART_MSR_DCD | UART_MSR_RI);
  687. info->lsr |= UART_LSR_TEMT;
  688. if (local) {
  689. cmd.driver = di;
  690. cmd.command = ISDN_CMD_HANGUP;
  691. cmd.arg = ch;
  692. isdn_command(&cmd);
  693. }
  694. isdn_all_eaz(di, ch);
  695. info->emu.mdmreg[REG_RINGCNT] = 0;
  696. isdn_free_channel(di, ch, 0);
  697. if (info->drv_index >= 0) {
  698. dev->m_idx[info->drv_index] = -1;
  699. info->drv_index = -1;
  700. }
  701. }
  702. /*
  703. * Begin of a CAPI like interface, currently used only for
  704. * supplementary service (CAPI 2.0 part III)
  705. */
  706. #include <linux/isdn/capicmd.h>
  707. #include <linux/module.h>
  708. int
  709. isdn_tty_capi_facility(capi_msg *cm) {
  710. return(-1); /* dummy */
  711. }
  712. /* isdn_tty_suspend() tries to suspend the current tty connection
  713. */
  714. static void
  715. isdn_tty_suspend(char *id, modem_info * info, atemu * m)
  716. {
  717. isdn_ctrl cmd;
  718. int l;
  719. if (!info)
  720. return;
  721. #ifdef ISDN_DEBUG_MODEM_SERVICES
  722. printk(KERN_DEBUG "Msusp ttyI%d\n", info->line);
  723. #endif
  724. l = strlen(id);
  725. if ((info->isdn_driver >= 0)) {
  726. cmd.parm.cmsg.Length = l+18;
  727. cmd.parm.cmsg.Command = CAPI_FACILITY;
  728. cmd.parm.cmsg.Subcommand = CAPI_REQ;
  729. cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
  730. cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
  731. cmd.parm.cmsg.para[1] = 0;
  732. cmd.parm.cmsg.para[2] = l + 3;
  733. cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */
  734. cmd.parm.cmsg.para[4] = 0;
  735. cmd.parm.cmsg.para[5] = l;
  736. strncpy(&cmd.parm.cmsg.para[6], id, l);
  737. cmd.command = CAPI_PUT_MESSAGE;
  738. cmd.driver = info->isdn_driver;
  739. cmd.arg = info->isdn_channel;
  740. isdn_command(&cmd);
  741. }
  742. }
  743. /* isdn_tty_resume() tries to resume a suspended call
  744. * setup of the lower levels before that. unfortunately here is no
  745. * checking for compatibility of used protocols implemented by Q931
  746. * It does the same things like isdn_tty_dial, the last command
  747. * is different, may be we can merge it.
  748. */
  749. static void
  750. isdn_tty_resume(char *id, modem_info * info, atemu * m)
  751. {
  752. int usg = ISDN_USAGE_MODEM;
  753. int si = 7;
  754. int l2 = m->mdmreg[REG_L2PROT];
  755. isdn_ctrl cmd;
  756. ulong flags;
  757. int i;
  758. int j;
  759. int l;
  760. l = strlen(id);
  761. for (j = 7; j >= 0; j--)
  762. if (m->mdmreg[REG_SI1] & (1 << j)) {
  763. si = bit2si[j];
  764. break;
  765. }
  766. usg = isdn_calc_usage(si, l2);
  767. #ifdef CONFIG_ISDN_AUDIO
  768. if ((si == 1) &&
  769. (l2 != ISDN_PROTO_L2_MODEM)
  770. #ifdef CONFIG_ISDN_TTY_FAX
  771. && (l2 != ISDN_PROTO_L2_FAX)
  772. #endif
  773. ) {
  774. l2 = ISDN_PROTO_L2_TRANS;
  775. usg = ISDN_USAGE_VOICE;
  776. }
  777. #endif
  778. m->mdmreg[REG_SI1I] = si2bit[si];
  779. spin_lock_irqsave(&dev->lock, flags);
  780. i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
  781. if (i < 0) {
  782. spin_unlock_irqrestore(&dev->lock, flags);
  783. isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
  784. } else {
  785. info->isdn_driver = dev->drvmap[i];
  786. info->isdn_channel = dev->chanmap[i];
  787. info->drv_index = i;
  788. dev->m_idx[i] = info->line;
  789. dev->usage[i] |= ISDN_USAGE_OUTGOING;
  790. info->last_dir = 1;
  791. // strcpy(info->last_num, n);
  792. isdn_info_update();
  793. spin_unlock_irqrestore(&dev->lock, flags);
  794. cmd.driver = info->isdn_driver;
  795. cmd.arg = info->isdn_channel;
  796. cmd.command = ISDN_CMD_CLREAZ;
  797. isdn_command(&cmd);
  798. strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
  799. cmd.driver = info->isdn_driver;
  800. cmd.command = ISDN_CMD_SETEAZ;
  801. isdn_command(&cmd);
  802. cmd.driver = info->isdn_driver;
  803. cmd.command = ISDN_CMD_SETL2;
  804. info->last_l2 = l2;
  805. cmd.arg = info->isdn_channel + (l2 << 8);
  806. isdn_command(&cmd);
  807. cmd.driver = info->isdn_driver;
  808. cmd.command = ISDN_CMD_SETL3;
  809. cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
  810. isdn_command(&cmd);
  811. cmd.driver = info->isdn_driver;
  812. cmd.arg = info->isdn_channel;
  813. cmd.parm.cmsg.Length = l+18;
  814. cmd.parm.cmsg.Command = CAPI_FACILITY;
  815. cmd.parm.cmsg.Subcommand = CAPI_REQ;
  816. cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
  817. cmd.parm.cmsg.para[0] = 3; /* 16 bit 0x0003 suplementary service */
  818. cmd.parm.cmsg.para[1] = 0;
  819. cmd.parm.cmsg.para[2] = l+3;
  820. cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */
  821. cmd.parm.cmsg.para[4] = 0;
  822. cmd.parm.cmsg.para[5] = l;
  823. strncpy(&cmd.parm.cmsg.para[6], id, l);
  824. cmd.command =CAPI_PUT_MESSAGE;
  825. info->dialing = 1;
  826. // strcpy(dev->num[i], n);
  827. isdn_info_update();
  828. isdn_command(&cmd);
  829. isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
  830. }
  831. }
  832. /* isdn_tty_send_msg() sends a message to a HL driver
  833. * This is used for hybrid modem cards to send AT commands to it
  834. */
  835. static void
  836. isdn_tty_send_msg(modem_info * info, atemu * m, char *msg)
  837. {
  838. int usg = ISDN_USAGE_MODEM;
  839. int si = 7;
  840. int l2 = m->mdmreg[REG_L2PROT];
  841. isdn_ctrl cmd;
  842. ulong flags;
  843. int i;
  844. int j;
  845. int l;
  846. l = strlen(msg);
  847. if (!l) {
  848. isdn_tty_modem_result(RESULT_ERROR, info);
  849. return;
  850. }
  851. for (j = 7; j >= 0; j--)
  852. if (m->mdmreg[REG_SI1] & (1 << j)) {
  853. si = bit2si[j];
  854. break;
  855. }
  856. usg = isdn_calc_usage(si, l2);
  857. #ifdef CONFIG_ISDN_AUDIO
  858. if ((si == 1) &&
  859. (l2 != ISDN_PROTO_L2_MODEM)
  860. #ifdef CONFIG_ISDN_TTY_FAX
  861. && (l2 != ISDN_PROTO_L2_FAX)
  862. #endif
  863. ) {
  864. l2 = ISDN_PROTO_L2_TRANS;
  865. usg = ISDN_USAGE_VOICE;
  866. }
  867. #endif
  868. m->mdmreg[REG_SI1I] = si2bit[si];
  869. spin_lock_irqsave(&dev->lock, flags);
  870. i = isdn_get_free_channel(usg, l2, m->mdmreg[REG_L3PROT], -1, -1, m->msn);
  871. if (i < 0) {
  872. spin_unlock_irqrestore(&dev->lock, flags);
  873. isdn_tty_modem_result(RESULT_NO_DIALTONE, info);
  874. } else {
  875. info->isdn_driver = dev->drvmap[i];
  876. info->isdn_channel = dev->chanmap[i];
  877. info->drv_index = i;
  878. dev->m_idx[i] = info->line;
  879. dev->usage[i] |= ISDN_USAGE_OUTGOING;
  880. info->last_dir = 1;
  881. isdn_info_update();
  882. spin_unlock_irqrestore(&dev->lock, flags);
  883. cmd.driver = info->isdn_driver;
  884. cmd.arg = info->isdn_channel;
  885. cmd.command = ISDN_CMD_CLREAZ;
  886. isdn_command(&cmd);
  887. strcpy(cmd.parm.num, isdn_map_eaz2msn(m->msn, info->isdn_driver));
  888. cmd.driver = info->isdn_driver;
  889. cmd.command = ISDN_CMD_SETEAZ;
  890. isdn_command(&cmd);
  891. cmd.driver = info->isdn_driver;
  892. cmd.command = ISDN_CMD_SETL2;
  893. info->last_l2 = l2;
  894. cmd.arg = info->isdn_channel + (l2 << 8);
  895. isdn_command(&cmd);
  896. cmd.driver = info->isdn_driver;
  897. cmd.command = ISDN_CMD_SETL3;
  898. cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
  899. isdn_command(&cmd);
  900. cmd.driver = info->isdn_driver;
  901. cmd.arg = info->isdn_channel;
  902. cmd.parm.cmsg.Length = l+14;
  903. cmd.parm.cmsg.Command = CAPI_MANUFACTURER;
  904. cmd.parm.cmsg.Subcommand = CAPI_REQ;
  905. cmd.parm.cmsg.adr.Controller = info->isdn_driver + 1;
  906. cmd.parm.cmsg.para[0] = l+1;
  907. strncpy(&cmd.parm.cmsg.para[1], msg, l);
  908. cmd.parm.cmsg.para[l+1] = 0xd;
  909. cmd.command =CAPI_PUT_MESSAGE;
  910. /* info->dialing = 1;
  911. strcpy(dev->num[i], n);
  912. isdn_info_update();
  913. */
  914. isdn_command(&cmd);
  915. }
  916. }
  917. static inline int
  918. isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine)
  919. {
  920. #ifdef MODEM_PARANOIA_CHECK
  921. if (!info) {
  922. printk(KERN_WARNING "isdn_tty: null info_struct for %s in %s\n",
  923. name, routine);
  924. return 1;
  925. }
  926. if (info->magic != ISDN_ASYNC_MAGIC) {
  927. printk(KERN_WARNING "isdn_tty: bad magic for modem struct %s in %s\n",
  928. name, routine);
  929. return 1;
  930. }
  931. #endif
  932. return 0;
  933. }
  934. /*
  935. * This routine is called to set the UART divisor registers to match
  936. * the specified baud rate for a serial port.
  937. */
  938. static void
  939. isdn_tty_change_speed(modem_info * info)
  940. {
  941. uint cflag,
  942. cval,
  943. quot;
  944. int i;
  945. if (!info->tty || !info->tty->termios)
  946. return;
  947. cflag = info->tty->termios->c_cflag;
  948. quot = i = cflag & CBAUD;
  949. if (i & CBAUDEX) {
  950. i &= ~CBAUDEX;
  951. if (i < 1 || i > 2)
  952. info->tty->termios->c_cflag &= ~CBAUDEX;
  953. else
  954. i += 15;
  955. }
  956. if (quot) {
  957. info->mcr |= UART_MCR_DTR;
  958. isdn_tty_modem_ncarrier(info);
  959. } else {
  960. info->mcr &= ~UART_MCR_DTR;
  961. if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
  962. #ifdef ISDN_DEBUG_MODEM_HUP
  963. printk(KERN_DEBUG "Mhup in changespeed\n");
  964. #endif
  965. if (info->online)
  966. info->ncarrier = 1;
  967. isdn_tty_modem_reset_regs(info, 0);
  968. isdn_tty_modem_hup(info, 1);
  969. }
  970. return;
  971. }
  972. /* byte size and parity */
  973. cval = cflag & (CSIZE | CSTOPB);
  974. cval >>= 4;
  975. if (cflag & PARENB)
  976. cval |= UART_LCR_PARITY;
  977. if (!(cflag & PARODD))
  978. cval |= UART_LCR_EPAR;
  979. /* CTS flow control flag and modem status interrupts */
  980. if (cflag & CRTSCTS) {
  981. info->flags |= ISDN_ASYNC_CTS_FLOW;
  982. } else
  983. info->flags &= ~ISDN_ASYNC_CTS_FLOW;
  984. if (cflag & CLOCAL)
  985. info->flags &= ~ISDN_ASYNC_CHECK_CD;
  986. else {
  987. info->flags |= ISDN_ASYNC_CHECK_CD;
  988. }
  989. }
  990. static int
  991. isdn_tty_startup(modem_info * info)
  992. {
  993. if (info->flags & ISDN_ASYNC_INITIALIZED)
  994. return 0;
  995. isdn_lock_drivers();
  996. #ifdef ISDN_DEBUG_MODEM_OPEN
  997. printk(KERN_DEBUG "starting up ttyi%d ...\n", info->line);
  998. #endif
  999. /*
  1000. * Now, initialize the UART
  1001. */
  1002. info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
  1003. if (info->tty)
  1004. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  1005. /*
  1006. * and set the speed of the serial port
  1007. */
  1008. isdn_tty_change_speed(info);
  1009. info->flags |= ISDN_ASYNC_INITIALIZED;
  1010. info->msr |= (UART_MSR_DSR | UART_MSR_CTS);
  1011. info->send_outstanding = 0;
  1012. return 0;
  1013. }
  1014. /*
  1015. * This routine will shutdown a serial port; interrupts are disabled, and
  1016. * DTR is dropped if the hangup on close termio flag is on.
  1017. */
  1018. static void
  1019. isdn_tty_shutdown(modem_info * info)
  1020. {
  1021. if (!(info->flags & ISDN_ASYNC_INITIALIZED))
  1022. return;
  1023. #ifdef ISDN_DEBUG_MODEM_OPEN
  1024. printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line);
  1025. #endif
  1026. isdn_unlock_drivers();
  1027. info->msr &= ~UART_MSR_RI;
  1028. if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
  1029. info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
  1030. if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
  1031. isdn_tty_modem_reset_regs(info, 0);
  1032. #ifdef ISDN_DEBUG_MODEM_HUP
  1033. printk(KERN_DEBUG "Mhup in isdn_tty_shutdown\n");
  1034. #endif
  1035. isdn_tty_modem_hup(info, 1);
  1036. }
  1037. }
  1038. if (info->tty)
  1039. set_bit(TTY_IO_ERROR, &info->tty->flags);
  1040. info->flags &= ~ISDN_ASYNC_INITIALIZED;
  1041. }
  1042. /* isdn_tty_write() is the main send-routine. It is called from the upper
  1043. * levels within the kernel to perform sending data. Depending on the
  1044. * online-flag it either directs output to the at-command-interpreter or
  1045. * to the lower level. Additional tasks done here:
  1046. * - If online, check for escape-sequence (+++)
  1047. * - If sending audio-data, call isdn_tty_DLEdown() to parse DLE-codes.
  1048. * - If receiving audio-data, call isdn_tty_end_vrx() to abort if needed.
  1049. * - If dialing, abort dial.
  1050. */
  1051. static int
  1052. isdn_tty_write(struct tty_struct *tty, const u_char * buf, int count)
  1053. {
  1054. int c;
  1055. int total = 0;
  1056. modem_info *info = (modem_info *) tty->driver_data;
  1057. atemu *m = &info->emu;
  1058. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write"))
  1059. return 0;
  1060. /* See isdn_tty_senddown() */
  1061. atomic_inc(&info->xmit_lock);
  1062. while (1) {
  1063. c = count;
  1064. if (c > info->xmit_size - info->xmit_count)
  1065. c = info->xmit_size - info->xmit_count;
  1066. if (info->isdn_driver >= 0 && c > dev->drv[info->isdn_driver]->maxbufsize)
  1067. c = dev->drv[info->isdn_driver]->maxbufsize;
  1068. if (c <= 0)
  1069. break;
  1070. if ((info->online > 1)
  1071. #ifdef CONFIG_ISDN_AUDIO
  1072. || (info->vonline & 3)
  1073. #endif
  1074. ) {
  1075. #ifdef CONFIG_ISDN_AUDIO
  1076. if (!info->vonline)
  1077. #endif
  1078. isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c,
  1079. &(m->pluscount),
  1080. &(m->lastplus));
  1081. memcpy(&(info->xmit_buf[info->xmit_count]), buf, c);
  1082. #ifdef CONFIG_ISDN_AUDIO
  1083. if (info->vonline) {
  1084. int cc = isdn_tty_handleDLEdown(info, m, c);
  1085. if (info->vonline & 2) {
  1086. if (!cc) {
  1087. /* If DLE decoding results in zero-transmit, but
  1088. * c originally was non-zero, do a wakeup.
  1089. */
  1090. tty_wakeup(tty);
  1091. info->msr |= UART_MSR_CTS;
  1092. info->lsr |= UART_LSR_TEMT;
  1093. }
  1094. info->xmit_count += cc;
  1095. }
  1096. if ((info->vonline & 3) == 1) {
  1097. /* Do NOT handle Ctrl-Q or Ctrl-S
  1098. * when in full-duplex audio mode.
  1099. */
  1100. if (isdn_tty_end_vrx(buf, c)) {
  1101. info->vonline &= ~1;
  1102. #ifdef ISDN_DEBUG_MODEM_VOICE
  1103. printk(KERN_DEBUG
  1104. "got !^Q/^S, send DLE-ETX,VCON on ttyI%d\n",
  1105. info->line);
  1106. #endif
  1107. isdn_tty_at_cout("\020\003\r\nVCON\r\n", info);
  1108. }
  1109. }
  1110. } else
  1111. if (TTY_IS_FCLASS1(info)) {
  1112. int cc = isdn_tty_handleDLEdown(info, m, c);
  1113. if (info->vonline & 4) { /* ETX seen */
  1114. isdn_ctrl c;
  1115. c.command = ISDN_CMD_FAXCMD;
  1116. c.driver = info->isdn_driver;
  1117. c.arg = info->isdn_channel;
  1118. c.parm.aux.cmd = ISDN_FAX_CLASS1_CTRL;
  1119. c.parm.aux.subcmd = ETX;
  1120. isdn_command(&c);
  1121. }
  1122. info->vonline = 0;
  1123. #ifdef ISDN_DEBUG_MODEM_VOICE
  1124. printk(KERN_DEBUG "fax dle cc/c %d/%d\n", cc, c);
  1125. #endif
  1126. info->xmit_count += cc;
  1127. } else
  1128. #endif
  1129. info->xmit_count += c;
  1130. } else {
  1131. info->msr |= UART_MSR_CTS;
  1132. info->lsr |= UART_LSR_TEMT;
  1133. if (info->dialing) {
  1134. info->dialing = 0;
  1135. #ifdef ISDN_DEBUG_MODEM_HUP
  1136. printk(KERN_DEBUG "Mhup in isdn_tty_write\n");
  1137. #endif
  1138. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  1139. isdn_tty_modem_hup(info, 1);
  1140. } else
  1141. c = isdn_tty_edit_at(buf, c, info);
  1142. }
  1143. buf += c;
  1144. count -= c;
  1145. total += c;
  1146. }
  1147. atomic_dec(&info->xmit_lock);
  1148. if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue)) {
  1149. if (m->mdmreg[REG_DXMT] & BIT_DXMT) {
  1150. isdn_tty_senddown(info);
  1151. isdn_tty_tint(info);
  1152. }
  1153. isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
  1154. }
  1155. return total;
  1156. }
  1157. static int
  1158. isdn_tty_write_room(struct tty_struct *tty)
  1159. {
  1160. modem_info *info = (modem_info *) tty->driver_data;
  1161. int ret;
  1162. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_write_room"))
  1163. return 0;
  1164. if (!info->online)
  1165. return info->xmit_size;
  1166. ret = info->xmit_size - info->xmit_count;
  1167. return (ret < 0) ? 0 : ret;
  1168. }
  1169. static int
  1170. isdn_tty_chars_in_buffer(struct tty_struct *tty)
  1171. {
  1172. modem_info *info = (modem_info *) tty->driver_data;
  1173. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_chars_in_buffer"))
  1174. return 0;
  1175. if (!info->online)
  1176. return 0;
  1177. return (info->xmit_count);
  1178. }
  1179. static void
  1180. isdn_tty_flush_buffer(struct tty_struct *tty)
  1181. {
  1182. modem_info *info;
  1183. if (!tty) {
  1184. return;
  1185. }
  1186. info = (modem_info *) tty->driver_data;
  1187. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_buffer")) {
  1188. return;
  1189. }
  1190. isdn_tty_cleanup_xmit(info);
  1191. info->xmit_count = 0;
  1192. tty_wakeup(tty);
  1193. }
  1194. static void
  1195. isdn_tty_flush_chars(struct tty_struct *tty)
  1196. {
  1197. modem_info *info = (modem_info *) tty->driver_data;
  1198. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_flush_chars"))
  1199. return;
  1200. if ((info->xmit_count) || !skb_queue_empty(&info->xmit_queue))
  1201. isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, 1);
  1202. }
  1203. /*
  1204. * ------------------------------------------------------------
  1205. * isdn_tty_throttle()
  1206. *
  1207. * This routine is called by the upper-layer tty layer to signal that
  1208. * incoming characters should be throttled.
  1209. * ------------------------------------------------------------
  1210. */
  1211. static void
  1212. isdn_tty_throttle(struct tty_struct *tty)
  1213. {
  1214. modem_info *info = (modem_info *) tty->driver_data;
  1215. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_throttle"))
  1216. return;
  1217. if (I_IXOFF(tty))
  1218. info->x_char = STOP_CHAR(tty);
  1219. info->mcr &= ~UART_MCR_RTS;
  1220. }
  1221. static void
  1222. isdn_tty_unthrottle(struct tty_struct *tty)
  1223. {
  1224. modem_info *info = (modem_info *) tty->driver_data;
  1225. if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_unthrottle"))
  1226. return;
  1227. if (I_IXOFF(tty)) {
  1228. if (info->x_char)
  1229. info->x_char = 0;
  1230. else
  1231. info->x_char = START_CHAR(tty);
  1232. }
  1233. info->mcr |= UART_MCR_RTS;
  1234. }
  1235. /*
  1236. * ------------------------------------------------------------
  1237. * isdn_tty_ioctl() and friends
  1238. * ------------------------------------------------------------
  1239. */
  1240. /*
  1241. * isdn_tty_get_lsr_info - get line status register info
  1242. *
  1243. * Purpose: Let user call ioctl() to get info when the UART physically
  1244. * is emptied. On bus types like RS485, the transmitter must
  1245. * release the bus after transmitting. This must be done when
  1246. * the transmit shift register is empty, not be done when the
  1247. * transmit holding register is empty. This functionality
  1248. * allows RS485 driver to be written in user space.
  1249. */
  1250. static int
  1251. isdn_tty_get_lsr_info(modem_info * info, uint __user * value)
  1252. {
  1253. u_char status;
  1254. uint result;
  1255. status = info->lsr;
  1256. result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
  1257. return put_user(result, value);
  1258. }
  1259. static int
  1260. isdn_tty_tiocmget(struct tty_struct *tty)
  1261. {
  1262. modem_info *info = (modem_info *) tty->driver_data;
  1263. u_char control, status;
  1264. if (isdn_tty_paranoia_check(info, tty->name, __func__))
  1265. return -ENODEV;
  1266. if (tty->flags & (1 << TTY_IO_ERROR))
  1267. return -EIO;
  1268. mutex_lock(&modem_info_mutex);
  1269. #ifdef ISDN_DEBUG_MODEM_IOCTL
  1270. printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line);
  1271. #endif
  1272. control = info->mcr;
  1273. status = info->msr;
  1274. mutex_unlock(&modem_info_mutex);
  1275. return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
  1276. | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
  1277. | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
  1278. | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
  1279. | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
  1280. | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
  1281. }
  1282. static int
  1283. isdn_tty_tiocmset(struct tty_struct *tty,
  1284. unsigned int set, unsigned int clear)
  1285. {
  1286. modem_info *info = (modem_info *) tty->driver_data;
  1287. if (isdn_tty_paranoia_check(info, tty->name, __func__))
  1288. return -ENODEV;
  1289. if (tty->flags & (1 << TTY_IO_ERROR))
  1290. return -EIO;
  1291. #ifdef ISDN_DEBUG_MODEM_IOCTL
  1292. printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear);
  1293. #endif
  1294. mutex_lock(&modem_info_mutex);
  1295. if (set & TIOCM_RTS)
  1296. info->mcr |= UART_MCR_RTS;
  1297. if (set & TIOCM_DTR) {
  1298. info->mcr |= UART_MCR_DTR;
  1299. isdn_tty_modem_ncarrier(info);
  1300. }
  1301. if (clear & TIOCM_RTS)
  1302. info->mcr &= ~UART_MCR_RTS;
  1303. if (clear & TIOCM_DTR) {
  1304. info->mcr &= ~UART_MCR_DTR;
  1305. if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
  1306. isdn_tty_modem_reset_regs(info, 0);
  1307. #ifdef ISDN_DEBUG_MODEM_HUP
  1308. printk(KERN_DEBUG "Mhup in TIOCMSET\n");
  1309. #endif
  1310. if (info->online)
  1311. info->ncarrier = 1;
  1312. isdn_tty_modem_hup(info, 1);
  1313. }
  1314. }
  1315. mutex_unlock(&modem_info_mutex);
  1316. return 0;
  1317. }
  1318. static int
  1319. isdn_tty_ioctl(struct tty_struct *tty, 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_from_close(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. if ((info->flags & ISDN_ASYNC_CHECK_CD) &&
  2490. (!((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
  2491. (info->flags & ISDN_ASYNC_CALLOUT_NOHUP)))) {
  2492. tty_hangup(info->tty);
  2493. }
  2494. }
  2495. }
  2496. /*
  2497. * Display a modem-register-value.
  2498. */
  2499. static void
  2500. isdn_tty_show_profile(int ridx, modem_info * info)
  2501. {
  2502. char v[6];
  2503. sprintf(v, "\r\n%d", info->emu.mdmreg[ridx]);
  2504. isdn_tty_at_cout(v, info);
  2505. }
  2506. /*
  2507. * Get MSN-string from char-pointer, set pointer to end of number
  2508. */
  2509. static void
  2510. isdn_tty_get_msnstr(char *n, char **p)
  2511. {
  2512. int limit = ISDN_MSNLEN - 1;
  2513. while (((*p[0] >= '0' && *p[0] <= '9') ||
  2514. /* Why a comma ??? */
  2515. (*p[0] == ',') || (*p[0] == ':')) &&
  2516. (limit--))
  2517. *n++ = *p[0]++;
  2518. *n = '\0';
  2519. }
  2520. /*
  2521. * Get phone-number from modem-commandbuffer
  2522. */
  2523. static void
  2524. isdn_tty_getdial(char *p, char *q,int cnt)
  2525. {
  2526. int first = 1;
  2527. int limit = ISDN_MSNLEN - 1; /* MUST match the size of interface var to avoid
  2528. buffer overflow */
  2529. while (strchr(" 0123456789,#.*WPTSR-", *p) && *p && --cnt>0) {
  2530. if ((*p >= '0' && *p <= '9') || ((*p == 'S') && first) ||
  2531. ((*p == 'R') && first) ||
  2532. (*p == '*') || (*p == '#')) {
  2533. *q++ = *p;
  2534. limit--;
  2535. }
  2536. if(!limit)
  2537. break;
  2538. p++;
  2539. first = 0;
  2540. }
  2541. *q = 0;
  2542. }
  2543. #define PARSE_ERROR { isdn_tty_modem_result(RESULT_ERROR, info); return; }
  2544. #define PARSE_ERROR1 { isdn_tty_modem_result(RESULT_ERROR, info); return 1; }
  2545. static void
  2546. isdn_tty_report(modem_info * info)
  2547. {
  2548. atemu *m = &info->emu;
  2549. char s[80];
  2550. isdn_tty_at_cout("\r\nStatistics of last connection:\r\n\r\n", info);
  2551. sprintf(s, " Remote Number: %s\r\n", info->last_num);
  2552. isdn_tty_at_cout(s, info);
  2553. sprintf(s, " Direction: %s\r\n", info->last_dir ? "outgoing" : "incoming");
  2554. isdn_tty_at_cout(s, info);
  2555. isdn_tty_at_cout(" Layer-2 Protocol: ", info);
  2556. switch (info->last_l2) {
  2557. case ISDN_PROTO_L2_X75I:
  2558. isdn_tty_at_cout("X.75i", info);
  2559. break;
  2560. case ISDN_PROTO_L2_X75UI:
  2561. isdn_tty_at_cout("X.75ui", info);
  2562. break;
  2563. case ISDN_PROTO_L2_X75BUI:
  2564. isdn_tty_at_cout("X.75bui", info);
  2565. break;
  2566. case ISDN_PROTO_L2_HDLC:
  2567. isdn_tty_at_cout("HDLC", info);
  2568. break;
  2569. case ISDN_PROTO_L2_V11096:
  2570. isdn_tty_at_cout("V.110 9600 Baud", info);
  2571. break;
  2572. case ISDN_PROTO_L2_V11019:
  2573. isdn_tty_at_cout("V.110 19200 Baud", info);
  2574. break;
  2575. case ISDN_PROTO_L2_V11038:
  2576. isdn_tty_at_cout("V.110 38400 Baud", info);
  2577. break;
  2578. case ISDN_PROTO_L2_TRANS:
  2579. isdn_tty_at_cout("transparent", info);
  2580. break;
  2581. case ISDN_PROTO_L2_MODEM:
  2582. isdn_tty_at_cout("modem", info);
  2583. break;
  2584. case ISDN_PROTO_L2_FAX:
  2585. isdn_tty_at_cout("fax", info);
  2586. break;
  2587. default:
  2588. isdn_tty_at_cout("unknown", info);
  2589. break;
  2590. }
  2591. if (m->mdmreg[REG_T70] & BIT_T70) {
  2592. isdn_tty_at_cout("/T.70", info);
  2593. if (m->mdmreg[REG_T70] & BIT_T70_EXT)
  2594. isdn_tty_at_cout("+", info);
  2595. }
  2596. isdn_tty_at_cout("\r\n", info);
  2597. isdn_tty_at_cout(" Service: ", info);
  2598. switch (info->last_si) {
  2599. case 1:
  2600. isdn_tty_at_cout("audio\r\n", info);
  2601. break;
  2602. case 5:
  2603. isdn_tty_at_cout("btx\r\n", info);
  2604. break;
  2605. case 7:
  2606. isdn_tty_at_cout("data\r\n", info);
  2607. break;
  2608. default:
  2609. sprintf(s, "%d\r\n", info->last_si);
  2610. isdn_tty_at_cout(s, info);
  2611. break;
  2612. }
  2613. sprintf(s, " Hangup location: %s\r\n", info->last_lhup ? "local" : "remote");
  2614. isdn_tty_at_cout(s, info);
  2615. sprintf(s, " Last cause: %s\r\n", info->last_cause);
  2616. isdn_tty_at_cout(s, info);
  2617. }
  2618. /*
  2619. * Parse AT&.. commands.
  2620. */
  2621. static int
  2622. isdn_tty_cmd_ATand(char **p, modem_info * info)
  2623. {
  2624. atemu *m = &info->emu;
  2625. int i;
  2626. char rb[100];
  2627. #define MAXRB (sizeof(rb) - 1)
  2628. switch (*p[0]) {
  2629. case 'B':
  2630. /* &B - Set Buffersize */
  2631. p[0]++;
  2632. i = isdn_getnum(p);
  2633. if ((i < 0) || (i > ISDN_SERIAL_XMIT_MAX))
  2634. PARSE_ERROR1;
  2635. #ifdef CONFIG_ISDN_AUDIO
  2636. if ((m->mdmreg[REG_SI1] & 1) && (i > VBUF))
  2637. PARSE_ERROR1;
  2638. #endif
  2639. m->mdmreg[REG_PSIZE] = i / 16;
  2640. info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
  2641. switch (m->mdmreg[REG_L2PROT]) {
  2642. case ISDN_PROTO_L2_V11096:
  2643. case ISDN_PROTO_L2_V11019:
  2644. case ISDN_PROTO_L2_V11038:
  2645. info->xmit_size /= 10;
  2646. }
  2647. break;
  2648. case 'C':
  2649. /* &C - DCD Status */
  2650. p[0]++;
  2651. switch (isdn_getnum(p)) {
  2652. case 0:
  2653. m->mdmreg[REG_DCD] &= ~BIT_DCD;
  2654. break;
  2655. case 1:
  2656. m->mdmreg[REG_DCD] |= BIT_DCD;
  2657. break;
  2658. default:
  2659. PARSE_ERROR1
  2660. }
  2661. break;
  2662. case 'D':
  2663. /* &D - Set DTR-Low-behavior */
  2664. p[0]++;
  2665. switch (isdn_getnum(p)) {
  2666. case 0:
  2667. m->mdmreg[REG_DTRHUP] &= ~BIT_DTRHUP;
  2668. m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
  2669. break;
  2670. case 2:
  2671. m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
  2672. m->mdmreg[REG_DTRR] &= ~BIT_DTRR;
  2673. break;
  2674. case 3:
  2675. m->mdmreg[REG_DTRHUP] |= BIT_DTRHUP;
  2676. m->mdmreg[REG_DTRR] |= BIT_DTRR;
  2677. break;
  2678. default:
  2679. PARSE_ERROR1
  2680. }
  2681. break;
  2682. case 'E':
  2683. /* &E -Set EAZ/MSN */
  2684. p[0]++;
  2685. isdn_tty_get_msnstr(m->msn, p);
  2686. break;
  2687. case 'F':
  2688. /* &F -Set Factory-Defaults */
  2689. p[0]++;
  2690. if (info->msr & UART_MSR_DCD)
  2691. PARSE_ERROR1;
  2692. isdn_tty_reset_profile(m);
  2693. isdn_tty_modem_reset_regs(info, 1);
  2694. break;
  2695. #ifdef DUMMY_HAYES_AT
  2696. case 'K':
  2697. /* only for be compilant with common scripts */
  2698. /* &K Flowcontrol - no function */
  2699. p[0]++;
  2700. isdn_getnum(p);
  2701. break;
  2702. #endif
  2703. case 'L':
  2704. /* &L -Set Numbers to listen on */
  2705. p[0]++;
  2706. i = 0;
  2707. while (*p[0] && (strchr("0123456789,-*[]?;", *p[0])) &&
  2708. (i < ISDN_LMSNLEN - 1))
  2709. m->lmsn[i++] = *p[0]++;
  2710. m->lmsn[i] = '\0';
  2711. break;
  2712. case 'R':
  2713. /* &R - Set V.110 bitrate adaption */
  2714. p[0]++;
  2715. i = isdn_getnum(p);
  2716. switch (i) {
  2717. case 0:
  2718. /* Switch off V.110, back to X.75 */
  2719. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2720. m->mdmreg[REG_SI2] = 0;
  2721. info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
  2722. break;
  2723. case 9600:
  2724. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11096;
  2725. m->mdmreg[REG_SI2] = 197;
  2726. info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
  2727. break;
  2728. case 19200:
  2729. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11019;
  2730. m->mdmreg[REG_SI2] = 199;
  2731. info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
  2732. break;
  2733. case 38400:
  2734. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_V11038;
  2735. m->mdmreg[REG_SI2] = 198; /* no existing standard for this */
  2736. info->xmit_size = m->mdmreg[REG_PSIZE] * 16 / 10;
  2737. break;
  2738. default:
  2739. PARSE_ERROR1;
  2740. }
  2741. /* Switch off T.70 */
  2742. m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
  2743. /* Set Service 7 */
  2744. m->mdmreg[REG_SI1] |= 4;
  2745. break;
  2746. case 'S':
  2747. /* &S - Set Windowsize */
  2748. p[0]++;
  2749. i = isdn_getnum(p);
  2750. if ((i > 0) && (i < 9))
  2751. m->mdmreg[REG_WSIZE] = i;
  2752. else
  2753. PARSE_ERROR1;
  2754. break;
  2755. case 'V':
  2756. /* &V - Show registers */
  2757. p[0]++;
  2758. isdn_tty_at_cout("\r\n", info);
  2759. for (i = 0; i < ISDN_MODEM_NUMREG; i++) {
  2760. sprintf(rb, "S%02d=%03d%s", i,
  2761. m->mdmreg[i], ((i + 1) % 10) ? " " : "\r\n");
  2762. isdn_tty_at_cout(rb, info);
  2763. }
  2764. sprintf(rb, "\r\nEAZ/MSN: %.50s\r\n",
  2765. strlen(m->msn) ? m->msn : "None");
  2766. isdn_tty_at_cout(rb, info);
  2767. if (strlen(m->lmsn)) {
  2768. isdn_tty_at_cout("\r\nListen: ", info);
  2769. isdn_tty_at_cout(m->lmsn, info);
  2770. isdn_tty_at_cout("\r\n", info);
  2771. }
  2772. break;
  2773. case 'W':
  2774. /* &W - Write Profile */
  2775. p[0]++;
  2776. switch (*p[0]) {
  2777. case '0':
  2778. p[0]++;
  2779. modem_write_profile(m);
  2780. break;
  2781. default:
  2782. PARSE_ERROR1;
  2783. }
  2784. break;
  2785. case 'X':
  2786. /* &X - Switch to BTX-Mode and T.70 */
  2787. p[0]++;
  2788. switch (isdn_getnum(p)) {
  2789. case 0:
  2790. m->mdmreg[REG_T70] &= ~(BIT_T70 | BIT_T70_EXT);
  2791. info->xmit_size = m->mdmreg[REG_PSIZE] * 16;
  2792. break;
  2793. case 1:
  2794. m->mdmreg[REG_T70] |= BIT_T70;
  2795. m->mdmreg[REG_T70] &= ~BIT_T70_EXT;
  2796. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2797. info->xmit_size = 112;
  2798. m->mdmreg[REG_SI1] = 4;
  2799. m->mdmreg[REG_SI2] = 0;
  2800. break;
  2801. case 2:
  2802. m->mdmreg[REG_T70] |= (BIT_T70 | BIT_T70_EXT);
  2803. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2804. info->xmit_size = 112;
  2805. m->mdmreg[REG_SI1] = 4;
  2806. m->mdmreg[REG_SI2] = 0;
  2807. break;
  2808. default:
  2809. PARSE_ERROR1;
  2810. }
  2811. break;
  2812. default:
  2813. PARSE_ERROR1;
  2814. }
  2815. return 0;
  2816. }
  2817. static int
  2818. isdn_tty_check_ats(int mreg, int mval, modem_info * info, atemu * m)
  2819. {
  2820. /* Some plausibility checks */
  2821. switch (mreg) {
  2822. case REG_L2PROT:
  2823. if (mval > ISDN_PROTO_L2_MAX)
  2824. return 1;
  2825. break;
  2826. case REG_PSIZE:
  2827. if ((mval * 16) > ISDN_SERIAL_XMIT_MAX)
  2828. return 1;
  2829. #ifdef CONFIG_ISDN_AUDIO
  2830. if ((m->mdmreg[REG_SI1] & 1) && (mval > VBUFX))
  2831. return 1;
  2832. #endif
  2833. info->xmit_size = mval * 16;
  2834. switch (m->mdmreg[REG_L2PROT]) {
  2835. case ISDN_PROTO_L2_V11096:
  2836. case ISDN_PROTO_L2_V11019:
  2837. case ISDN_PROTO_L2_V11038:
  2838. info->xmit_size /= 10;
  2839. }
  2840. break;
  2841. case REG_SI1I:
  2842. case REG_PLAN:
  2843. case REG_SCREEN:
  2844. /* readonly registers */
  2845. return 1;
  2846. }
  2847. return 0;
  2848. }
  2849. /*
  2850. * Perform ATS command
  2851. */
  2852. static int
  2853. isdn_tty_cmd_ATS(char **p, modem_info * info)
  2854. {
  2855. atemu *m = &info->emu;
  2856. int bitpos;
  2857. int mreg;
  2858. int mval;
  2859. int bval;
  2860. mreg = isdn_getnum(p);
  2861. if (mreg < 0 || mreg >= ISDN_MODEM_NUMREG)
  2862. PARSE_ERROR1;
  2863. switch (*p[0]) {
  2864. case '=':
  2865. p[0]++;
  2866. mval = isdn_getnum(p);
  2867. if (mval < 0 || mval > 255)
  2868. PARSE_ERROR1;
  2869. if (isdn_tty_check_ats(mreg, mval, info, m))
  2870. PARSE_ERROR1;
  2871. m->mdmreg[mreg] = mval;
  2872. break;
  2873. case '.':
  2874. /* Set/Clear a single bit */
  2875. p[0]++;
  2876. bitpos = isdn_getnum(p);
  2877. if ((bitpos < 0) || (bitpos > 7))
  2878. PARSE_ERROR1;
  2879. switch (*p[0]) {
  2880. case '=':
  2881. p[0]++;
  2882. bval = isdn_getnum(p);
  2883. if (bval < 0 || bval > 1)
  2884. PARSE_ERROR1;
  2885. if (bval)
  2886. mval = m->mdmreg[mreg] | (1 << bitpos);
  2887. else
  2888. mval = m->mdmreg[mreg] & ~(1 << bitpos);
  2889. if (isdn_tty_check_ats(mreg, mval, info, m))
  2890. PARSE_ERROR1;
  2891. m->mdmreg[mreg] = mval;
  2892. break;
  2893. case '?':
  2894. p[0]++;
  2895. isdn_tty_at_cout("\r\n", info);
  2896. isdn_tty_at_cout((m->mdmreg[mreg] & (1 << bitpos)) ? "1" : "0",
  2897. info);
  2898. break;
  2899. default:
  2900. PARSE_ERROR1;
  2901. }
  2902. break;
  2903. case '?':
  2904. p[0]++;
  2905. isdn_tty_show_profile(mreg, info);
  2906. break;
  2907. default:
  2908. PARSE_ERROR1;
  2909. break;
  2910. }
  2911. return 0;
  2912. }
  2913. /*
  2914. * Perform ATA command
  2915. */
  2916. static void
  2917. isdn_tty_cmd_ATA(modem_info * info)
  2918. {
  2919. atemu *m = &info->emu;
  2920. isdn_ctrl cmd;
  2921. int l2;
  2922. if (info->msr & UART_MSR_RI) {
  2923. /* Accept incoming call */
  2924. info->last_dir = 0;
  2925. strcpy(info->last_num, dev->num[info->drv_index]);
  2926. m->mdmreg[REG_RINGCNT] = 0;
  2927. info->msr &= ~UART_MSR_RI;
  2928. l2 = m->mdmreg[REG_L2PROT];
  2929. #ifdef CONFIG_ISDN_AUDIO
  2930. /* If more than one bit set in reg18, autoselect Layer2 */
  2931. if ((m->mdmreg[REG_SI1] & m->mdmreg[REG_SI1I]) != m->mdmreg[REG_SI1]) {
  2932. if (m->mdmreg[REG_SI1I] == 1) {
  2933. if ((l2 != ISDN_PROTO_L2_MODEM) && (l2 != ISDN_PROTO_L2_FAX))
  2934. l2 = ISDN_PROTO_L2_TRANS;
  2935. } else
  2936. l2 = ISDN_PROTO_L2_X75I;
  2937. }
  2938. #endif
  2939. cmd.driver = info->isdn_driver;
  2940. cmd.command = ISDN_CMD_SETL2;
  2941. cmd.arg = info->isdn_channel + (l2 << 8);
  2942. info->last_l2 = l2;
  2943. isdn_command(&cmd);
  2944. cmd.driver = info->isdn_driver;
  2945. cmd.command = ISDN_CMD_SETL3;
  2946. cmd.arg = info->isdn_channel + (m->mdmreg[REG_L3PROT] << 8);
  2947. #ifdef CONFIG_ISDN_TTY_FAX
  2948. if (l2 == ISDN_PROTO_L2_FAX) {
  2949. cmd.parm.fax = info->fax;
  2950. info->fax->direction = ISDN_TTY_FAX_CONN_IN;
  2951. }
  2952. #endif
  2953. isdn_command(&cmd);
  2954. cmd.driver = info->isdn_driver;
  2955. cmd.arg = info->isdn_channel;
  2956. cmd.command = ISDN_CMD_ACCEPTD;
  2957. info->dialing = 16;
  2958. info->emu.carrierwait = 0;
  2959. isdn_command(&cmd);
  2960. isdn_timer_ctrl(ISDN_TIMER_CARRIER, 1);
  2961. } else
  2962. isdn_tty_modem_result(RESULT_NO_ANSWER, info);
  2963. }
  2964. #ifdef CONFIG_ISDN_AUDIO
  2965. /*
  2966. * Parse AT+F.. commands
  2967. */
  2968. static int
  2969. isdn_tty_cmd_PLUSF(char **p, modem_info * info)
  2970. {
  2971. atemu *m = &info->emu;
  2972. char rs[20];
  2973. if (!strncmp(p[0], "CLASS", 5)) {
  2974. p[0] += 5;
  2975. switch (*p[0]) {
  2976. case '?':
  2977. p[0]++;
  2978. sprintf(rs, "\r\n%d",
  2979. (m->mdmreg[REG_SI1] & 1) ? 8 : 0);
  2980. #ifdef CONFIG_ISDN_TTY_FAX
  2981. if (TTY_IS_FCLASS2(info))
  2982. sprintf(rs, "\r\n2");
  2983. else if (TTY_IS_FCLASS1(info))
  2984. sprintf(rs, "\r\n1");
  2985. #endif
  2986. isdn_tty_at_cout(rs, info);
  2987. break;
  2988. case '=':
  2989. p[0]++;
  2990. switch (*p[0]) {
  2991. case '0':
  2992. p[0]++;
  2993. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  2994. m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
  2995. m->mdmreg[REG_SI1] = 4;
  2996. info->xmit_size =
  2997. m->mdmreg[REG_PSIZE] * 16;
  2998. break;
  2999. #ifdef CONFIG_ISDN_TTY_FAX
  3000. case '1':
  3001. p[0]++;
  3002. if (!(dev->global_features &
  3003. ISDN_FEATURE_L3_FCLASS1))
  3004. PARSE_ERROR1;
  3005. m->mdmreg[REG_SI1] = 1;
  3006. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
  3007. m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS1;
  3008. info->xmit_size =
  3009. m->mdmreg[REG_PSIZE] * 16;
  3010. break;
  3011. case '2':
  3012. p[0]++;
  3013. if (!(dev->global_features &
  3014. ISDN_FEATURE_L3_FCLASS2))
  3015. PARSE_ERROR1;
  3016. m->mdmreg[REG_SI1] = 1;
  3017. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_FAX;
  3018. m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_FCLASS2;
  3019. info->xmit_size =
  3020. m->mdmreg[REG_PSIZE] * 16;
  3021. break;
  3022. #endif
  3023. case '8':
  3024. p[0]++;
  3025. /* L2 will change on dialout with si=1 */
  3026. m->mdmreg[REG_L2PROT] = ISDN_PROTO_L2_X75I;
  3027. m->mdmreg[REG_L3PROT] = ISDN_PROTO_L3_TRANS;
  3028. m->mdmreg[REG_SI1] = 5;
  3029. info->xmit_size = VBUF;
  3030. break;
  3031. case '?':
  3032. p[0]++;
  3033. strcpy(rs, "\r\n0,");
  3034. #ifdef CONFIG_ISDN_TTY_FAX
  3035. if (dev->global_features &
  3036. ISDN_FEATURE_L3_FCLASS1)
  3037. strcat(rs, "1,");
  3038. if (dev->global_features &
  3039. ISDN_FEATURE_L3_FCLASS2)
  3040. strcat(rs, "2,");
  3041. #endif
  3042. strcat(rs, "8");
  3043. isdn_tty_at_cout(rs, info);
  3044. break;
  3045. default:
  3046. PARSE_ERROR1;
  3047. }
  3048. break;
  3049. default:
  3050. PARSE_ERROR1;
  3051. }
  3052. return 0;
  3053. }
  3054. #ifdef CONFIG_ISDN_TTY_FAX
  3055. return (isdn_tty_cmd_PLUSF_FAX(p, info));
  3056. #else
  3057. PARSE_ERROR1;
  3058. #endif
  3059. }
  3060. /*
  3061. * Parse AT+V.. commands
  3062. */
  3063. static int
  3064. isdn_tty_cmd_PLUSV(char **p, modem_info * info)
  3065. {
  3066. atemu *m = &info->emu;
  3067. isdn_ctrl cmd;
  3068. static char *vcmd[] =
  3069. {"NH", "IP", "LS", "RX", "SD", "SM", "TX", "DD", NULL};
  3070. int i;
  3071. int par1;
  3072. int par2;
  3073. char rs[20];
  3074. i = 0;
  3075. while (vcmd[i]) {
  3076. if (!strncmp(vcmd[i], p[0], 2)) {
  3077. p[0] += 2;
  3078. break;
  3079. }
  3080. i++;
  3081. }
  3082. switch (i) {
  3083. case 0:
  3084. /* AT+VNH - Auto hangup feature */
  3085. switch (*p[0]) {
  3086. case '?':
  3087. p[0]++;
  3088. isdn_tty_at_cout("\r\n1", info);
  3089. break;
  3090. case '=':
  3091. p[0]++;
  3092. switch (*p[0]) {
  3093. case '1':
  3094. p[0]++;
  3095. break;
  3096. case '?':
  3097. p[0]++;
  3098. isdn_tty_at_cout("\r\n1", info);
  3099. break;
  3100. default:
  3101. PARSE_ERROR1;
  3102. }
  3103. break;
  3104. default:
  3105. PARSE_ERROR1;
  3106. }
  3107. break;
  3108. case 1:
  3109. /* AT+VIP - Reset all voice parameters */
  3110. isdn_tty_modem_reset_vpar(m);
  3111. break;
  3112. case 2:
  3113. /* AT+VLS - Select device, accept incoming call */
  3114. switch (*p[0]) {
  3115. case '?':
  3116. p[0]++;
  3117. sprintf(rs, "\r\n%d", m->vpar[0]);
  3118. isdn_tty_at_cout(rs, info);
  3119. break;
  3120. case '=':
  3121. p[0]++;
  3122. switch (*p[0]) {
  3123. case '0':
  3124. p[0]++;
  3125. m->vpar[0] = 0;
  3126. break;
  3127. case '2':
  3128. p[0]++;
  3129. m->vpar[0] = 2;
  3130. break;
  3131. case '?':
  3132. p[0]++;
  3133. isdn_tty_at_cout("\r\n0,2", info);
  3134. break;
  3135. default:
  3136. PARSE_ERROR1;
  3137. }
  3138. break;
  3139. default:
  3140. PARSE_ERROR1;
  3141. }
  3142. break;
  3143. case 3:
  3144. /* AT+VRX - Start recording */
  3145. if (!m->vpar[0])
  3146. PARSE_ERROR1;
  3147. if (info->online != 1) {
  3148. isdn_tty_modem_result(RESULT_NO_ANSWER, info);
  3149. return 1;
  3150. }
  3151. info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
  3152. if (!info->dtmf_state) {
  3153. printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
  3154. PARSE_ERROR1;
  3155. }
  3156. info->silence_state = isdn_audio_silence_init(info->silence_state);
  3157. if (!info->silence_state) {
  3158. printk(KERN_WARNING "isdn_tty: Couldn't malloc silence state\n");
  3159. PARSE_ERROR1;
  3160. }
  3161. if (m->vpar[3] < 5) {
  3162. info->adpcmr = isdn_audio_adpcm_init(info->adpcmr, m->vpar[3]);
  3163. if (!info->adpcmr) {
  3164. printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
  3165. PARSE_ERROR1;
  3166. }
  3167. }
  3168. #ifdef ISDN_DEBUG_AT
  3169. printk(KERN_DEBUG "AT: +VRX\n");
  3170. #endif
  3171. info->vonline |= 1;
  3172. isdn_tty_modem_result(RESULT_CONNECT, info);
  3173. return 0;
  3174. break;
  3175. case 4:
  3176. /* AT+VSD - Silence detection */
  3177. switch (*p[0]) {
  3178. case '?':
  3179. p[0]++;
  3180. sprintf(rs, "\r\n<%d>,<%d>",
  3181. m->vpar[1],
  3182. m->vpar[2]);
  3183. isdn_tty_at_cout(rs, info);
  3184. break;
  3185. case '=':
  3186. p[0]++;
  3187. if ((*p[0]>='0') && (*p[0]<='9')) {
  3188. par1 = isdn_getnum(p);
  3189. if ((par1 < 0) || (par1 > 31))
  3190. PARSE_ERROR1;
  3191. if (*p[0] != ',')
  3192. PARSE_ERROR1;
  3193. p[0]++;
  3194. par2 = isdn_getnum(p);
  3195. if ((par2 < 0) || (par2 > 255))
  3196. PARSE_ERROR1;
  3197. m->vpar[1] = par1;
  3198. m->vpar[2] = par2;
  3199. break;
  3200. } else
  3201. if (*p[0] == '?') {
  3202. p[0]++;
  3203. isdn_tty_at_cout("\r\n<0-31>,<0-255>",
  3204. info);
  3205. break;
  3206. } else
  3207. PARSE_ERROR1;
  3208. break;
  3209. default:
  3210. PARSE_ERROR1;
  3211. }
  3212. break;
  3213. case 5:
  3214. /* AT+VSM - Select compression */
  3215. switch (*p[0]) {
  3216. case '?':
  3217. p[0]++;
  3218. sprintf(rs, "\r\n<%d>,<%d><8000>",
  3219. m->vpar[3],
  3220. m->vpar[1]);
  3221. isdn_tty_at_cout(rs, info);
  3222. break;
  3223. case '=':
  3224. p[0]++;
  3225. switch (*p[0]) {
  3226. case '2':
  3227. case '3':
  3228. case '4':
  3229. case '5':
  3230. case '6':
  3231. par1 = isdn_getnum(p);
  3232. if ((par1 < 2) || (par1 > 6))
  3233. PARSE_ERROR1;
  3234. m->vpar[3] = par1;
  3235. break;
  3236. case '?':
  3237. p[0]++;
  3238. isdn_tty_at_cout("\r\n2;ADPCM;2;0;(8000)\r\n",
  3239. info);
  3240. isdn_tty_at_cout("3;ADPCM;3;0;(8000)\r\n",
  3241. info);
  3242. isdn_tty_at_cout("4;ADPCM;4;0;(8000)\r\n",
  3243. info);
  3244. isdn_tty_at_cout("5;ALAW;8;0;(8000)\r\n",
  3245. info);
  3246. isdn_tty_at_cout("6;ULAW;8;0;(8000)\r\n",
  3247. info);
  3248. break;
  3249. default:
  3250. PARSE_ERROR1;
  3251. }
  3252. break;
  3253. default:
  3254. PARSE_ERROR1;
  3255. }
  3256. break;
  3257. case 6:
  3258. /* AT+VTX - Start sending */
  3259. if (!m->vpar[0])
  3260. PARSE_ERROR1;
  3261. if (info->online != 1) {
  3262. isdn_tty_modem_result(RESULT_NO_ANSWER, info);
  3263. return 1;
  3264. }
  3265. info->dtmf_state = isdn_audio_dtmf_init(info->dtmf_state);
  3266. if (!info->dtmf_state) {
  3267. printk(KERN_WARNING "isdn_tty: Couldn't malloc dtmf state\n");
  3268. PARSE_ERROR1;
  3269. }
  3270. if (m->vpar[3] < 5) {
  3271. info->adpcms = isdn_audio_adpcm_init(info->adpcms, m->vpar[3]);
  3272. if (!info->adpcms) {
  3273. printk(KERN_WARNING "isdn_tty: Couldn't malloc adpcm state\n");
  3274. PARSE_ERROR1;
  3275. }
  3276. }
  3277. #ifdef ISDN_DEBUG_AT
  3278. printk(KERN_DEBUG "AT: +VTX\n");
  3279. #endif
  3280. m->lastDLE = 0;
  3281. info->vonline |= 2;
  3282. isdn_tty_modem_result(RESULT_CONNECT, info);
  3283. return 0;
  3284. break;
  3285. case 7:
  3286. /* AT+VDD - DTMF detection */
  3287. switch (*p[0]) {
  3288. case '?':
  3289. p[0]++;
  3290. sprintf(rs, "\r\n<%d>,<%d>",
  3291. m->vpar[4],
  3292. m->vpar[5]);
  3293. isdn_tty_at_cout(rs, info);
  3294. break;
  3295. case '=':
  3296. p[0]++;
  3297. if ((*p[0]>='0') && (*p[0]<='9')) {
  3298. if (info->online != 1)
  3299. PARSE_ERROR1;
  3300. par1 = isdn_getnum(p);
  3301. if ((par1 < 0) || (par1 > 15))
  3302. PARSE_ERROR1;
  3303. if (*p[0] != ',')
  3304. PARSE_ERROR1;
  3305. p[0]++;
  3306. par2 = isdn_getnum(p);
  3307. if ((par2 < 0) || (par2 > 255))
  3308. PARSE_ERROR1;
  3309. m->vpar[4] = par1;
  3310. m->vpar[5] = par2;
  3311. cmd.driver = info->isdn_driver;
  3312. cmd.command = ISDN_CMD_AUDIO;
  3313. cmd.arg = info->isdn_channel + (ISDN_AUDIO_SETDD << 8);
  3314. cmd.parm.num[0] = par1;
  3315. cmd.parm.num[1] = par2;
  3316. isdn_command(&cmd);
  3317. break;
  3318. } else
  3319. if (*p[0] == '?') {
  3320. p[0]++;
  3321. isdn_tty_at_cout("\r\n<0-15>,<0-255>",
  3322. info);
  3323. break;
  3324. } else
  3325. PARSE_ERROR1;
  3326. break;
  3327. default:
  3328. PARSE_ERROR1;
  3329. }
  3330. break;
  3331. default:
  3332. PARSE_ERROR1;
  3333. }
  3334. return 0;
  3335. }
  3336. #endif /* CONFIG_ISDN_AUDIO */
  3337. /*
  3338. * Parse and perform an AT-command-line.
  3339. */
  3340. static void
  3341. isdn_tty_parse_at(modem_info * info)
  3342. {
  3343. atemu *m = &info->emu;
  3344. char *p;
  3345. char ds[ISDN_MSNLEN];
  3346. #ifdef ISDN_DEBUG_AT
  3347. printk(KERN_DEBUG "AT: '%s'\n", m->mdmcmd);
  3348. #endif
  3349. for (p = &m->mdmcmd[2]; *p;) {
  3350. switch (*p) {
  3351. case ' ':
  3352. p++;
  3353. break;
  3354. case 'A':
  3355. /* A - Accept incoming call */
  3356. p++;
  3357. isdn_tty_cmd_ATA(info);
  3358. return;
  3359. break;
  3360. case 'D':
  3361. /* D - Dial */
  3362. if (info->msr & UART_MSR_DCD)
  3363. PARSE_ERROR;
  3364. if (info->msr & UART_MSR_RI) {
  3365. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  3366. return;
  3367. }
  3368. isdn_tty_getdial(++p, ds, sizeof ds);
  3369. p += strlen(p);
  3370. if (!strlen(m->msn))
  3371. isdn_tty_modem_result(RESULT_NO_MSN_EAZ, info);
  3372. else if (strlen(ds))
  3373. isdn_tty_dial(ds, info, m);
  3374. else
  3375. PARSE_ERROR;
  3376. return;
  3377. case 'E':
  3378. /* E - Turn Echo on/off */
  3379. p++;
  3380. switch (isdn_getnum(&p)) {
  3381. case 0:
  3382. m->mdmreg[REG_ECHO] &= ~BIT_ECHO;
  3383. break;
  3384. case 1:
  3385. m->mdmreg[REG_ECHO] |= BIT_ECHO;
  3386. break;
  3387. default:
  3388. PARSE_ERROR;
  3389. }
  3390. break;
  3391. case 'H':
  3392. /* H - On/Off-hook */
  3393. p++;
  3394. switch (*p) {
  3395. case '0':
  3396. p++;
  3397. isdn_tty_on_hook(info);
  3398. break;
  3399. case '1':
  3400. p++;
  3401. isdn_tty_off_hook();
  3402. break;
  3403. default:
  3404. isdn_tty_on_hook(info);
  3405. break;
  3406. }
  3407. break;
  3408. case 'I':
  3409. /* I - Information */
  3410. p++;
  3411. isdn_tty_at_cout("\r\nLinux ISDN", info);
  3412. switch (*p) {
  3413. case '0':
  3414. case '1':
  3415. p++;
  3416. break;
  3417. case '2':
  3418. p++;
  3419. isdn_tty_report(info);
  3420. break;
  3421. case '3':
  3422. p++;
  3423. snprintf(ds, sizeof(ds), "\r\n%d", info->emu.charge);
  3424. isdn_tty_at_cout(ds, info);
  3425. break;
  3426. default:;
  3427. }
  3428. break;
  3429. #ifdef DUMMY_HAYES_AT
  3430. case 'L':
  3431. case 'M':
  3432. /* only for be compilant with common scripts */
  3433. /* no function */
  3434. p++;
  3435. isdn_getnum(&p);
  3436. break;
  3437. #endif
  3438. case 'O':
  3439. /* O - Go online */
  3440. p++;
  3441. if (info->msr & UART_MSR_DCD)
  3442. /* if B-Channel is up */
  3443. isdn_tty_modem_result((m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM) ? RESULT_CONNECT:RESULT_CONNECT64000, info);
  3444. else
  3445. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  3446. return;
  3447. case 'Q':
  3448. /* Q - Turn Emulator messages on/off */
  3449. p++;
  3450. switch (isdn_getnum(&p)) {
  3451. case 0:
  3452. m->mdmreg[REG_RESP] |= BIT_RESP;
  3453. break;
  3454. case 1:
  3455. m->mdmreg[REG_RESP] &= ~BIT_RESP;
  3456. break;
  3457. default:
  3458. PARSE_ERROR;
  3459. }
  3460. break;
  3461. case 'S':
  3462. /* S - Set/Get Register */
  3463. p++;
  3464. if (isdn_tty_cmd_ATS(&p, info))
  3465. return;
  3466. break;
  3467. case 'V':
  3468. /* V - Numeric or ASCII Emulator-messages */
  3469. p++;
  3470. switch (isdn_getnum(&p)) {
  3471. case 0:
  3472. m->mdmreg[REG_RESP] |= BIT_RESPNUM;
  3473. break;
  3474. case 1:
  3475. m->mdmreg[REG_RESP] &= ~BIT_RESPNUM;
  3476. break;
  3477. default:
  3478. PARSE_ERROR;
  3479. }
  3480. break;
  3481. case 'Z':
  3482. /* Z - Load Registers from Profile */
  3483. p++;
  3484. if (info->msr & UART_MSR_DCD) {
  3485. info->online = 0;
  3486. isdn_tty_on_hook(info);
  3487. }
  3488. isdn_tty_modem_reset_regs(info, 1);
  3489. break;
  3490. case '+':
  3491. p++;
  3492. switch (*p) {
  3493. #ifdef CONFIG_ISDN_AUDIO
  3494. case 'F':
  3495. p++;
  3496. if (isdn_tty_cmd_PLUSF(&p, info))
  3497. return;
  3498. break;
  3499. case 'V':
  3500. if ((!(m->mdmreg[REG_SI1] & 1)) ||
  3501. (m->mdmreg[REG_L2PROT] == ISDN_PROTO_L2_MODEM))
  3502. PARSE_ERROR;
  3503. p++;
  3504. if (isdn_tty_cmd_PLUSV(&p, info))
  3505. return;
  3506. break;
  3507. #endif /* CONFIG_ISDN_AUDIO */
  3508. case 'S': /* SUSPEND */
  3509. p++;
  3510. isdn_tty_get_msnstr(ds, &p);
  3511. isdn_tty_suspend(ds, info, m);
  3512. break;
  3513. case 'R': /* RESUME */
  3514. p++;
  3515. isdn_tty_get_msnstr(ds, &p);
  3516. isdn_tty_resume(ds, info, m);
  3517. break;
  3518. case 'M': /* MESSAGE */
  3519. p++;
  3520. isdn_tty_send_msg(info, m, p);
  3521. break;
  3522. default:
  3523. PARSE_ERROR;
  3524. }
  3525. break;
  3526. case '&':
  3527. p++;
  3528. if (isdn_tty_cmd_ATand(&p, info))
  3529. return;
  3530. break;
  3531. default:
  3532. PARSE_ERROR;
  3533. }
  3534. }
  3535. #ifdef CONFIG_ISDN_AUDIO
  3536. if (!info->vonline)
  3537. #endif
  3538. isdn_tty_modem_result(RESULT_OK, info);
  3539. }
  3540. /* Need own toupper() because standard-toupper is not available
  3541. * within modules.
  3542. */
  3543. #define my_toupper(c) (((c>='a')&&(c<='z'))?(c&0xdf):c)
  3544. /*
  3545. * Perform line-editing of AT-commands
  3546. *
  3547. * Parameters:
  3548. * p inputbuffer
  3549. * count length of buffer
  3550. * channel index to line (minor-device)
  3551. */
  3552. static int
  3553. isdn_tty_edit_at(const char *p, int count, modem_info * info)
  3554. {
  3555. atemu *m = &info->emu;
  3556. int total = 0;
  3557. u_char c;
  3558. char eb[2];
  3559. int cnt;
  3560. for (cnt = count; cnt > 0; p++, cnt--) {
  3561. c = *p;
  3562. total++;
  3563. if (c == m->mdmreg[REG_CR] || c == m->mdmreg[REG_LF]) {
  3564. /* Separator (CR or LF) */
  3565. m->mdmcmd[m->mdmcmdl] = 0;
  3566. if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
  3567. eb[0] = c;
  3568. eb[1] = 0;
  3569. isdn_tty_at_cout(eb, info);
  3570. }
  3571. if ((m->mdmcmdl >= 2) && (!(strncmp(m->mdmcmd, "AT", 2))))
  3572. isdn_tty_parse_at(info);
  3573. m->mdmcmdl = 0;
  3574. continue;
  3575. }
  3576. if (c == m->mdmreg[REG_BS] && m->mdmreg[REG_BS] < 128) {
  3577. /* Backspace-Function */
  3578. if ((m->mdmcmdl > 2) || (!m->mdmcmdl)) {
  3579. if (m->mdmcmdl)
  3580. m->mdmcmdl--;
  3581. if (m->mdmreg[REG_ECHO] & BIT_ECHO)
  3582. isdn_tty_at_cout("\b", info);
  3583. }
  3584. continue;
  3585. }
  3586. if (cmdchar(c)) {
  3587. if (m->mdmreg[REG_ECHO] & BIT_ECHO) {
  3588. eb[0] = c;
  3589. eb[1] = 0;
  3590. isdn_tty_at_cout(eb, info);
  3591. }
  3592. if (m->mdmcmdl < 255) {
  3593. c = my_toupper(c);
  3594. switch (m->mdmcmdl) {
  3595. case 1:
  3596. if (c == 'T') {
  3597. m->mdmcmd[m->mdmcmdl] = c;
  3598. m->mdmcmd[++m->mdmcmdl] = 0;
  3599. break;
  3600. } else
  3601. m->mdmcmdl = 0;
  3602. /* Fall through, check for 'A' */
  3603. case 0:
  3604. if (c == 'A') {
  3605. m->mdmcmd[m->mdmcmdl] = c;
  3606. m->mdmcmd[++m->mdmcmdl] = 0;
  3607. }
  3608. break;
  3609. default:
  3610. m->mdmcmd[m->mdmcmdl] = c;
  3611. m->mdmcmd[++m->mdmcmdl] = 0;
  3612. }
  3613. }
  3614. }
  3615. }
  3616. return total;
  3617. }
  3618. /*
  3619. * Switch all modem-channels who are online and got a valid
  3620. * escape-sequence 1.5 seconds ago, to command-mode.
  3621. * This function is called every second via timer-interrupt from within
  3622. * timer-dispatcher isdn_timer_function()
  3623. */
  3624. void
  3625. isdn_tty_modem_escape(void)
  3626. {
  3627. int ton = 0;
  3628. int i;
  3629. int midx;
  3630. for (i = 0; i < ISDN_MAX_CHANNELS; i++)
  3631. if (USG_MODEM(dev->usage[i]))
  3632. if ((midx = dev->m_idx[i]) >= 0) {
  3633. modem_info *info = &dev->mdm.info[midx];
  3634. if (info->online) {
  3635. ton = 1;
  3636. if ((info->emu.pluscount == 3) &&
  3637. time_after(jiffies , info->emu.lastplus + PLUSWAIT2)) {
  3638. info->emu.pluscount = 0;
  3639. info->online = 0;
  3640. isdn_tty_modem_result(RESULT_OK, info);
  3641. }
  3642. }
  3643. }
  3644. isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton);
  3645. }
  3646. /*
  3647. * Put a RING-message to all modem-channels who have the RI-bit set.
  3648. * This function is called every second via timer-interrupt from within
  3649. * timer-dispatcher isdn_timer_function()
  3650. */
  3651. void
  3652. isdn_tty_modem_ring(void)
  3653. {
  3654. int ton = 0;
  3655. int i;
  3656. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  3657. modem_info *info = &dev->mdm.info[i];
  3658. if (info->msr & UART_MSR_RI) {
  3659. ton = 1;
  3660. isdn_tty_modem_result(RESULT_RING, info);
  3661. }
  3662. }
  3663. isdn_timer_ctrl(ISDN_TIMER_MODEMRING, ton);
  3664. }
  3665. /*
  3666. * For all online tty's, try sending data to
  3667. * the lower levels.
  3668. */
  3669. void
  3670. isdn_tty_modem_xmit(void)
  3671. {
  3672. int ton = 1;
  3673. int i;
  3674. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  3675. modem_info *info = &dev->mdm.info[i];
  3676. if (info->online) {
  3677. ton = 1;
  3678. isdn_tty_senddown(info);
  3679. isdn_tty_tint(info);
  3680. }
  3681. }
  3682. isdn_timer_ctrl(ISDN_TIMER_MODEMXMIT, ton);
  3683. }
  3684. /*
  3685. * Check all channels if we have a 'no carrier' timeout.
  3686. * Timeout value is set by Register S7.
  3687. */
  3688. void
  3689. isdn_tty_carrier_timeout(void)
  3690. {
  3691. int ton = 0;
  3692. int i;
  3693. for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
  3694. modem_info *info = &dev->mdm.info[i];
  3695. if (info->dialing) {
  3696. if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) {
  3697. info->dialing = 0;
  3698. isdn_tty_modem_result(RESULT_NO_CARRIER, info);
  3699. isdn_tty_modem_hup(info, 1);
  3700. }
  3701. else
  3702. ton = 1;
  3703. }
  3704. }
  3705. isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton);
  3706. }