isdn_tty.c 89 KB

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