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