isdn_net.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206
  1. /* $Id: isdn_net.c,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
  2. *
  3. * Linux ISDN subsystem, network interfaces and related functions (linklevel).
  4. *
  5. * Copyright 1994-1998 by Fritz Elfert (fritz@isdn4linux.de)
  6. * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
  7. * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. * Data Over Voice (DOV) support added - Guy Ellis 23-Mar-02
  13. * guy@traverse.com.au
  14. * Outgoing calls - looks for a 'V' in first char of dialed number
  15. * Incoming calls - checks first character of eaz as follows:
  16. * Numeric - accept DATA only - original functionality
  17. * 'V' - accept VOICE (DOV) only
  18. * 'B' - accept BOTH DATA and DOV types
  19. *
  20. * Jan 2001: fix CISCO HDLC Bjoern A. Zeeb <i4l@zabbadoz.net>
  21. * for info on the protocol, see
  22. * http://i4l.zabbadoz.net/i4l/cisco-hdlc.txt
  23. */
  24. #include <linux/isdn.h>
  25. #include <net/arp.h>
  26. #include <net/dst.h>
  27. #include <net/pkt_sched.h>
  28. #include <linux/inetdevice.h>
  29. #include "isdn_common.h"
  30. #include "isdn_net.h"
  31. #ifdef CONFIG_ISDN_PPP
  32. #include "isdn_ppp.h"
  33. #endif
  34. #ifdef CONFIG_ISDN_X25
  35. #include <linux/concap.h>
  36. #include "isdn_concap.h"
  37. #endif
  38. /*
  39. * Outline of new tbusy handling:
  40. *
  41. * Old method, roughly spoken, consisted of setting tbusy when entering
  42. * isdn_net_start_xmit() and at several other locations and clearing
  43. * it from isdn_net_start_xmit() thread when sending was successful.
  44. *
  45. * With 2.3.x multithreaded network core, to prevent problems, tbusy should
  46. * only be set by the isdn_net_start_xmit() thread and only when a tx-busy
  47. * condition is detected. Other threads (in particular isdn_net_stat_callb())
  48. * are only allowed to clear tbusy.
  49. *
  50. * -HE
  51. */
  52. /*
  53. * About SOFTNET:
  54. * Most of the changes were pretty obvious and basically done by HE already.
  55. *
  56. * One problem of the isdn net device code is that is uses struct net_device
  57. * for masters and slaves. However, only master interface are registered to
  58. * the network layer, and therefore, it only makes sense to call netif_*
  59. * functions on them.
  60. *
  61. * --KG
  62. */
  63. /*
  64. * Find out if the netdevice has been ifup-ed yet.
  65. * For slaves, look at the corresponding master.
  66. */
  67. static __inline__ int isdn_net_device_started(isdn_net_dev *n)
  68. {
  69. isdn_net_local *lp = n->local;
  70. struct net_device *dev;
  71. if (lp->master)
  72. dev = lp->master;
  73. else
  74. dev = n->dev;
  75. return netif_running(dev);
  76. }
  77. /*
  78. * wake up the network -> net_device queue.
  79. * For slaves, wake the corresponding master interface.
  80. */
  81. static __inline__ void isdn_net_device_wake_queue(isdn_net_local *lp)
  82. {
  83. if (lp->master)
  84. netif_wake_queue(lp->master);
  85. else
  86. netif_wake_queue(lp->netdev->dev);
  87. }
  88. /*
  89. * stop the network -> net_device queue.
  90. * For slaves, stop the corresponding master interface.
  91. */
  92. static __inline__ void isdn_net_device_stop_queue(isdn_net_local *lp)
  93. {
  94. if (lp->master)
  95. netif_stop_queue(lp->master);
  96. else
  97. netif_stop_queue(lp->netdev->dev);
  98. }
  99. /*
  100. * find out if the net_device which this lp belongs to (lp can be
  101. * master or slave) is busy. It's busy iff all (master and slave)
  102. * queues are busy
  103. */
  104. static __inline__ int isdn_net_device_busy(isdn_net_local *lp)
  105. {
  106. isdn_net_local *nlp;
  107. isdn_net_dev *nd;
  108. unsigned long flags;
  109. if (!isdn_net_lp_busy(lp))
  110. return 0;
  111. if (lp->master)
  112. nd = ISDN_MASTER_PRIV(lp)->netdev;
  113. else
  114. nd = lp->netdev;
  115. spin_lock_irqsave(&nd->queue_lock, flags);
  116. nlp = lp->next;
  117. while (nlp != lp) {
  118. if (!isdn_net_lp_busy(nlp)) {
  119. spin_unlock_irqrestore(&nd->queue_lock, flags);
  120. return 0;
  121. }
  122. nlp = nlp->next;
  123. }
  124. spin_unlock_irqrestore(&nd->queue_lock, flags);
  125. return 1;
  126. }
  127. static __inline__ void isdn_net_inc_frame_cnt(isdn_net_local *lp)
  128. {
  129. atomic_inc(&lp->frame_cnt);
  130. if (isdn_net_device_busy(lp))
  131. isdn_net_device_stop_queue(lp);
  132. }
  133. static __inline__ void isdn_net_dec_frame_cnt(isdn_net_local *lp)
  134. {
  135. atomic_dec(&lp->frame_cnt);
  136. if (!(isdn_net_device_busy(lp))) {
  137. if (!skb_queue_empty(&lp->super_tx_queue)) {
  138. schedule_work(&lp->tqueue);
  139. } else {
  140. isdn_net_device_wake_queue(lp);
  141. }
  142. }
  143. }
  144. static __inline__ void isdn_net_zero_frame_cnt(isdn_net_local *lp)
  145. {
  146. atomic_set(&lp->frame_cnt, 0);
  147. }
  148. /* For 2.2.x we leave the transmitter busy timeout at 2 secs, just
  149. * to be safe.
  150. * For 2.3.x we push it up to 20 secs, because call establishment
  151. * (in particular callback) may take such a long time, and we
  152. * don't want confusing messages in the log. However, there is a slight
  153. * possibility that this large timeout will break other things like MPPP,
  154. * which might rely on the tx timeout. If so, we'll find out this way...
  155. */
  156. #define ISDN_NET_TX_TIMEOUT (20*HZ)
  157. /* Prototypes */
  158. static int isdn_net_force_dial_lp(isdn_net_local *);
  159. static int isdn_net_start_xmit(struct sk_buff *, struct net_device *);
  160. static void isdn_net_ciscohdlck_connected(isdn_net_local *lp);
  161. static void isdn_net_ciscohdlck_disconnected(isdn_net_local *lp);
  162. char *isdn_net_revision = "$Revision: 1.1.2.2 $";
  163. /*
  164. * Code for raw-networking over ISDN
  165. */
  166. static void
  167. isdn_net_unreachable(struct net_device *dev, struct sk_buff *skb, char *reason)
  168. {
  169. if(skb) {
  170. u_short proto = ntohs(skb->protocol);
  171. printk(KERN_DEBUG "isdn_net: %s: %s, signalling dst_link_failure %s\n",
  172. dev->name,
  173. (reason != NULL) ? reason : "unknown",
  174. (proto != ETH_P_IP) ? "Protocol != ETH_P_IP" : "");
  175. dst_link_failure(skb);
  176. }
  177. else { /* dial not triggered by rawIP packet */
  178. printk(KERN_DEBUG "isdn_net: %s: %s\n",
  179. dev->name,
  180. (reason != NULL) ? reason : "reason unknown");
  181. }
  182. }
  183. static void
  184. isdn_net_reset(struct net_device *dev)
  185. {
  186. #ifdef CONFIG_ISDN_X25
  187. struct concap_device_ops * dops =
  188. ((isdn_net_local *) netdev_priv(dev))->dops;
  189. struct concap_proto * cprot =
  190. ((isdn_net_local *) netdev_priv(dev))->netdev->cprot;
  191. #endif
  192. #ifdef CONFIG_ISDN_X25
  193. if( cprot && cprot -> pops && dops )
  194. cprot -> pops -> restart ( cprot, dev, dops );
  195. #endif
  196. }
  197. /* Open/initialize the board. */
  198. static int
  199. isdn_net_open(struct net_device *dev)
  200. {
  201. int i;
  202. struct net_device *p;
  203. struct in_device *in_dev;
  204. /* moved here from isdn_net_reset, because only the master has an
  205. interface associated which is supposed to be started. BTW:
  206. we need to call netif_start_queue, not netif_wake_queue here */
  207. netif_start_queue(dev);
  208. isdn_net_reset(dev);
  209. /* Fill in the MAC-level header (not needed, but for compatibility... */
  210. for (i = 0; i < ETH_ALEN - sizeof(u32); i++)
  211. dev->dev_addr[i] = 0xfc;
  212. if ((in_dev = dev->ip_ptr) != NULL) {
  213. /*
  214. * Any address will do - we take the first
  215. */
  216. struct in_ifaddr *ifa = in_dev->ifa_list;
  217. if (ifa != NULL)
  218. memcpy(dev->dev_addr+2, &ifa->ifa_local, 4);
  219. }
  220. /* If this interface has slaves, start them also */
  221. p = MASTER_TO_SLAVE(dev);
  222. if (p) {
  223. while (p) {
  224. isdn_net_reset(p);
  225. p = MASTER_TO_SLAVE(p);
  226. }
  227. }
  228. isdn_lock_drivers();
  229. return 0;
  230. }
  231. /*
  232. * Assign an ISDN-channel to a net-interface
  233. */
  234. static void
  235. isdn_net_bind_channel(isdn_net_local * lp, int idx)
  236. {
  237. lp->flags |= ISDN_NET_CONNECTED;
  238. lp->isdn_device = dev->drvmap[idx];
  239. lp->isdn_channel = dev->chanmap[idx];
  240. dev->rx_netdev[idx] = lp->netdev;
  241. dev->st_netdev[idx] = lp->netdev;
  242. }
  243. /*
  244. * unbind a net-interface (resets interface after an error)
  245. */
  246. static void
  247. isdn_net_unbind_channel(isdn_net_local * lp)
  248. {
  249. skb_queue_purge(&lp->super_tx_queue);
  250. if (!lp->master) { /* reset only master device */
  251. /* Moral equivalent of dev_purge_queues():
  252. BEWARE! This chunk of code cannot be called from hardware
  253. interrupt handler. I hope it is true. --ANK
  254. */
  255. qdisc_reset_all_tx(lp->netdev->dev);
  256. }
  257. lp->dialstate = 0;
  258. dev->rx_netdev[isdn_dc2minor(lp->isdn_device, lp->isdn_channel)] = NULL;
  259. dev->st_netdev[isdn_dc2minor(lp->isdn_device, lp->isdn_channel)] = NULL;
  260. isdn_free_channel(lp->isdn_device, lp->isdn_channel, ISDN_USAGE_NET);
  261. lp->flags &= ~ISDN_NET_CONNECTED;
  262. lp->isdn_device = -1;
  263. lp->isdn_channel = -1;
  264. }
  265. /*
  266. * Perform auto-hangup and cps-calculation for net-interfaces.
  267. *
  268. * auto-hangup:
  269. * Increment idle-counter (this counter is reset on any incoming or
  270. * outgoing packet), if counter exceeds configured limit either do a
  271. * hangup immediately or - if configured - wait until just before the next
  272. * charge-info.
  273. *
  274. * cps-calculation (needed for dynamic channel-bundling):
  275. * Since this function is called every second, simply reset the
  276. * byte-counter of the interface after copying it to the cps-variable.
  277. */
  278. static unsigned long last_jiffies = -HZ;
  279. void
  280. isdn_net_autohup(void)
  281. {
  282. isdn_net_dev *p = dev->netdev;
  283. int anymore;
  284. anymore = 0;
  285. while (p) {
  286. isdn_net_local *l = p->local;
  287. if (jiffies == last_jiffies)
  288. l->cps = l->transcount;
  289. else
  290. l->cps = (l->transcount * HZ) / (jiffies - last_jiffies);
  291. l->transcount = 0;
  292. if (dev->net_verbose > 3)
  293. printk(KERN_DEBUG "%s: %d bogocps\n", p->dev->name, l->cps);
  294. if ((l->flags & ISDN_NET_CONNECTED) && (!l->dialstate)) {
  295. anymore = 1;
  296. l->huptimer++;
  297. /*
  298. * if there is some dialmode where timeout-hangup
  299. * should _not_ be done, check for that here
  300. */
  301. if ((l->onhtime) &&
  302. (l->huptimer > l->onhtime))
  303. {
  304. if (l->hupflags & ISDN_MANCHARGE &&
  305. l->hupflags & ISDN_CHARGEHUP) {
  306. while (time_after(jiffies, l->chargetime + l->chargeint))
  307. l->chargetime += l->chargeint;
  308. if (time_after(jiffies, l->chargetime + l->chargeint - 2 * HZ))
  309. if (l->outgoing || l->hupflags & ISDN_INHUP)
  310. isdn_net_hangup(p->dev);
  311. } else if (l->outgoing) {
  312. if (l->hupflags & ISDN_CHARGEHUP) {
  313. if (l->hupflags & ISDN_WAITCHARGE) {
  314. printk(KERN_DEBUG "isdn_net: Hupflags of %s are %X\n",
  315. p->dev->name, l->hupflags);
  316. isdn_net_hangup(p->dev);
  317. } else if (time_after(jiffies, l->chargetime + l->chargeint)) {
  318. printk(KERN_DEBUG
  319. "isdn_net: %s: chtime = %lu, chint = %d\n",
  320. p->dev->name, l->chargetime, l->chargeint);
  321. isdn_net_hangup(p->dev);
  322. }
  323. } else
  324. isdn_net_hangup(p->dev);
  325. } else if (l->hupflags & ISDN_INHUP)
  326. isdn_net_hangup(p->dev);
  327. }
  328. if(dev->global_flags & ISDN_GLOBAL_STOPPED || (ISDN_NET_DIALMODE(*l) == ISDN_NET_DM_OFF)) {
  329. isdn_net_hangup(p->dev);
  330. break;
  331. }
  332. }
  333. p = (isdn_net_dev *) p->next;
  334. }
  335. last_jiffies = jiffies;
  336. isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, anymore);
  337. }
  338. static void isdn_net_lp_disconnected(isdn_net_local *lp)
  339. {
  340. isdn_net_rm_from_bundle(lp);
  341. }
  342. /*
  343. * Handle status-messages from ISDN-interfacecard.
  344. * This function is called from within the main-status-dispatcher
  345. * isdn_status_callback, which itself is called from the low-level driver.
  346. * Return: 1 = Event handled, 0 = not for us or unknown Event.
  347. */
  348. int
  349. isdn_net_stat_callback(int idx, isdn_ctrl *c)
  350. {
  351. isdn_net_dev *p = dev->st_netdev[idx];
  352. int cmd = c->command;
  353. if (p) {
  354. isdn_net_local *lp = p->local;
  355. #ifdef CONFIG_ISDN_X25
  356. struct concap_proto *cprot = lp->netdev->cprot;
  357. struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
  358. #endif
  359. switch (cmd) {
  360. case ISDN_STAT_BSENT:
  361. /* A packet has successfully been sent out */
  362. if ((lp->flags & ISDN_NET_CONNECTED) &&
  363. (!lp->dialstate)) {
  364. isdn_net_dec_frame_cnt(lp);
  365. lp->stats.tx_packets++;
  366. lp->stats.tx_bytes += c->parm.length;
  367. }
  368. return 1;
  369. case ISDN_STAT_DCONN:
  370. /* D-Channel is up */
  371. switch (lp->dialstate) {
  372. case 4:
  373. case 7:
  374. case 8:
  375. lp->dialstate++;
  376. return 1;
  377. case 12:
  378. lp->dialstate = 5;
  379. return 1;
  380. }
  381. break;
  382. case ISDN_STAT_DHUP:
  383. /* Either D-Channel-hangup or error during dialout */
  384. #ifdef CONFIG_ISDN_X25
  385. /* If we are not connencted then dialing had
  386. failed. If there are generic encap protocol
  387. receiver routines signal the closure of
  388. the link*/
  389. if( !(lp->flags & ISDN_NET_CONNECTED)
  390. && pops && pops -> disconn_ind )
  391. pops -> disconn_ind(cprot);
  392. #endif /* CONFIG_ISDN_X25 */
  393. if ((!lp->dialstate) && (lp->flags & ISDN_NET_CONNECTED)) {
  394. if (lp->p_encap == ISDN_NET_ENCAP_CISCOHDLCK)
  395. isdn_net_ciscohdlck_disconnected(lp);
  396. #ifdef CONFIG_ISDN_PPP
  397. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  398. isdn_ppp_free(lp);
  399. #endif
  400. isdn_net_lp_disconnected(lp);
  401. isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
  402. printk(KERN_INFO "%s: remote hangup\n", p->dev->name);
  403. printk(KERN_INFO "%s: Chargesum is %d\n", p->dev->name,
  404. lp->charge);
  405. isdn_net_unbind_channel(lp);
  406. return 1;
  407. }
  408. break;
  409. #ifdef CONFIG_ISDN_X25
  410. case ISDN_STAT_BHUP:
  411. /* B-Channel-hangup */
  412. /* try if there are generic encap protocol
  413. receiver routines and signal the closure of
  414. the link */
  415. if( pops && pops -> disconn_ind ){
  416. pops -> disconn_ind(cprot);
  417. return 1;
  418. }
  419. break;
  420. #endif /* CONFIG_ISDN_X25 */
  421. case ISDN_STAT_BCONN:
  422. /* B-Channel is up */
  423. isdn_net_zero_frame_cnt(lp);
  424. switch (lp->dialstate) {
  425. case 5:
  426. case 6:
  427. case 7:
  428. case 8:
  429. case 9:
  430. case 10:
  431. case 12:
  432. if (lp->dialstate <= 6) {
  433. dev->usage[idx] |= ISDN_USAGE_OUTGOING;
  434. isdn_info_update();
  435. } else
  436. dev->rx_netdev[idx] = p;
  437. lp->dialstate = 0;
  438. isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 1);
  439. if (lp->p_encap == ISDN_NET_ENCAP_CISCOHDLCK)
  440. isdn_net_ciscohdlck_connected(lp);
  441. if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP) {
  442. if (lp->master) { /* is lp a slave? */
  443. isdn_net_dev *nd = ISDN_MASTER_PRIV(lp)->netdev;
  444. isdn_net_add_to_bundle(nd, lp);
  445. }
  446. }
  447. printk(KERN_INFO "isdn_net: %s connected\n", p->dev->name);
  448. /* If first Chargeinfo comes before B-Channel connect,
  449. * we correct the timestamp here.
  450. */
  451. lp->chargetime = jiffies;
  452. /* reset dial-timeout */
  453. lp->dialstarted = 0;
  454. lp->dialwait_timer = 0;
  455. #ifdef CONFIG_ISDN_PPP
  456. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  457. isdn_ppp_wakeup_daemon(lp);
  458. #endif
  459. #ifdef CONFIG_ISDN_X25
  460. /* try if there are generic concap receiver routines */
  461. if( pops )
  462. if( pops->connect_ind)
  463. pops->connect_ind(cprot);
  464. #endif /* CONFIG_ISDN_X25 */
  465. /* ppp needs to do negotiations first */
  466. if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP)
  467. isdn_net_device_wake_queue(lp);
  468. return 1;
  469. }
  470. break;
  471. case ISDN_STAT_NODCH:
  472. /* No D-Channel avail. */
  473. if (lp->dialstate == 4) {
  474. lp->dialstate--;
  475. return 1;
  476. }
  477. break;
  478. case ISDN_STAT_CINF:
  479. /* Charge-info from TelCo. Calculate interval between
  480. * charge-infos and set timestamp for last info for
  481. * usage by isdn_net_autohup()
  482. */
  483. lp->charge++;
  484. if (lp->hupflags & ISDN_HAVECHARGE) {
  485. lp->hupflags &= ~ISDN_WAITCHARGE;
  486. lp->chargeint = jiffies - lp->chargetime - (2 * HZ);
  487. }
  488. if (lp->hupflags & ISDN_WAITCHARGE)
  489. lp->hupflags |= ISDN_HAVECHARGE;
  490. lp->chargetime = jiffies;
  491. printk(KERN_DEBUG "isdn_net: Got CINF chargetime of %s now %lu\n",
  492. p->dev->name, lp->chargetime);
  493. return 1;
  494. }
  495. }
  496. return 0;
  497. }
  498. /*
  499. * Perform dialout for net-interfaces and timeout-handling for
  500. * D-Channel-up and B-Channel-up Messages.
  501. * This function is initially called from within isdn_net_start_xmit() or
  502. * or isdn_net_find_icall() after initializing the dialstate for an
  503. * interface. If further calls are needed, the function schedules itself
  504. * for a timer-callback via isdn_timer_function().
  505. * The dialstate is also affected by incoming status-messages from
  506. * the ISDN-Channel which are handled in isdn_net_stat_callback() above.
  507. */
  508. void
  509. isdn_net_dial(void)
  510. {
  511. isdn_net_dev *p = dev->netdev;
  512. int anymore = 0;
  513. int i;
  514. isdn_ctrl cmd;
  515. u_char *phone_number;
  516. while (p) {
  517. isdn_net_local *lp = p->local;
  518. #ifdef ISDN_DEBUG_NET_DIAL
  519. if (lp->dialstate)
  520. printk(KERN_DEBUG "%s: dialstate=%d\n", p->dev->name, lp->dialstate);
  521. #endif
  522. switch (lp->dialstate) {
  523. case 0:
  524. /* Nothing to do for this interface */
  525. break;
  526. case 1:
  527. /* Initiate dialout. Set phone-number-pointer to first number
  528. * of interface.
  529. */
  530. lp->dial = lp->phone[1];
  531. if (!lp->dial) {
  532. printk(KERN_WARNING "%s: phone number deleted?\n",
  533. p->dev->name);
  534. isdn_net_hangup(p->dev);
  535. break;
  536. }
  537. anymore = 1;
  538. if(lp->dialtimeout > 0)
  539. if(lp->dialstarted == 0 || time_after(jiffies, lp->dialstarted + lp->dialtimeout + lp->dialwait)) {
  540. lp->dialstarted = jiffies;
  541. lp->dialwait_timer = 0;
  542. }
  543. lp->dialstate++;
  544. /* Fall through */
  545. case 2:
  546. /* Prepare dialing. Clear EAZ, then set EAZ. */
  547. cmd.driver = lp->isdn_device;
  548. cmd.arg = lp->isdn_channel;
  549. cmd.command = ISDN_CMD_CLREAZ;
  550. isdn_command(&cmd);
  551. sprintf(cmd.parm.num, "%s", isdn_map_eaz2msn(lp->msn, cmd.driver));
  552. cmd.command = ISDN_CMD_SETEAZ;
  553. isdn_command(&cmd);
  554. lp->dialretry = 0;
  555. anymore = 1;
  556. lp->dialstate++;
  557. /* Fall through */
  558. case 3:
  559. /* Setup interface, dial current phone-number, switch to next number.
  560. * If list of phone-numbers is exhausted, increment
  561. * retry-counter.
  562. */
  563. if(dev->global_flags & ISDN_GLOBAL_STOPPED || (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF)) {
  564. char *s;
  565. if (dev->global_flags & ISDN_GLOBAL_STOPPED)
  566. s = "dial suppressed: isdn system stopped";
  567. else
  568. s = "dial suppressed: dialmode `off'";
  569. isdn_net_unreachable(p->dev, NULL, s);
  570. isdn_net_hangup(p->dev);
  571. break;
  572. }
  573. cmd.driver = lp->isdn_device;
  574. cmd.command = ISDN_CMD_SETL2;
  575. cmd.arg = lp->isdn_channel + (lp->l2_proto << 8);
  576. isdn_command(&cmd);
  577. cmd.driver = lp->isdn_device;
  578. cmd.command = ISDN_CMD_SETL3;
  579. cmd.arg = lp->isdn_channel + (lp->l3_proto << 8);
  580. isdn_command(&cmd);
  581. cmd.driver = lp->isdn_device;
  582. cmd.arg = lp->isdn_channel;
  583. if (!lp->dial) {
  584. printk(KERN_WARNING "%s: phone number deleted?\n",
  585. p->dev->name);
  586. isdn_net_hangup(p->dev);
  587. break;
  588. }
  589. if (!strncmp(lp->dial->num, "LEASED", strlen("LEASED"))) {
  590. lp->dialstate = 4;
  591. printk(KERN_INFO "%s: Open leased line ...\n", p->dev->name);
  592. } else {
  593. if(lp->dialtimeout > 0)
  594. if (time_after(jiffies, lp->dialstarted + lp->dialtimeout)) {
  595. lp->dialwait_timer = jiffies + lp->dialwait;
  596. lp->dialstarted = 0;
  597. isdn_net_unreachable(p->dev, NULL, "dial: timed out");
  598. isdn_net_hangup(p->dev);
  599. break;
  600. }
  601. cmd.driver = lp->isdn_device;
  602. cmd.command = ISDN_CMD_DIAL;
  603. cmd.parm.setup.si2 = 0;
  604. /* check for DOV */
  605. phone_number = lp->dial->num;
  606. if ((*phone_number == 'v') ||
  607. (*phone_number == 'V')) { /* DOV call */
  608. cmd.parm.setup.si1 = 1;
  609. } else { /* DATA call */
  610. cmd.parm.setup.si1 = 7;
  611. }
  612. strcpy(cmd.parm.setup.phone, phone_number);
  613. /*
  614. * Switch to next number or back to start if at end of list.
  615. */
  616. if (!(lp->dial = (isdn_net_phone *) lp->dial->next)) {
  617. lp->dial = lp->phone[1];
  618. lp->dialretry++;
  619. if (lp->dialretry > lp->dialmax) {
  620. if (lp->dialtimeout == 0) {
  621. lp->dialwait_timer = jiffies + lp->dialwait;
  622. lp->dialstarted = 0;
  623. isdn_net_unreachable(p->dev, NULL, "dial: tried all numbers dialmax times");
  624. }
  625. isdn_net_hangup(p->dev);
  626. break;
  627. }
  628. }
  629. sprintf(cmd.parm.setup.eazmsn, "%s",
  630. isdn_map_eaz2msn(lp->msn, cmd.driver));
  631. i = isdn_dc2minor(lp->isdn_device, lp->isdn_channel);
  632. if (i >= 0) {
  633. strcpy(dev->num[i], cmd.parm.setup.phone);
  634. dev->usage[i] |= ISDN_USAGE_OUTGOING;
  635. isdn_info_update();
  636. }
  637. printk(KERN_INFO "%s: dialing %d %s... %s\n", p->dev->name,
  638. lp->dialretry, cmd.parm.setup.phone,
  639. (cmd.parm.setup.si1 == 1) ? "DOV" : "");
  640. lp->dtimer = 0;
  641. #ifdef ISDN_DEBUG_NET_DIAL
  642. printk(KERN_DEBUG "dial: d=%d c=%d\n", lp->isdn_device,
  643. lp->isdn_channel);
  644. #endif
  645. isdn_command(&cmd);
  646. }
  647. lp->huptimer = 0;
  648. lp->outgoing = 1;
  649. if (lp->chargeint) {
  650. lp->hupflags |= ISDN_HAVECHARGE;
  651. lp->hupflags &= ~ISDN_WAITCHARGE;
  652. } else {
  653. lp->hupflags |= ISDN_WAITCHARGE;
  654. lp->hupflags &= ~ISDN_HAVECHARGE;
  655. }
  656. anymore = 1;
  657. lp->dialstate =
  658. (lp->cbdelay &&
  659. (lp->flags & ISDN_NET_CBOUT)) ? 12 : 4;
  660. break;
  661. case 4:
  662. /* Wait for D-Channel-connect.
  663. * If timeout, switch back to state 3.
  664. * Dialmax-handling moved to state 3.
  665. */
  666. if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
  667. lp->dialstate = 3;
  668. anymore = 1;
  669. break;
  670. case 5:
  671. /* Got D-Channel-Connect, send B-Channel-request */
  672. cmd.driver = lp->isdn_device;
  673. cmd.arg = lp->isdn_channel;
  674. cmd.command = ISDN_CMD_ACCEPTB;
  675. anymore = 1;
  676. lp->dtimer = 0;
  677. lp->dialstate++;
  678. isdn_command(&cmd);
  679. break;
  680. case 6:
  681. /* Wait for B- or D-Channel-connect. If timeout,
  682. * switch back to state 3.
  683. */
  684. #ifdef ISDN_DEBUG_NET_DIAL
  685. printk(KERN_DEBUG "dialtimer2: %d\n", lp->dtimer);
  686. #endif
  687. if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
  688. lp->dialstate = 3;
  689. anymore = 1;
  690. break;
  691. case 7:
  692. /* Got incoming Call, setup L2 and L3 protocols,
  693. * then wait for D-Channel-connect
  694. */
  695. #ifdef ISDN_DEBUG_NET_DIAL
  696. printk(KERN_DEBUG "dialtimer4: %d\n", lp->dtimer);
  697. #endif
  698. cmd.driver = lp->isdn_device;
  699. cmd.command = ISDN_CMD_SETL2;
  700. cmd.arg = lp->isdn_channel + (lp->l2_proto << 8);
  701. isdn_command(&cmd);
  702. cmd.driver = lp->isdn_device;
  703. cmd.command = ISDN_CMD_SETL3;
  704. cmd.arg = lp->isdn_channel + (lp->l3_proto << 8);
  705. isdn_command(&cmd);
  706. if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT15)
  707. isdn_net_hangup(p->dev);
  708. else {
  709. anymore = 1;
  710. lp->dialstate++;
  711. }
  712. break;
  713. case 9:
  714. /* Got incoming D-Channel-Connect, send B-Channel-request */
  715. cmd.driver = lp->isdn_device;
  716. cmd.arg = lp->isdn_channel;
  717. cmd.command = ISDN_CMD_ACCEPTB;
  718. isdn_command(&cmd);
  719. anymore = 1;
  720. lp->dtimer = 0;
  721. lp->dialstate++;
  722. break;
  723. case 8:
  724. case 10:
  725. /* Wait for B- or D-channel-connect */
  726. #ifdef ISDN_DEBUG_NET_DIAL
  727. printk(KERN_DEBUG "dialtimer4: %d\n", lp->dtimer);
  728. #endif
  729. if (lp->dtimer++ > ISDN_TIMER_DTIMEOUT10)
  730. isdn_net_hangup(p->dev);
  731. else
  732. anymore = 1;
  733. break;
  734. case 11:
  735. /* Callback Delay */
  736. if (lp->dtimer++ > lp->cbdelay)
  737. lp->dialstate = 1;
  738. anymore = 1;
  739. break;
  740. case 12:
  741. /* Remote does callback. Hangup after cbdelay, then wait for incoming
  742. * call (in state 4).
  743. */
  744. if (lp->dtimer++ > lp->cbdelay)
  745. {
  746. printk(KERN_INFO "%s: hangup waiting for callback ...\n", p->dev->name);
  747. lp->dtimer = 0;
  748. lp->dialstate = 4;
  749. cmd.driver = lp->isdn_device;
  750. cmd.command = ISDN_CMD_HANGUP;
  751. cmd.arg = lp->isdn_channel;
  752. isdn_command(&cmd);
  753. isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
  754. }
  755. anymore = 1;
  756. break;
  757. default:
  758. printk(KERN_WARNING "isdn_net: Illegal dialstate %d for device %s\n",
  759. lp->dialstate, p->dev->name);
  760. }
  761. p = (isdn_net_dev *) p->next;
  762. }
  763. isdn_timer_ctrl(ISDN_TIMER_NETDIAL, anymore);
  764. }
  765. /*
  766. * Perform hangup for a net-interface.
  767. */
  768. void
  769. isdn_net_hangup(struct net_device *d)
  770. {
  771. isdn_net_local *lp = (isdn_net_local *) netdev_priv(d);
  772. isdn_ctrl cmd;
  773. #ifdef CONFIG_ISDN_X25
  774. struct concap_proto *cprot = lp->netdev->cprot;
  775. struct concap_proto_ops *pops = cprot ? cprot->pops : NULL;
  776. #endif
  777. if (lp->flags & ISDN_NET_CONNECTED) {
  778. if (lp->slave != NULL) {
  779. isdn_net_local *slp = ISDN_SLAVE_PRIV(lp);
  780. if (slp->flags & ISDN_NET_CONNECTED) {
  781. printk(KERN_INFO
  782. "isdn_net: hang up slave %s before %s\n",
  783. lp->slave->name, d->name);
  784. isdn_net_hangup(lp->slave);
  785. }
  786. }
  787. printk(KERN_INFO "isdn_net: local hangup %s\n", d->name);
  788. #ifdef CONFIG_ISDN_PPP
  789. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  790. isdn_ppp_free(lp);
  791. #endif
  792. isdn_net_lp_disconnected(lp);
  793. #ifdef CONFIG_ISDN_X25
  794. /* try if there are generic encap protocol
  795. receiver routines and signal the closure of
  796. the link */
  797. if( pops && pops -> disconn_ind )
  798. pops -> disconn_ind(cprot);
  799. #endif /* CONFIG_ISDN_X25 */
  800. cmd.driver = lp->isdn_device;
  801. cmd.command = ISDN_CMD_HANGUP;
  802. cmd.arg = lp->isdn_channel;
  803. isdn_command(&cmd);
  804. printk(KERN_INFO "%s: Chargesum is %d\n", d->name, lp->charge);
  805. isdn_all_eaz(lp->isdn_device, lp->isdn_channel);
  806. }
  807. isdn_net_unbind_channel(lp);
  808. }
  809. typedef struct {
  810. __be16 source;
  811. __be16 dest;
  812. } ip_ports;
  813. static void
  814. isdn_net_log_skb(struct sk_buff * skb, isdn_net_local * lp)
  815. {
  816. /* hopefully, this was set correctly */
  817. const u_char *p = skb_network_header(skb);
  818. unsigned short proto = ntohs(skb->protocol);
  819. int data_ofs;
  820. ip_ports *ipp;
  821. char addinfo[100];
  822. addinfo[0] = '\0';
  823. /* This check stolen from 2.1.72 dev_queue_xmit_nit() */
  824. if (p < skb->data || skb->network_header >= skb->tail) {
  825. /* fall back to old isdn_net_log_packet method() */
  826. char * buf = skb->data;
  827. printk(KERN_DEBUG "isdn_net: protocol %04x is buggy, dev %s\n", skb->protocol, lp->netdev->dev->name);
  828. p = buf;
  829. proto = ETH_P_IP;
  830. switch (lp->p_encap) {
  831. case ISDN_NET_ENCAP_IPTYP:
  832. proto = ntohs(*(__be16 *)&buf[0]);
  833. p = &buf[2];
  834. break;
  835. case ISDN_NET_ENCAP_ETHER:
  836. proto = ntohs(*(__be16 *)&buf[12]);
  837. p = &buf[14];
  838. break;
  839. case ISDN_NET_ENCAP_CISCOHDLC:
  840. proto = ntohs(*(__be16 *)&buf[2]);
  841. p = &buf[4];
  842. break;
  843. #ifdef CONFIG_ISDN_PPP
  844. case ISDN_NET_ENCAP_SYNCPPP:
  845. proto = ntohs(skb->protocol);
  846. p = &buf[IPPP_MAX_HEADER];
  847. break;
  848. #endif
  849. }
  850. }
  851. data_ofs = ((p[0] & 15) * 4);
  852. switch (proto) {
  853. case ETH_P_IP:
  854. switch (p[9]) {
  855. case 1:
  856. strcpy(addinfo, " ICMP");
  857. break;
  858. case 2:
  859. strcpy(addinfo, " IGMP");
  860. break;
  861. case 4:
  862. strcpy(addinfo, " IPIP");
  863. break;
  864. case 6:
  865. ipp = (ip_ports *) (&p[data_ofs]);
  866. sprintf(addinfo, " TCP, port: %d -> %d", ntohs(ipp->source),
  867. ntohs(ipp->dest));
  868. break;
  869. case 8:
  870. strcpy(addinfo, " EGP");
  871. break;
  872. case 12:
  873. strcpy(addinfo, " PUP");
  874. break;
  875. case 17:
  876. ipp = (ip_ports *) (&p[data_ofs]);
  877. sprintf(addinfo, " UDP, port: %d -> %d", ntohs(ipp->source),
  878. ntohs(ipp->dest));
  879. break;
  880. case 22:
  881. strcpy(addinfo, " IDP");
  882. break;
  883. }
  884. printk(KERN_INFO "OPEN: %pI4 -> %pI4%s\n",
  885. p + 12, p + 16, addinfo);
  886. break;
  887. case ETH_P_ARP:
  888. printk(KERN_INFO "OPEN: ARP %pI4 -> *.*.*.* ?%pI4\n",
  889. p + 14, p + 24);
  890. break;
  891. }
  892. }
  893. /*
  894. * this function is used to send supervisory data, i.e. data which was
  895. * not received from the network layer, but e.g. frames from ipppd, CCP
  896. * reset frames etc.
  897. */
  898. void isdn_net_write_super(isdn_net_local *lp, struct sk_buff *skb)
  899. {
  900. if (in_irq()) {
  901. // we can't grab the lock from irq context,
  902. // so we just queue the packet
  903. skb_queue_tail(&lp->super_tx_queue, skb);
  904. schedule_work(&lp->tqueue);
  905. return;
  906. }
  907. spin_lock_bh(&lp->xmit_lock);
  908. if (!isdn_net_lp_busy(lp)) {
  909. isdn_net_writebuf_skb(lp, skb);
  910. } else {
  911. skb_queue_tail(&lp->super_tx_queue, skb);
  912. }
  913. spin_unlock_bh(&lp->xmit_lock);
  914. }
  915. /*
  916. * called from tq_immediate
  917. */
  918. static void isdn_net_softint(struct work_struct *work)
  919. {
  920. isdn_net_local *lp = container_of(work, isdn_net_local, tqueue);
  921. struct sk_buff *skb;
  922. spin_lock_bh(&lp->xmit_lock);
  923. while (!isdn_net_lp_busy(lp)) {
  924. skb = skb_dequeue(&lp->super_tx_queue);
  925. if (!skb)
  926. break;
  927. isdn_net_writebuf_skb(lp, skb);
  928. }
  929. spin_unlock_bh(&lp->xmit_lock);
  930. }
  931. /*
  932. * all frames sent from the (net) LL to a HL driver should go via this function
  933. * it's serialized by the caller holding the lp->xmit_lock spinlock
  934. */
  935. void isdn_net_writebuf_skb(isdn_net_local *lp, struct sk_buff *skb)
  936. {
  937. int ret;
  938. int len = skb->len; /* save len */
  939. /* before obtaining the lock the caller should have checked that
  940. the lp isn't busy */
  941. if (isdn_net_lp_busy(lp)) {
  942. printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
  943. goto error;
  944. }
  945. if (!(lp->flags & ISDN_NET_CONNECTED)) {
  946. printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
  947. goto error;
  948. }
  949. ret = isdn_writebuf_skb_stub(lp->isdn_device, lp->isdn_channel, 1, skb);
  950. if (ret != len) {
  951. /* we should never get here */
  952. printk(KERN_WARNING "%s: HL driver queue full\n", lp->netdev->dev->name);
  953. goto error;
  954. }
  955. lp->transcount += len;
  956. isdn_net_inc_frame_cnt(lp);
  957. return;
  958. error:
  959. dev_kfree_skb(skb);
  960. lp->stats.tx_errors++;
  961. }
  962. /*
  963. * Helper function for isdn_net_start_xmit.
  964. * When called, the connection is already established.
  965. * Based on cps-calculation, check if device is overloaded.
  966. * If so, and if a slave exists, trigger dialing for it.
  967. * If any slave is online, deliver packets using a simple round robin
  968. * scheme.
  969. *
  970. * Return: 0 on success, !0 on failure.
  971. */
  972. static int
  973. isdn_net_xmit(struct net_device *ndev, struct sk_buff *skb)
  974. {
  975. isdn_net_dev *nd;
  976. isdn_net_local *slp;
  977. isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
  978. int retv = 0;
  979. if (((isdn_net_local *) netdev_priv(ndev))->master) {
  980. printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
  981. dev_kfree_skb(skb);
  982. return 0;
  983. }
  984. /* For the other encaps the header has already been built */
  985. #ifdef CONFIG_ISDN_PPP
  986. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
  987. return isdn_ppp_xmit(skb, ndev);
  988. }
  989. #endif
  990. nd = ((isdn_net_local *) netdev_priv(ndev))->netdev;
  991. lp = isdn_net_get_locked_lp(nd);
  992. if (!lp) {
  993. printk(KERN_WARNING "%s: all channels busy - requeuing!\n", ndev->name);
  994. return 1;
  995. }
  996. /* we have our lp locked from now on */
  997. /* Reset hangup-timeout */
  998. lp->huptimer = 0; // FIXME?
  999. isdn_net_writebuf_skb(lp, skb);
  1000. spin_unlock_bh(&lp->xmit_lock);
  1001. /* the following stuff is here for backwards compatibility.
  1002. * in future, start-up and hangup of slaves (based on current load)
  1003. * should move to userspace and get based on an overall cps
  1004. * calculation
  1005. */
  1006. if (lp->cps > lp->triggercps) {
  1007. if (lp->slave) {
  1008. if (!lp->sqfull) {
  1009. /* First time overload: set timestamp only */
  1010. lp->sqfull = 1;
  1011. lp->sqfull_stamp = jiffies;
  1012. } else {
  1013. /* subsequent overload: if slavedelay exceeded, start dialing */
  1014. if (time_after(jiffies, lp->sqfull_stamp + lp->slavedelay)) {
  1015. slp = ISDN_SLAVE_PRIV(lp);
  1016. if (!(slp->flags & ISDN_NET_CONNECTED)) {
  1017. isdn_net_force_dial_lp(ISDN_SLAVE_PRIV(lp));
  1018. }
  1019. }
  1020. }
  1021. }
  1022. } else {
  1023. if (lp->sqfull && time_after(jiffies, lp->sqfull_stamp + lp->slavedelay + (10 * HZ))) {
  1024. lp->sqfull = 0;
  1025. }
  1026. /* this is a hack to allow auto-hangup for slaves on moderate loads */
  1027. nd->queue = nd->local;
  1028. }
  1029. return retv;
  1030. }
  1031. static void
  1032. isdn_net_adjust_hdr(struct sk_buff *skb, struct net_device *dev)
  1033. {
  1034. isdn_net_local *lp = (isdn_net_local *) netdev_priv(dev);
  1035. if (!skb)
  1036. return;
  1037. if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
  1038. const int pullsize = skb_network_offset(skb) - ETH_HLEN;
  1039. if (pullsize > 0) {
  1040. printk(KERN_DEBUG "isdn_net: Pull junk %d\n", pullsize);
  1041. skb_pull(skb, pullsize);
  1042. }
  1043. }
  1044. }
  1045. static void isdn_net_tx_timeout(struct net_device * ndev)
  1046. {
  1047. isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
  1048. printk(KERN_WARNING "isdn_tx_timeout dev %s dialstate %d\n", ndev->name, lp->dialstate);
  1049. if (!lp->dialstate){
  1050. lp->stats.tx_errors++;
  1051. /*
  1052. * There is a certain probability that this currently
  1053. * works at all because if we always wake up the interface,
  1054. * then upper layer will try to send the next packet
  1055. * immediately. And then, the old clean_up logic in the
  1056. * driver will hopefully continue to work as it used to do.
  1057. *
  1058. * This is rather primitive right know, we better should
  1059. * clean internal queues here, in particular for multilink and
  1060. * ppp, and reset HL driver's channel, too. --HE
  1061. *
  1062. * actually, this may not matter at all, because ISDN hardware
  1063. * should not see transmitter hangs at all IMO
  1064. * changed KERN_DEBUG to KERN_WARNING to find out if this is
  1065. * ever called --KG
  1066. */
  1067. }
  1068. ndev->trans_start = jiffies;
  1069. netif_wake_queue(ndev);
  1070. }
  1071. /*
  1072. * Try sending a packet.
  1073. * If this interface isn't connected to a ISDN-Channel, find a free channel,
  1074. * and start dialing.
  1075. */
  1076. static int
  1077. isdn_net_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  1078. {
  1079. isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
  1080. #ifdef CONFIG_ISDN_X25
  1081. struct concap_proto * cprot = lp -> netdev -> cprot;
  1082. /* At this point hard_start_xmit() passes control to the encapsulation
  1083. protocol (if present).
  1084. For X.25 auto-dialing is completly bypassed because:
  1085. - It does not conform with the semantics of a reliable datalink
  1086. service as needed by X.25 PLP.
  1087. - I don't want that the interface starts dialing when the network layer
  1088. sends a message which requests to disconnect the lapb link (or if it
  1089. sends any other message not resulting in data transmission).
  1090. Instead, dialing will be initiated by the encapsulation protocol entity
  1091. when a dl_establish request is received from the upper layer.
  1092. */
  1093. if (cprot && cprot -> pops) {
  1094. int ret = cprot -> pops -> encap_and_xmit ( cprot , skb);
  1095. if (ret)
  1096. netif_stop_queue(ndev);
  1097. return ret;
  1098. } else
  1099. #endif
  1100. /* auto-dialing xmit function */
  1101. {
  1102. #ifdef ISDN_DEBUG_NET_DUMP
  1103. u_char *buf;
  1104. #endif
  1105. isdn_net_adjust_hdr(skb, ndev);
  1106. #ifdef ISDN_DEBUG_NET_DUMP
  1107. buf = skb->data;
  1108. isdn_dumppkt("S:", buf, skb->len, 40);
  1109. #endif
  1110. if (!(lp->flags & ISDN_NET_CONNECTED)) {
  1111. int chi;
  1112. /* only do autodial if allowed by config */
  1113. if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) {
  1114. isdn_net_unreachable(ndev, skb, "dial rejected: interface not in dialmode `auto'");
  1115. dev_kfree_skb(skb);
  1116. return 0;
  1117. }
  1118. if (lp->phone[1]) {
  1119. ulong flags;
  1120. if(lp->dialwait_timer <= 0)
  1121. if(lp->dialstarted > 0 && lp->dialtimeout > 0 && time_before(jiffies, lp->dialstarted + lp->dialtimeout + lp->dialwait))
  1122. lp->dialwait_timer = lp->dialstarted + lp->dialtimeout + lp->dialwait;
  1123. if(lp->dialwait_timer > 0) {
  1124. if(time_before(jiffies, lp->dialwait_timer)) {
  1125. isdn_net_unreachable(ndev, skb, "dial rejected: retry-time not reached");
  1126. dev_kfree_skb(skb);
  1127. return 0;
  1128. } else
  1129. lp->dialwait_timer = 0;
  1130. }
  1131. /* Grab a free ISDN-Channel */
  1132. spin_lock_irqsave(&dev->lock, flags);
  1133. if (((chi =
  1134. isdn_get_free_channel(
  1135. ISDN_USAGE_NET,
  1136. lp->l2_proto,
  1137. lp->l3_proto,
  1138. lp->pre_device,
  1139. lp->pre_channel,
  1140. lp->msn)
  1141. ) < 0) &&
  1142. ((chi =
  1143. isdn_get_free_channel(
  1144. ISDN_USAGE_NET,
  1145. lp->l2_proto,
  1146. lp->l3_proto,
  1147. lp->pre_device,
  1148. lp->pre_channel^1,
  1149. lp->msn)
  1150. ) < 0)) {
  1151. spin_unlock_irqrestore(&dev->lock, flags);
  1152. isdn_net_unreachable(ndev, skb,
  1153. "No channel");
  1154. dev_kfree_skb(skb);
  1155. return 0;
  1156. }
  1157. /* Log packet, which triggered dialing */
  1158. if (dev->net_verbose)
  1159. isdn_net_log_skb(skb, lp);
  1160. lp->dialstate = 1;
  1161. /* Connect interface with channel */
  1162. isdn_net_bind_channel(lp, chi);
  1163. #ifdef CONFIG_ISDN_PPP
  1164. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
  1165. /* no 'first_skb' handling for syncPPP */
  1166. if (isdn_ppp_bind(lp) < 0) {
  1167. dev_kfree_skb(skb);
  1168. isdn_net_unbind_channel(lp);
  1169. spin_unlock_irqrestore(&dev->lock, flags);
  1170. return 0; /* STN (skb to nirvana) ;) */
  1171. }
  1172. #ifdef CONFIG_IPPP_FILTER
  1173. if (isdn_ppp_autodial_filter(skb, lp)) {
  1174. isdn_ppp_free(lp);
  1175. isdn_net_unbind_channel(lp);
  1176. spin_unlock_irqrestore(&dev->lock, flags);
  1177. isdn_net_unreachable(ndev, skb, "dial rejected: packet filtered");
  1178. dev_kfree_skb(skb);
  1179. return 0;
  1180. }
  1181. #endif
  1182. spin_unlock_irqrestore(&dev->lock, flags);
  1183. isdn_net_dial(); /* Initiate dialing */
  1184. netif_stop_queue(ndev);
  1185. return 1; /* let upper layer requeue skb packet */
  1186. }
  1187. #endif
  1188. /* Initiate dialing */
  1189. spin_unlock_irqrestore(&dev->lock, flags);
  1190. isdn_net_dial();
  1191. isdn_net_device_stop_queue(lp);
  1192. return 1;
  1193. } else {
  1194. isdn_net_unreachable(ndev, skb,
  1195. "No phone number");
  1196. dev_kfree_skb(skb);
  1197. return 0;
  1198. }
  1199. } else {
  1200. /* Device is connected to an ISDN channel */
  1201. ndev->trans_start = jiffies;
  1202. if (!lp->dialstate) {
  1203. /* ISDN connection is established, try sending */
  1204. int ret;
  1205. ret = (isdn_net_xmit(ndev, skb));
  1206. if(ret) netif_stop_queue(ndev);
  1207. return ret;
  1208. } else
  1209. netif_stop_queue(ndev);
  1210. }
  1211. }
  1212. return 1;
  1213. }
  1214. /*
  1215. * Shutdown a net-interface.
  1216. */
  1217. static int
  1218. isdn_net_close(struct net_device *dev)
  1219. {
  1220. struct net_device *p;
  1221. #ifdef CONFIG_ISDN_X25
  1222. struct concap_proto * cprot =
  1223. ((isdn_net_local *) netdev_priv(dev))->netdev->cprot;
  1224. /* printk(KERN_DEBUG "isdn_net_close %s\n" , dev-> name ); */
  1225. #endif
  1226. #ifdef CONFIG_ISDN_X25
  1227. if( cprot && cprot -> pops ) cprot -> pops -> close( cprot );
  1228. #endif
  1229. netif_stop_queue(dev);
  1230. p = MASTER_TO_SLAVE(dev);
  1231. if (p) {
  1232. /* If this interface has slaves, stop them also */
  1233. while (p) {
  1234. #ifdef CONFIG_ISDN_X25
  1235. cprot = ((isdn_net_local *) netdev_priv(p))
  1236. -> netdev -> cprot;
  1237. if( cprot && cprot -> pops )
  1238. cprot -> pops -> close( cprot );
  1239. #endif
  1240. isdn_net_hangup(p);
  1241. p = MASTER_TO_SLAVE(p);
  1242. }
  1243. }
  1244. isdn_net_hangup(dev);
  1245. isdn_unlock_drivers();
  1246. return 0;
  1247. }
  1248. /*
  1249. * Get statistics
  1250. */
  1251. static struct net_device_stats *
  1252. isdn_net_get_stats(struct net_device *dev)
  1253. {
  1254. isdn_net_local *lp = (isdn_net_local *) netdev_priv(dev);
  1255. return &lp->stats;
  1256. }
  1257. /* This is simply a copy from std. eth.c EXCEPT we pull ETH_HLEN
  1258. * instead of dev->hard_header_len off. This is done because the
  1259. * lowlevel-driver has already pulled off its stuff when we get
  1260. * here and this routine only gets called with p_encap == ETHER.
  1261. * Determine the packet's protocol ID. The rule here is that we
  1262. * assume 802.3 if the type field is short enough to be a length.
  1263. * This is normal practice and works for any 'now in use' protocol.
  1264. */
  1265. static __be16
  1266. isdn_net_type_trans(struct sk_buff *skb, struct net_device *dev)
  1267. {
  1268. struct ethhdr *eth;
  1269. unsigned char *rawp;
  1270. skb_reset_mac_header(skb);
  1271. skb_pull(skb, ETH_HLEN);
  1272. eth = eth_hdr(skb);
  1273. if (*eth->h_dest & 1) {
  1274. if (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
  1275. skb->pkt_type = PACKET_BROADCAST;
  1276. else
  1277. skb->pkt_type = PACKET_MULTICAST;
  1278. }
  1279. /*
  1280. * This ALLMULTI check should be redundant by 1.4
  1281. * so don't forget to remove it.
  1282. */
  1283. else if (dev->flags & (IFF_PROMISC /*| IFF_ALLMULTI*/)) {
  1284. if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
  1285. skb->pkt_type = PACKET_OTHERHOST;
  1286. }
  1287. if (ntohs(eth->h_proto) >= 1536)
  1288. return eth->h_proto;
  1289. rawp = skb->data;
  1290. /*
  1291. * This is a magic hack to spot IPX packets. Older Novell breaks
  1292. * the protocol design and runs IPX over 802.3 without an 802.2 LLC
  1293. * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
  1294. * won't work for fault tolerant netware but does for the rest.
  1295. */
  1296. if (*(unsigned short *) rawp == 0xFFFF)
  1297. return htons(ETH_P_802_3);
  1298. /*
  1299. * Real 802.2 LLC
  1300. */
  1301. return htons(ETH_P_802_2);
  1302. }
  1303. /*
  1304. * CISCO HDLC keepalive specific stuff
  1305. */
  1306. static struct sk_buff*
  1307. isdn_net_ciscohdlck_alloc_skb(isdn_net_local *lp, int len)
  1308. {
  1309. unsigned short hl = dev->drv[lp->isdn_device]->interface->hl_hdrlen;
  1310. struct sk_buff *skb;
  1311. skb = alloc_skb(hl + len, GFP_ATOMIC);
  1312. if (skb)
  1313. skb_reserve(skb, hl);
  1314. else
  1315. printk("isdn out of mem at %s:%d!\n", __FILE__, __LINE__);
  1316. return skb;
  1317. }
  1318. /* cisco hdlck device private ioctls */
  1319. static int
  1320. isdn_ciscohdlck_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1321. {
  1322. isdn_net_local *lp = (isdn_net_local *) netdev_priv(dev);
  1323. unsigned long len = 0;
  1324. unsigned long expires = 0;
  1325. int tmp = 0;
  1326. int period = lp->cisco_keepalive_period;
  1327. s8 debserint = lp->cisco_debserint;
  1328. int rc = 0;
  1329. if (lp->p_encap != ISDN_NET_ENCAP_CISCOHDLCK)
  1330. return -EINVAL;
  1331. switch (cmd) {
  1332. /* get/set keepalive period */
  1333. case SIOCGKEEPPERIOD:
  1334. len = (unsigned long)sizeof(lp->cisco_keepalive_period);
  1335. if (copy_to_user(ifr->ifr_data,
  1336. &lp->cisco_keepalive_period, len))
  1337. rc = -EFAULT;
  1338. break;
  1339. case SIOCSKEEPPERIOD:
  1340. tmp = lp->cisco_keepalive_period;
  1341. len = (unsigned long)sizeof(lp->cisco_keepalive_period);
  1342. if (copy_from_user(&period, ifr->ifr_data, len))
  1343. rc = -EFAULT;
  1344. if ((period > 0) && (period <= 32767))
  1345. lp->cisco_keepalive_period = period;
  1346. else
  1347. rc = -EINVAL;
  1348. if (!rc && (tmp != lp->cisco_keepalive_period)) {
  1349. expires = (unsigned long)(jiffies +
  1350. lp->cisco_keepalive_period * HZ);
  1351. mod_timer(&lp->cisco_timer, expires);
  1352. printk(KERN_INFO "%s: Keepalive period set "
  1353. "to %d seconds.\n",
  1354. dev->name, lp->cisco_keepalive_period);
  1355. }
  1356. break;
  1357. /* get/set debugging */
  1358. case SIOCGDEBSERINT:
  1359. len = (unsigned long)sizeof(lp->cisco_debserint);
  1360. if (copy_to_user(ifr->ifr_data,
  1361. &lp->cisco_debserint, len))
  1362. rc = -EFAULT;
  1363. break;
  1364. case SIOCSDEBSERINT:
  1365. len = (unsigned long)sizeof(lp->cisco_debserint);
  1366. if (copy_from_user(&debserint,
  1367. ifr->ifr_data, len))
  1368. rc = -EFAULT;
  1369. if ((debserint >= 0) && (debserint <= 64))
  1370. lp->cisco_debserint = debserint;
  1371. else
  1372. rc = -EINVAL;
  1373. break;
  1374. default:
  1375. rc = -EINVAL;
  1376. break;
  1377. }
  1378. return (rc);
  1379. }
  1380. /* called via cisco_timer.function */
  1381. static void
  1382. isdn_net_ciscohdlck_slarp_send_keepalive(unsigned long data)
  1383. {
  1384. isdn_net_local *lp = (isdn_net_local *) data;
  1385. struct sk_buff *skb;
  1386. unsigned char *p;
  1387. unsigned long last_cisco_myseq = lp->cisco_myseq;
  1388. int myseq_diff = 0;
  1389. if (!(lp->flags & ISDN_NET_CONNECTED) || lp->dialstate) {
  1390. printk("isdn BUG at %s:%d!\n", __FILE__, __LINE__);
  1391. return;
  1392. }
  1393. lp->cisco_myseq++;
  1394. myseq_diff = (lp->cisco_myseq - lp->cisco_mineseen);
  1395. if ((lp->cisco_line_state) && ((myseq_diff >= 3)||(myseq_diff <= -3))) {
  1396. /* line up -> down */
  1397. lp->cisco_line_state = 0;
  1398. printk (KERN_WARNING
  1399. "UPDOWN: Line protocol on Interface %s,"
  1400. " changed state to down\n", lp->netdev->dev->name);
  1401. /* should stop routing higher-level data accross */
  1402. } else if ((!lp->cisco_line_state) &&
  1403. (myseq_diff >= 0) && (myseq_diff <= 2)) {
  1404. /* line down -> up */
  1405. lp->cisco_line_state = 1;
  1406. printk (KERN_WARNING
  1407. "UPDOWN: Line protocol on Interface %s,"
  1408. " changed state to up\n", lp->netdev->dev->name);
  1409. /* restart routing higher-level data accross */
  1410. }
  1411. if (lp->cisco_debserint)
  1412. printk (KERN_DEBUG "%s: HDLC "
  1413. "myseq %lu, mineseen %lu%c, yourseen %lu, %s\n",
  1414. lp->netdev->dev->name, last_cisco_myseq, lp->cisco_mineseen,
  1415. ((last_cisco_myseq == lp->cisco_mineseen) ? '*' : 040),
  1416. lp->cisco_yourseq,
  1417. ((lp->cisco_line_state) ? "line up" : "line down"));
  1418. skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
  1419. if (!skb)
  1420. return;
  1421. p = skb_put(skb, 4 + 14);
  1422. /* cisco header */
  1423. *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
  1424. *(u8 *)(p + 1) = CISCO_CTRL;
  1425. *(__be16 *)(p + 2) = cpu_to_be16(CISCO_TYPE_SLARP);
  1426. /* slarp keepalive */
  1427. *(__be32 *)(p + 4) = cpu_to_be32(CISCO_SLARP_KEEPALIVE);
  1428. *(__be32 *)(p + 8) = cpu_to_be32(lp->cisco_myseq);
  1429. *(__be32 *)(p + 12) = cpu_to_be32(lp->cisco_yourseq);
  1430. *(__be16 *)(p + 16) = cpu_to_be16(0xffff); // reliablity, always 0xffff
  1431. p += 18;
  1432. isdn_net_write_super(lp, skb);
  1433. lp->cisco_timer.expires = jiffies + lp->cisco_keepalive_period * HZ;
  1434. add_timer(&lp->cisco_timer);
  1435. }
  1436. static void
  1437. isdn_net_ciscohdlck_slarp_send_request(isdn_net_local *lp)
  1438. {
  1439. struct sk_buff *skb;
  1440. unsigned char *p;
  1441. skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
  1442. if (!skb)
  1443. return;
  1444. p = skb_put(skb, 4 + 14);
  1445. /* cisco header */
  1446. *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
  1447. *(u8 *)(p + 1) = CISCO_CTRL;
  1448. *(__be16 *)(p + 2) = cpu_to_be16(CISCO_TYPE_SLARP);
  1449. /* slarp request */
  1450. *(__be32 *)(p + 4) = cpu_to_be32(CISCO_SLARP_REQUEST);
  1451. *(__be32 *)(p + 8) = cpu_to_be32(0); // address
  1452. *(__be32 *)(p + 12) = cpu_to_be32(0); // netmask
  1453. *(__be16 *)(p + 16) = cpu_to_be16(0); // unused
  1454. p += 18;
  1455. isdn_net_write_super(lp, skb);
  1456. }
  1457. static void
  1458. isdn_net_ciscohdlck_connected(isdn_net_local *lp)
  1459. {
  1460. lp->cisco_myseq = 0;
  1461. lp->cisco_mineseen = 0;
  1462. lp->cisco_yourseq = 0;
  1463. lp->cisco_keepalive_period = ISDN_TIMER_KEEPINT;
  1464. lp->cisco_last_slarp_in = 0;
  1465. lp->cisco_line_state = 0;
  1466. lp->cisco_debserint = 0;
  1467. /* send slarp request because interface/seq.no.s reset */
  1468. isdn_net_ciscohdlck_slarp_send_request(lp);
  1469. init_timer(&lp->cisco_timer);
  1470. lp->cisco_timer.data = (unsigned long) lp;
  1471. lp->cisco_timer.function = isdn_net_ciscohdlck_slarp_send_keepalive;
  1472. lp->cisco_timer.expires = jiffies + lp->cisco_keepalive_period * HZ;
  1473. add_timer(&lp->cisco_timer);
  1474. }
  1475. static void
  1476. isdn_net_ciscohdlck_disconnected(isdn_net_local *lp)
  1477. {
  1478. del_timer(&lp->cisco_timer);
  1479. }
  1480. static void
  1481. isdn_net_ciscohdlck_slarp_send_reply(isdn_net_local *lp)
  1482. {
  1483. struct sk_buff *skb;
  1484. unsigned char *p;
  1485. struct in_device *in_dev = NULL;
  1486. __be32 addr = 0; /* local ipv4 address */
  1487. __be32 mask = 0; /* local netmask */
  1488. if ((in_dev = lp->netdev->dev->ip_ptr) != NULL) {
  1489. /* take primary(first) address of interface */
  1490. struct in_ifaddr *ifa = in_dev->ifa_list;
  1491. if (ifa != NULL) {
  1492. addr = ifa->ifa_local;
  1493. mask = ifa->ifa_mask;
  1494. }
  1495. }
  1496. skb = isdn_net_ciscohdlck_alloc_skb(lp, 4 + 14);
  1497. if (!skb)
  1498. return;
  1499. p = skb_put(skb, 4 + 14);
  1500. /* cisco header */
  1501. *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
  1502. *(u8 *)(p + 1) = CISCO_CTRL;
  1503. *(__be16 *)(p + 2) = cpu_to_be16(CISCO_TYPE_SLARP);
  1504. /* slarp reply, send own ip/netmask; if values are nonsense remote
  1505. * should think we are unable to provide it with an address via SLARP */
  1506. *(__be32 *)(p + 4) = cpu_to_be32(CISCO_SLARP_REPLY);
  1507. *(__be32 *)(p + 8) = addr; // address
  1508. *(__be32 *)(p + 12) = mask; // netmask
  1509. *(__be16 *)(p + 16) = cpu_to_be16(0); // unused
  1510. p += 18;
  1511. isdn_net_write_super(lp, skb);
  1512. }
  1513. static void
  1514. isdn_net_ciscohdlck_slarp_in(isdn_net_local *lp, struct sk_buff *skb)
  1515. {
  1516. unsigned char *p;
  1517. int period;
  1518. u32 code;
  1519. u32 my_seq;
  1520. u32 your_seq;
  1521. __be32 local;
  1522. __be32 *addr, *mask;
  1523. u16 unused;
  1524. if (skb->len < 14)
  1525. return;
  1526. p = skb->data;
  1527. code = be32_to_cpup((__be32 *)p);
  1528. p += 4;
  1529. switch (code) {
  1530. case CISCO_SLARP_REQUEST:
  1531. lp->cisco_yourseq = 0;
  1532. isdn_net_ciscohdlck_slarp_send_reply(lp);
  1533. break;
  1534. case CISCO_SLARP_REPLY:
  1535. addr = (__be32 *)p;
  1536. mask = (__be32 *)(p + 4);
  1537. if (*mask != cpu_to_be32(0xfffffffc))
  1538. goto slarp_reply_out;
  1539. if ((*addr & cpu_to_be32(3)) == cpu_to_be32(0) ||
  1540. (*addr & cpu_to_be32(3)) == cpu_to_be32(3))
  1541. goto slarp_reply_out;
  1542. local = *addr ^ cpu_to_be32(3);
  1543. printk(KERN_INFO "%s: got slarp reply: remote ip: %pI4, local ip: %pI4 mask: %pI4\n",
  1544. lp->netdev->dev->name, addr, &local, mask);
  1545. break;
  1546. slarp_reply_out:
  1547. printk(KERN_INFO "%s: got invalid slarp reply (%pI4/%pI4) - ignored\n",
  1548. lp->netdev->dev->name, addr, mask);
  1549. break;
  1550. case CISCO_SLARP_KEEPALIVE:
  1551. period = (int)((jiffies - lp->cisco_last_slarp_in
  1552. + HZ/2 - 1) / HZ);
  1553. if (lp->cisco_debserint &&
  1554. (period != lp->cisco_keepalive_period) &&
  1555. lp->cisco_last_slarp_in) {
  1556. printk(KERN_DEBUG "%s: Keepalive period mismatch - "
  1557. "is %d but should be %d.\n",
  1558. lp->netdev->dev->name, period,
  1559. lp->cisco_keepalive_period);
  1560. }
  1561. lp->cisco_last_slarp_in = jiffies;
  1562. my_seq = be32_to_cpup((__be32 *)(p + 0));
  1563. your_seq = be32_to_cpup((__be32 *)(p + 4));
  1564. unused = be16_to_cpup((__be16 *)(p + 8));
  1565. p += 10;
  1566. lp->cisco_yourseq = my_seq;
  1567. lp->cisco_mineseen = your_seq;
  1568. break;
  1569. }
  1570. }
  1571. static void
  1572. isdn_net_ciscohdlck_receive(isdn_net_local *lp, struct sk_buff *skb)
  1573. {
  1574. unsigned char *p;
  1575. u8 addr;
  1576. u8 ctrl;
  1577. u16 type;
  1578. if (skb->len < 4)
  1579. goto out_free;
  1580. p = skb->data;
  1581. addr = *(u8 *)(p + 0);
  1582. ctrl = *(u8 *)(p + 1);
  1583. type = be16_to_cpup((__be16 *)(p + 2));
  1584. p += 4;
  1585. skb_pull(skb, 4);
  1586. if (addr != CISCO_ADDR_UNICAST && addr != CISCO_ADDR_BROADCAST) {
  1587. printk(KERN_WARNING "%s: Unknown Cisco addr 0x%02x\n",
  1588. lp->netdev->dev->name, addr);
  1589. goto out_free;
  1590. }
  1591. if (ctrl != CISCO_CTRL) {
  1592. printk(KERN_WARNING "%s: Unknown Cisco ctrl 0x%02x\n",
  1593. lp->netdev->dev->name, ctrl);
  1594. goto out_free;
  1595. }
  1596. switch (type) {
  1597. case CISCO_TYPE_SLARP:
  1598. isdn_net_ciscohdlck_slarp_in(lp, skb);
  1599. goto out_free;
  1600. case CISCO_TYPE_CDP:
  1601. if (lp->cisco_debserint)
  1602. printk(KERN_DEBUG "%s: Received CDP packet. use "
  1603. "\"no cdp enable\" on cisco.\n",
  1604. lp->netdev->dev->name);
  1605. goto out_free;
  1606. default:
  1607. /* no special cisco protocol */
  1608. skb->protocol = htons(type);
  1609. netif_rx(skb);
  1610. return;
  1611. }
  1612. out_free:
  1613. kfree_skb(skb);
  1614. }
  1615. /*
  1616. * Got a packet from ISDN-Channel.
  1617. */
  1618. static void
  1619. isdn_net_receive(struct net_device *ndev, struct sk_buff *skb)
  1620. {
  1621. isdn_net_local *lp = (isdn_net_local *) netdev_priv(ndev);
  1622. isdn_net_local *olp = lp; /* original 'lp' */
  1623. #ifdef CONFIG_ISDN_X25
  1624. struct concap_proto *cprot = lp -> netdev -> cprot;
  1625. #endif
  1626. lp->transcount += skb->len;
  1627. lp->stats.rx_packets++;
  1628. lp->stats.rx_bytes += skb->len;
  1629. if (lp->master) {
  1630. /* Bundling: If device is a slave-device, deliver to master, also
  1631. * handle master's statistics and hangup-timeout
  1632. */
  1633. ndev = lp->master;
  1634. lp = (isdn_net_local *) netdev_priv(ndev);
  1635. lp->stats.rx_packets++;
  1636. lp->stats.rx_bytes += skb->len;
  1637. }
  1638. skb->dev = ndev;
  1639. skb->pkt_type = PACKET_HOST;
  1640. skb_reset_mac_header(skb);
  1641. #ifdef ISDN_DEBUG_NET_DUMP
  1642. isdn_dumppkt("R:", skb->data, skb->len, 40);
  1643. #endif
  1644. switch (lp->p_encap) {
  1645. case ISDN_NET_ENCAP_ETHER:
  1646. /* Ethernet over ISDN */
  1647. olp->huptimer = 0;
  1648. lp->huptimer = 0;
  1649. skb->protocol = isdn_net_type_trans(skb, ndev);
  1650. break;
  1651. case ISDN_NET_ENCAP_UIHDLC:
  1652. /* HDLC with UI-frame (for ispa with -h1 option) */
  1653. olp->huptimer = 0;
  1654. lp->huptimer = 0;
  1655. skb_pull(skb, 2);
  1656. /* Fall through */
  1657. case ISDN_NET_ENCAP_RAWIP:
  1658. /* RAW-IP without MAC-Header */
  1659. olp->huptimer = 0;
  1660. lp->huptimer = 0;
  1661. skb->protocol = htons(ETH_P_IP);
  1662. break;
  1663. case ISDN_NET_ENCAP_CISCOHDLCK:
  1664. isdn_net_ciscohdlck_receive(lp, skb);
  1665. return;
  1666. case ISDN_NET_ENCAP_CISCOHDLC:
  1667. /* CISCO-HDLC IP with type field and fake I-frame-header */
  1668. skb_pull(skb, 2);
  1669. /* Fall through */
  1670. case ISDN_NET_ENCAP_IPTYP:
  1671. /* IP with type field */
  1672. olp->huptimer = 0;
  1673. lp->huptimer = 0;
  1674. skb->protocol = *(__be16 *)&(skb->data[0]);
  1675. skb_pull(skb, 2);
  1676. if (*(unsigned short *) skb->data == 0xFFFF)
  1677. skb->protocol = htons(ETH_P_802_3);
  1678. break;
  1679. #ifdef CONFIG_ISDN_PPP
  1680. case ISDN_NET_ENCAP_SYNCPPP:
  1681. /* huptimer is done in isdn_ppp_push_higher */
  1682. isdn_ppp_receive(lp->netdev, olp, skb);
  1683. return;
  1684. #endif
  1685. default:
  1686. #ifdef CONFIG_ISDN_X25
  1687. /* try if there are generic sync_device receiver routines */
  1688. if(cprot) if(cprot -> pops)
  1689. if( cprot -> pops -> data_ind){
  1690. cprot -> pops -> data_ind(cprot,skb);
  1691. return;
  1692. };
  1693. #endif /* CONFIG_ISDN_X25 */
  1694. printk(KERN_WARNING "%s: unknown encapsulation, dropping\n",
  1695. lp->netdev->dev->name);
  1696. kfree_skb(skb);
  1697. return;
  1698. }
  1699. netif_rx(skb);
  1700. return;
  1701. }
  1702. /*
  1703. * A packet arrived via ISDN. Search interface-chain for a corresponding
  1704. * interface. If found, deliver packet to receiver-function and return 1,
  1705. * else return 0.
  1706. */
  1707. int
  1708. isdn_net_rcv_skb(int idx, struct sk_buff *skb)
  1709. {
  1710. isdn_net_dev *p = dev->rx_netdev[idx];
  1711. if (p) {
  1712. isdn_net_local *lp = p->local;
  1713. if ((lp->flags & ISDN_NET_CONNECTED) &&
  1714. (!lp->dialstate)) {
  1715. isdn_net_receive(p->dev, skb);
  1716. return 1;
  1717. }
  1718. }
  1719. return 0;
  1720. }
  1721. /*
  1722. * build an header
  1723. * depends on encaps that is being used.
  1724. */
  1725. static int isdn_net_header(struct sk_buff *skb, struct net_device *dev,
  1726. unsigned short type,
  1727. const void *daddr, const void *saddr, unsigned plen)
  1728. {
  1729. isdn_net_local *lp = netdev_priv(dev);
  1730. unsigned char *p;
  1731. ushort len = 0;
  1732. switch (lp->p_encap) {
  1733. case ISDN_NET_ENCAP_ETHER:
  1734. len = eth_header(skb, dev, type, daddr, saddr, plen);
  1735. break;
  1736. #ifdef CONFIG_ISDN_PPP
  1737. case ISDN_NET_ENCAP_SYNCPPP:
  1738. /* stick on a fake header to keep fragmentation code happy. */
  1739. len = IPPP_MAX_HEADER;
  1740. skb_push(skb,len);
  1741. break;
  1742. #endif
  1743. case ISDN_NET_ENCAP_RAWIP:
  1744. printk(KERN_WARNING "isdn_net_header called with RAW_IP!\n");
  1745. len = 0;
  1746. break;
  1747. case ISDN_NET_ENCAP_IPTYP:
  1748. /* ethernet type field */
  1749. *((__be16 *)skb_push(skb, 2)) = htons(type);
  1750. len = 2;
  1751. break;
  1752. case ISDN_NET_ENCAP_UIHDLC:
  1753. /* HDLC with UI-Frames (for ispa with -h1 option) */
  1754. *((__be16 *)skb_push(skb, 2)) = htons(0x0103);
  1755. len = 2;
  1756. break;
  1757. case ISDN_NET_ENCAP_CISCOHDLC:
  1758. case ISDN_NET_ENCAP_CISCOHDLCK:
  1759. p = skb_push(skb, 4);
  1760. *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
  1761. *(u8 *)(p + 1) = CISCO_CTRL;
  1762. *(__be16 *)(p + 2) = cpu_to_be16(type);
  1763. p += 4;
  1764. len = 4;
  1765. break;
  1766. #ifdef CONFIG_ISDN_X25
  1767. default:
  1768. /* try if there are generic concap protocol routines */
  1769. if( lp-> netdev -> cprot ){
  1770. printk(KERN_WARNING "isdn_net_header called with concap_proto!\n");
  1771. len = 0;
  1772. break;
  1773. }
  1774. break;
  1775. #endif /* CONFIG_ISDN_X25 */
  1776. }
  1777. return len;
  1778. }
  1779. /* We don't need to send arp, because we have point-to-point connections. */
  1780. static int
  1781. isdn_net_rebuild_header(struct sk_buff *skb)
  1782. {
  1783. struct net_device *dev = skb->dev;
  1784. isdn_net_local *lp = netdev_priv(dev);
  1785. int ret = 0;
  1786. if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
  1787. struct ethhdr *eth = (struct ethhdr *) skb->data;
  1788. /*
  1789. * Only ARP/IP is currently supported
  1790. */
  1791. if (eth->h_proto != htons(ETH_P_IP)) {
  1792. printk(KERN_WARNING
  1793. "isdn_net: %s don't know how to resolve type %d addresses?\n",
  1794. dev->name, (int) eth->h_proto);
  1795. memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
  1796. return 0;
  1797. }
  1798. /*
  1799. * Try to get ARP to resolve the header.
  1800. */
  1801. #ifdef CONFIG_INET
  1802. ret = arp_find(eth->h_dest, skb);
  1803. #endif
  1804. }
  1805. return ret;
  1806. }
  1807. static int isdn_header_cache(const struct neighbour *neigh, struct hh_cache *hh)
  1808. {
  1809. const struct net_device *dev = neigh->dev;
  1810. isdn_net_local *lp = netdev_priv(dev);
  1811. if (lp->p_encap == ISDN_NET_ENCAP_ETHER)
  1812. return eth_header_cache(neigh, hh);
  1813. return -1;
  1814. }
  1815. static void isdn_header_cache_update(struct hh_cache *hh,
  1816. const struct net_device *dev,
  1817. const unsigned char *haddr)
  1818. {
  1819. isdn_net_local *lp = netdev_priv(dev);
  1820. if (lp->p_encap == ISDN_NET_ENCAP_ETHER)
  1821. eth_header_cache_update(hh, dev, haddr);
  1822. }
  1823. static const struct header_ops isdn_header_ops = {
  1824. .create = isdn_net_header,
  1825. .rebuild = isdn_net_rebuild_header,
  1826. .cache = isdn_header_cache,
  1827. .cache_update = isdn_header_cache_update,
  1828. };
  1829. /*
  1830. * Interface-setup. (just after registering a new interface)
  1831. */
  1832. static int
  1833. isdn_net_init(struct net_device *ndev)
  1834. {
  1835. ushort max_hlhdr_len = 0;
  1836. int drvidx;
  1837. ether_setup(ndev);
  1838. ndev->header_ops = NULL;
  1839. /* Setup the generic properties */
  1840. ndev->mtu = 1500;
  1841. ndev->flags = IFF_NOARP|IFF_POINTOPOINT;
  1842. ndev->type = ARPHRD_ETHER;
  1843. ndev->addr_len = ETH_ALEN;
  1844. ndev->validate_addr = NULL;
  1845. /* for clients with MPPP maybe higher values better */
  1846. ndev->tx_queue_len = 30;
  1847. /* The ISDN-specific entries in the device structure. */
  1848. ndev->open = &isdn_net_open;
  1849. ndev->hard_start_xmit = &isdn_net_start_xmit;
  1850. /*
  1851. * up till binding we ask the protocol layer to reserve as much
  1852. * as we might need for HL layer
  1853. */
  1854. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
  1855. if (dev->drv[drvidx])
  1856. if (max_hlhdr_len < dev->drv[drvidx]->interface->hl_hdrlen)
  1857. max_hlhdr_len = dev->drv[drvidx]->interface->hl_hdrlen;
  1858. ndev->hard_header_len = ETH_HLEN + max_hlhdr_len;
  1859. ndev->stop = &isdn_net_close;
  1860. ndev->get_stats = &isdn_net_get_stats;
  1861. ndev->do_ioctl = NULL;
  1862. return 0;
  1863. }
  1864. static void
  1865. isdn_net_swapbind(int drvidx)
  1866. {
  1867. isdn_net_dev *p;
  1868. #ifdef ISDN_DEBUG_NET_ICALL
  1869. printk(KERN_DEBUG "n_fi: swapping ch of %d\n", drvidx);
  1870. #endif
  1871. p = dev->netdev;
  1872. while (p) {
  1873. if (p->local->pre_device == drvidx)
  1874. switch (p->local->pre_channel) {
  1875. case 0:
  1876. p->local->pre_channel = 1;
  1877. break;
  1878. case 1:
  1879. p->local->pre_channel = 0;
  1880. break;
  1881. }
  1882. p = (isdn_net_dev *) p->next;
  1883. }
  1884. }
  1885. static void
  1886. isdn_net_swap_usage(int i1, int i2)
  1887. {
  1888. int u1 = dev->usage[i1] & ISDN_USAGE_EXCLUSIVE;
  1889. int u2 = dev->usage[i2] & ISDN_USAGE_EXCLUSIVE;
  1890. #ifdef ISDN_DEBUG_NET_ICALL
  1891. printk(KERN_DEBUG "n_fi: usage of %d and %d\n", i1, i2);
  1892. #endif
  1893. dev->usage[i1] &= ~ISDN_USAGE_EXCLUSIVE;
  1894. dev->usage[i1] |= u2;
  1895. dev->usage[i2] &= ~ISDN_USAGE_EXCLUSIVE;
  1896. dev->usage[i2] |= u1;
  1897. isdn_info_update();
  1898. }
  1899. /*
  1900. * An incoming call-request has arrived.
  1901. * Search the interface-chain for an appropriate interface.
  1902. * If found, connect the interface to the ISDN-channel and initiate
  1903. * D- and B-Channel-setup. If secure-flag is set, accept only
  1904. * configured phone-numbers. If callback-flag is set, initiate
  1905. * callback-dialing.
  1906. *
  1907. * Return-Value: 0 = No appropriate interface for this call.
  1908. * 1 = Call accepted
  1909. * 2 = Reject call, wait cbdelay, then call back
  1910. * 3 = Reject call
  1911. * 4 = Wait cbdelay, then call back
  1912. * 5 = No appropriate interface for this call,
  1913. * would eventually match if CID was longer.
  1914. */
  1915. int
  1916. isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
  1917. {
  1918. char *eaz;
  1919. int si1;
  1920. int si2;
  1921. int ematch;
  1922. int wret;
  1923. int swapped;
  1924. int sidx = 0;
  1925. u_long flags;
  1926. isdn_net_dev *p;
  1927. isdn_net_phone *n;
  1928. char nr[ISDN_MSNLEN];
  1929. char *my_eaz;
  1930. /* Search name in netdev-chain */
  1931. if (!setup->phone[0]) {
  1932. nr[0] = '0';
  1933. nr[1] = '\0';
  1934. printk(KERN_INFO "isdn_net: Incoming call without OAD, assuming '0'\n");
  1935. } else
  1936. strlcpy(nr, setup->phone, ISDN_MSNLEN);
  1937. si1 = (int) setup->si1;
  1938. si2 = (int) setup->si2;
  1939. if (!setup->eazmsn[0]) {
  1940. printk(KERN_WARNING "isdn_net: Incoming call without CPN, assuming '0'\n");
  1941. eaz = "0";
  1942. } else
  1943. eaz = setup->eazmsn;
  1944. if (dev->net_verbose > 1)
  1945. printk(KERN_INFO "isdn_net: call from %s,%d,%d -> %s\n", nr, si1, si2, eaz);
  1946. /* Accept DATA and VOICE calls at this stage
  1947. * local eaz is checked later for allowed call types
  1948. */
  1949. if ((si1 != 7) && (si1 != 1)) {
  1950. if (dev->net_verbose > 1)
  1951. printk(KERN_INFO "isdn_net: Service-Indicator not 1 or 7, ignored\n");
  1952. return 0;
  1953. }
  1954. n = (isdn_net_phone *) 0;
  1955. p = dev->netdev;
  1956. ematch = wret = swapped = 0;
  1957. #ifdef ISDN_DEBUG_NET_ICALL
  1958. printk(KERN_DEBUG "n_fi: di=%d ch=%d idx=%d usg=%d\n", di, ch, idx,
  1959. dev->usage[idx]);
  1960. #endif
  1961. while (p) {
  1962. int matchret;
  1963. isdn_net_local *lp = p->local;
  1964. /* If last check has triggered as binding-swap, revert it */
  1965. switch (swapped) {
  1966. case 2:
  1967. isdn_net_swap_usage(idx, sidx);
  1968. /* fall through */
  1969. case 1:
  1970. isdn_net_swapbind(di);
  1971. break;
  1972. }
  1973. swapped = 0;
  1974. /* check acceptable call types for DOV */
  1975. my_eaz = isdn_map_eaz2msn(lp->msn, di);
  1976. if (si1 == 1) { /* it's a DOV call, check if we allow it */
  1977. if (*my_eaz == 'v' || *my_eaz == 'V' ||
  1978. *my_eaz == 'b' || *my_eaz == 'B')
  1979. my_eaz++; /* skip to allow a match */
  1980. else
  1981. my_eaz = NULL; /* force non match */
  1982. } else { /* it's a DATA call, check if we allow it */
  1983. if (*my_eaz == 'b' || *my_eaz == 'B')
  1984. my_eaz++; /* skip to allow a match */
  1985. }
  1986. if (my_eaz)
  1987. matchret = isdn_msncmp(eaz, my_eaz);
  1988. else
  1989. matchret = 1;
  1990. if (!matchret)
  1991. ematch = 1;
  1992. /* Remember if more numbers eventually can match */
  1993. if (matchret > wret)
  1994. wret = matchret;
  1995. #ifdef ISDN_DEBUG_NET_ICALL
  1996. printk(KERN_DEBUG "n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
  1997. p->dev->name, lp->msn, lp->flags, lp->dialstate);
  1998. #endif
  1999. if ((!matchret) && /* EAZ is matching */
  2000. (((!(lp->flags & ISDN_NET_CONNECTED)) && /* but not connected */
  2001. (USG_NONE(dev->usage[idx]))) || /* and ch. unused or */
  2002. ((((lp->dialstate == 4) || (lp->dialstate == 12)) && /* if dialing */
  2003. (!(lp->flags & ISDN_NET_CALLBACK))) /* but no callback */
  2004. )))
  2005. {
  2006. #ifdef ISDN_DEBUG_NET_ICALL
  2007. printk(KERN_DEBUG "n_fi: match1, pdev=%d pch=%d\n",
  2008. lp->pre_device, lp->pre_channel);
  2009. #endif
  2010. if (dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) {
  2011. if ((lp->pre_channel != ch) ||
  2012. (lp->pre_device != di)) {
  2013. /* Here we got a problem:
  2014. * If using an ICN-Card, an incoming call is always signaled on
  2015. * on the first channel of the card, if both channels are
  2016. * down. However this channel may be bound exclusive. If the
  2017. * second channel is free, this call should be accepted.
  2018. * The solution is horribly but it runs, so what:
  2019. * We exchange the exclusive bindings of the two channels, the
  2020. * corresponding variables in the interface-structs.
  2021. */
  2022. if (ch == 0) {
  2023. sidx = isdn_dc2minor(di, 1);
  2024. #ifdef ISDN_DEBUG_NET_ICALL
  2025. printk(KERN_DEBUG "n_fi: ch is 0\n");
  2026. #endif
  2027. if (USG_NONE(dev->usage[sidx])) {
  2028. /* Second Channel is free, now see if it is bound
  2029. * exclusive too. */
  2030. if (dev->usage[sidx] & ISDN_USAGE_EXCLUSIVE) {
  2031. #ifdef ISDN_DEBUG_NET_ICALL
  2032. printk(KERN_DEBUG "n_fi: 2nd channel is down and bound\n");
  2033. #endif
  2034. /* Yes, swap bindings only, if the original
  2035. * binding is bound to channel 1 of this driver */
  2036. if ((lp->pre_device == di) &&
  2037. (lp->pre_channel == 1)) {
  2038. isdn_net_swapbind(di);
  2039. swapped = 1;
  2040. } else {
  2041. /* ... else iterate next device */
  2042. p = (isdn_net_dev *) p->next;
  2043. continue;
  2044. }
  2045. } else {
  2046. #ifdef ISDN_DEBUG_NET_ICALL
  2047. printk(KERN_DEBUG "n_fi: 2nd channel is down and unbound\n");
  2048. #endif
  2049. /* No, swap always and swap excl-usage also */
  2050. isdn_net_swap_usage(idx, sidx);
  2051. isdn_net_swapbind(di);
  2052. swapped = 2;
  2053. }
  2054. /* Now check for exclusive binding again */
  2055. #ifdef ISDN_DEBUG_NET_ICALL
  2056. printk(KERN_DEBUG "n_fi: final check\n");
  2057. #endif
  2058. if ((dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) &&
  2059. ((lp->pre_channel != ch) ||
  2060. (lp->pre_device != di))) {
  2061. #ifdef ISDN_DEBUG_NET_ICALL
  2062. printk(KERN_DEBUG "n_fi: final check failed\n");
  2063. #endif
  2064. p = (isdn_net_dev *) p->next;
  2065. continue;
  2066. }
  2067. }
  2068. } else {
  2069. /* We are already on the second channel, so nothing to do */
  2070. #ifdef ISDN_DEBUG_NET_ICALL
  2071. printk(KERN_DEBUG "n_fi: already on 2nd channel\n");
  2072. #endif
  2073. }
  2074. }
  2075. }
  2076. #ifdef ISDN_DEBUG_NET_ICALL
  2077. printk(KERN_DEBUG "n_fi: match2\n");
  2078. #endif
  2079. n = lp->phone[0];
  2080. if (lp->flags & ISDN_NET_SECURE) {
  2081. while (n) {
  2082. if (!isdn_msncmp(nr, n->num))
  2083. break;
  2084. n = (isdn_net_phone *) n->next;
  2085. }
  2086. }
  2087. if (n || (!(lp->flags & ISDN_NET_SECURE))) {
  2088. #ifdef ISDN_DEBUG_NET_ICALL
  2089. printk(KERN_DEBUG "n_fi: match3\n");
  2090. #endif
  2091. /* matching interface found */
  2092. /*
  2093. * Is the state STOPPED?
  2094. * If so, no dialin is allowed,
  2095. * so reject actively.
  2096. * */
  2097. if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
  2098. printk(KERN_INFO "incoming call, interface %s `stopped' -> rejected\n",
  2099. p->dev->name);
  2100. return 3;
  2101. }
  2102. /*
  2103. * Is the interface up?
  2104. * If not, reject the call actively.
  2105. */
  2106. if (!isdn_net_device_started(p)) {
  2107. printk(KERN_INFO "%s: incoming call, interface down -> rejected\n",
  2108. p->dev->name);
  2109. return 3;
  2110. }
  2111. /* Interface is up, now see if it's a slave. If so, see if
  2112. * it's master and parent slave is online. If not, reject the call.
  2113. */
  2114. if (lp->master) {
  2115. isdn_net_local *mlp = ISDN_MASTER_PRIV(lp);
  2116. printk(KERN_DEBUG "ICALLslv: %s\n", p->dev->name);
  2117. printk(KERN_DEBUG "master=%s\n", lp->master->name);
  2118. if (mlp->flags & ISDN_NET_CONNECTED) {
  2119. printk(KERN_DEBUG "master online\n");
  2120. /* Master is online, find parent-slave (master if first slave) */
  2121. while (mlp->slave) {
  2122. if (ISDN_SLAVE_PRIV(mlp) == lp)
  2123. break;
  2124. mlp = ISDN_SLAVE_PRIV(mlp);
  2125. }
  2126. } else
  2127. printk(KERN_DEBUG "master offline\n");
  2128. /* Found parent, if it's offline iterate next device */
  2129. printk(KERN_DEBUG "mlpf: %d\n", mlp->flags & ISDN_NET_CONNECTED);
  2130. if (!(mlp->flags & ISDN_NET_CONNECTED)) {
  2131. p = (isdn_net_dev *) p->next;
  2132. continue;
  2133. }
  2134. }
  2135. if (lp->flags & ISDN_NET_CALLBACK) {
  2136. int chi;
  2137. /*
  2138. * Is the state MANUAL?
  2139. * If so, no callback can be made,
  2140. * so reject actively.
  2141. * */
  2142. if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
  2143. printk(KERN_INFO "incoming call for callback, interface %s `off' -> rejected\n",
  2144. p->dev->name);
  2145. return 3;
  2146. }
  2147. printk(KERN_DEBUG "%s: call from %s -> %s, start callback\n",
  2148. p->dev->name, nr, eaz);
  2149. if (lp->phone[1]) {
  2150. /* Grab a free ISDN-Channel */
  2151. spin_lock_irqsave(&dev->lock, flags);
  2152. if ((chi =
  2153. isdn_get_free_channel(
  2154. ISDN_USAGE_NET,
  2155. lp->l2_proto,
  2156. lp->l3_proto,
  2157. lp->pre_device,
  2158. lp->pre_channel,
  2159. lp->msn)
  2160. ) < 0) {
  2161. printk(KERN_WARNING "isdn_net_find_icall: No channel for %s\n",
  2162. p->dev->name);
  2163. spin_unlock_irqrestore(&dev->lock, flags);
  2164. return 0;
  2165. }
  2166. /* Setup dialstate. */
  2167. lp->dtimer = 0;
  2168. lp->dialstate = 11;
  2169. /* Connect interface with channel */
  2170. isdn_net_bind_channel(lp, chi);
  2171. #ifdef CONFIG_ISDN_PPP
  2172. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  2173. if (isdn_ppp_bind(lp) < 0) {
  2174. spin_unlock_irqrestore(&dev->lock, flags);
  2175. isdn_net_unbind_channel(lp);
  2176. return 0;
  2177. }
  2178. #endif
  2179. spin_unlock_irqrestore(&dev->lock, flags);
  2180. /* Initiate dialing by returning 2 or 4 */
  2181. return (lp->flags & ISDN_NET_CBHUP) ? 2 : 4;
  2182. } else
  2183. printk(KERN_WARNING "isdn_net: %s: No phone number\n",
  2184. p->dev->name);
  2185. return 0;
  2186. } else {
  2187. printk(KERN_DEBUG "%s: call from %s -> %s accepted\n",
  2188. p->dev->name, nr, eaz);
  2189. /* if this interface is dialing, it does it probably on a different
  2190. device, so free this device */
  2191. if ((lp->dialstate == 4) || (lp->dialstate == 12)) {
  2192. #ifdef CONFIG_ISDN_PPP
  2193. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  2194. isdn_ppp_free(lp);
  2195. #endif
  2196. isdn_net_lp_disconnected(lp);
  2197. isdn_free_channel(lp->isdn_device, lp->isdn_channel,
  2198. ISDN_USAGE_NET);
  2199. }
  2200. spin_lock_irqsave(&dev->lock, flags);
  2201. dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
  2202. dev->usage[idx] |= ISDN_USAGE_NET;
  2203. strcpy(dev->num[idx], nr);
  2204. isdn_info_update();
  2205. dev->st_netdev[idx] = lp->netdev;
  2206. lp->isdn_device = di;
  2207. lp->isdn_channel = ch;
  2208. lp->ppp_slot = -1;
  2209. lp->flags |= ISDN_NET_CONNECTED;
  2210. lp->dialstate = 7;
  2211. lp->dtimer = 0;
  2212. lp->outgoing = 0;
  2213. lp->huptimer = 0;
  2214. lp->hupflags |= ISDN_WAITCHARGE;
  2215. lp->hupflags &= ~ISDN_HAVECHARGE;
  2216. #ifdef CONFIG_ISDN_PPP
  2217. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
  2218. if (isdn_ppp_bind(lp) < 0) {
  2219. isdn_net_unbind_channel(lp);
  2220. spin_unlock_irqrestore(&dev->lock, flags);
  2221. return 0;
  2222. }
  2223. }
  2224. #endif
  2225. spin_unlock_irqrestore(&dev->lock, flags);
  2226. return 1;
  2227. }
  2228. }
  2229. }
  2230. p = (isdn_net_dev *) p->next;
  2231. }
  2232. /* If none of configured EAZ/MSN matched and not verbose, be silent */
  2233. if (!ematch || dev->net_verbose)
  2234. printk(KERN_INFO "isdn_net: call from %s -> %d %s ignored\n", nr, di, eaz);
  2235. return (wret == 2)?5:0;
  2236. }
  2237. /*
  2238. * Search list of net-interfaces for an interface with given name.
  2239. */
  2240. isdn_net_dev *
  2241. isdn_net_findif(char *name)
  2242. {
  2243. isdn_net_dev *p = dev->netdev;
  2244. while (p) {
  2245. if (!strcmp(p->dev->name, name))
  2246. return p;
  2247. p = (isdn_net_dev *) p->next;
  2248. }
  2249. return (isdn_net_dev *) NULL;
  2250. }
  2251. /*
  2252. * Force a net-interface to dial out.
  2253. * This is called from the userlevel-routine below or
  2254. * from isdn_net_start_xmit().
  2255. */
  2256. static int
  2257. isdn_net_force_dial_lp(isdn_net_local * lp)
  2258. {
  2259. if ((!(lp->flags & ISDN_NET_CONNECTED)) && !lp->dialstate) {
  2260. int chi;
  2261. if (lp->phone[1]) {
  2262. ulong flags;
  2263. /* Grab a free ISDN-Channel */
  2264. spin_lock_irqsave(&dev->lock, flags);
  2265. if ((chi = isdn_get_free_channel(
  2266. ISDN_USAGE_NET,
  2267. lp->l2_proto,
  2268. lp->l3_proto,
  2269. lp->pre_device,
  2270. lp->pre_channel,
  2271. lp->msn)) < 0) {
  2272. printk(KERN_WARNING "isdn_net_force_dial: No channel for %s\n",
  2273. lp->netdev->dev->name);
  2274. spin_unlock_irqrestore(&dev->lock, flags);
  2275. return -EAGAIN;
  2276. }
  2277. lp->dialstate = 1;
  2278. /* Connect interface with channel */
  2279. isdn_net_bind_channel(lp, chi);
  2280. #ifdef CONFIG_ISDN_PPP
  2281. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  2282. if (isdn_ppp_bind(lp) < 0) {
  2283. isdn_net_unbind_channel(lp);
  2284. spin_unlock_irqrestore(&dev->lock, flags);
  2285. return -EAGAIN;
  2286. }
  2287. #endif
  2288. /* Initiate dialing */
  2289. spin_unlock_irqrestore(&dev->lock, flags);
  2290. isdn_net_dial();
  2291. return 0;
  2292. } else
  2293. return -EINVAL;
  2294. } else
  2295. return -EBUSY;
  2296. }
  2297. /*
  2298. * This is called from certain upper protocol layers (multilink ppp
  2299. * and x25iface encapsulation module) that want to initiate dialing
  2300. * themselves.
  2301. */
  2302. int
  2303. isdn_net_dial_req(isdn_net_local * lp)
  2304. {
  2305. /* is there a better error code? */
  2306. if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) return -EBUSY;
  2307. return isdn_net_force_dial_lp(lp);
  2308. }
  2309. /*
  2310. * Force a net-interface to dial out.
  2311. * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
  2312. */
  2313. int
  2314. isdn_net_force_dial(char *name)
  2315. {
  2316. isdn_net_dev *p = isdn_net_findif(name);
  2317. if (!p)
  2318. return -ENODEV;
  2319. return (isdn_net_force_dial_lp(p->local));
  2320. }
  2321. /*
  2322. * Helper for alloc_netdev()
  2323. */
  2324. static void _isdn_setup(struct net_device *dev)
  2325. {
  2326. isdn_net_local *lp = netdev_priv(dev);
  2327. dev->flags = IFF_NOARP | IFF_POINTOPOINT;
  2328. lp->p_encap = ISDN_NET_ENCAP_RAWIP;
  2329. lp->magic = ISDN_NET_MAGIC;
  2330. lp->last = lp;
  2331. lp->next = lp;
  2332. lp->isdn_device = -1;
  2333. lp->isdn_channel = -1;
  2334. lp->pre_device = -1;
  2335. lp->pre_channel = -1;
  2336. lp->exclusive = -1;
  2337. lp->ppp_slot = -1;
  2338. lp->pppbind = -1;
  2339. skb_queue_head_init(&lp->super_tx_queue);
  2340. lp->l2_proto = ISDN_PROTO_L2_X75I;
  2341. lp->l3_proto = ISDN_PROTO_L3_TRANS;
  2342. lp->triggercps = 6000;
  2343. lp->slavedelay = 10 * HZ;
  2344. lp->hupflags = ISDN_INHUP; /* Do hangup even on incoming calls */
  2345. lp->onhtime = 10; /* Default hangup-time for saving costs */
  2346. lp->dialmax = 1;
  2347. /* Hangup before Callback, manual dial */
  2348. lp->flags = ISDN_NET_CBHUP | ISDN_NET_DM_MANUAL;
  2349. lp->cbdelay = 25; /* Wait 5 secs before Callback */
  2350. lp->dialtimeout = -1; /* Infinite Dial-Timeout */
  2351. lp->dialwait = 5 * HZ; /* Wait 5 sec. after failed dial */
  2352. lp->dialstarted = 0; /* Jiffies of last dial-start */
  2353. lp->dialwait_timer = 0; /* Jiffies of earliest next dial-start */
  2354. }
  2355. /*
  2356. * Allocate a new network-interface and initialize its data structures.
  2357. */
  2358. char *
  2359. isdn_net_new(char *name, struct net_device *master)
  2360. {
  2361. isdn_net_dev *netdev;
  2362. /* Avoid creating an existing interface */
  2363. if (isdn_net_findif(name)) {
  2364. printk(KERN_WARNING "isdn_net: interface %s already exists\n", name);
  2365. return NULL;
  2366. }
  2367. if (name == NULL)
  2368. return NULL;
  2369. if (!(netdev = kzalloc(sizeof(isdn_net_dev), GFP_KERNEL))) {
  2370. printk(KERN_WARNING "isdn_net: Could not allocate net-device\n");
  2371. return NULL;
  2372. }
  2373. netdev->dev = alloc_netdev(sizeof(isdn_net_local), name, _isdn_setup);
  2374. if (!netdev->dev) {
  2375. printk(KERN_WARNING "isdn_net: Could not allocate network device\n");
  2376. kfree(netdev);
  2377. return NULL;
  2378. }
  2379. netdev->local = netdev_priv(netdev->dev);
  2380. netdev->dev->init = isdn_net_init;
  2381. if (master) {
  2382. /* Device shall be a slave */
  2383. struct net_device *p = MASTER_TO_SLAVE(master);
  2384. struct net_device *q = master;
  2385. netdev->local->master = master;
  2386. /* Put device at end of slave-chain */
  2387. while (p) {
  2388. q = p;
  2389. p = MASTER_TO_SLAVE(p);
  2390. }
  2391. MASTER_TO_SLAVE(q) = netdev->dev;
  2392. } else {
  2393. /* Device shall be a master */
  2394. /*
  2395. * Watchdog timer (currently) for master only.
  2396. */
  2397. netdev->dev->tx_timeout = isdn_net_tx_timeout;
  2398. netdev->dev->watchdog_timeo = ISDN_NET_TX_TIMEOUT;
  2399. if (register_netdev(netdev->dev) != 0) {
  2400. printk(KERN_WARNING "isdn_net: Could not register net-device\n");
  2401. free_netdev(netdev->dev);
  2402. kfree(netdev);
  2403. return NULL;
  2404. }
  2405. }
  2406. netdev->queue = netdev->local;
  2407. spin_lock_init(&netdev->queue_lock);
  2408. netdev->local->netdev = netdev;
  2409. INIT_WORK(&netdev->local->tqueue, isdn_net_softint);
  2410. spin_lock_init(&netdev->local->xmit_lock);
  2411. /* Put into to netdev-chain */
  2412. netdev->next = (void *) dev->netdev;
  2413. dev->netdev = netdev;
  2414. return netdev->dev->name;
  2415. }
  2416. char *
  2417. isdn_net_newslave(char *parm)
  2418. {
  2419. char *p = strchr(parm, ',');
  2420. isdn_net_dev *n;
  2421. char newname[10];
  2422. if (p) {
  2423. /* Slave-Name MUST not be empty */
  2424. if (!strlen(p + 1))
  2425. return NULL;
  2426. strcpy(newname, p + 1);
  2427. *p = 0;
  2428. /* Master must already exist */
  2429. if (!(n = isdn_net_findif(parm)))
  2430. return NULL;
  2431. /* Master must be a real interface, not a slave */
  2432. if (n->local->master)
  2433. return NULL;
  2434. /* Master must not be started yet */
  2435. if (isdn_net_device_started(n))
  2436. return NULL;
  2437. return (isdn_net_new(newname, n->dev));
  2438. }
  2439. return NULL;
  2440. }
  2441. /*
  2442. * Set interface-parameters.
  2443. * Always set all parameters, so the user-level application is responsible
  2444. * for not overwriting existing setups. It has to get the current
  2445. * setup first, if only selected parameters are to be changed.
  2446. */
  2447. int
  2448. isdn_net_setcfg(isdn_net_ioctl_cfg * cfg)
  2449. {
  2450. isdn_net_dev *p = isdn_net_findif(cfg->name);
  2451. ulong features;
  2452. int i;
  2453. int drvidx;
  2454. int chidx;
  2455. char drvid[25];
  2456. if (p) {
  2457. isdn_net_local *lp = p->local;
  2458. /* See if any registered driver supports the features we want */
  2459. features = ((1 << cfg->l2_proto) << ISDN_FEATURE_L2_SHIFT) |
  2460. ((1 << cfg->l3_proto) << ISDN_FEATURE_L3_SHIFT);
  2461. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  2462. if (dev->drv[i])
  2463. if ((dev->drv[i]->interface->features & features) == features)
  2464. break;
  2465. if (i == ISDN_MAX_DRIVERS) {
  2466. printk(KERN_WARNING "isdn_net: No driver with selected features\n");
  2467. return -ENODEV;
  2468. }
  2469. if (lp->p_encap != cfg->p_encap){
  2470. #ifdef CONFIG_ISDN_X25
  2471. struct concap_proto * cprot = p -> cprot;
  2472. #endif
  2473. if (isdn_net_device_started(p)) {
  2474. printk(KERN_WARNING "%s: cannot change encap when if is up\n",
  2475. p->dev->name);
  2476. return -EBUSY;
  2477. }
  2478. #ifdef CONFIG_ISDN_X25
  2479. if( cprot && cprot -> pops )
  2480. cprot -> pops -> proto_del ( cprot );
  2481. p -> cprot = NULL;
  2482. lp -> dops = NULL;
  2483. /* ... , prepare for configuration of new one ... */
  2484. switch ( cfg -> p_encap ){
  2485. case ISDN_NET_ENCAP_X25IFACE:
  2486. lp -> dops = &isdn_concap_reliable_dl_dops;
  2487. }
  2488. /* ... and allocate new one ... */
  2489. p -> cprot = isdn_concap_new( cfg -> p_encap );
  2490. /* p -> cprot == NULL now if p_encap is not supported
  2491. by means of the concap_proto mechanism */
  2492. /* the protocol is not configured yet; this will
  2493. happen later when isdn_net_reset() is called */
  2494. #endif
  2495. }
  2496. switch ( cfg->p_encap ) {
  2497. case ISDN_NET_ENCAP_SYNCPPP:
  2498. #ifndef CONFIG_ISDN_PPP
  2499. printk(KERN_WARNING "%s: SyncPPP support not configured\n",
  2500. p->dev->name);
  2501. return -EINVAL;
  2502. #else
  2503. p->dev->type = ARPHRD_PPP; /* change ARP type */
  2504. p->dev->addr_len = 0;
  2505. p->dev->do_ioctl = isdn_ppp_dev_ioctl;
  2506. #endif
  2507. break;
  2508. case ISDN_NET_ENCAP_X25IFACE:
  2509. #ifndef CONFIG_ISDN_X25
  2510. printk(KERN_WARNING "%s: isdn-x25 support not configured\n",
  2511. p->dev->name);
  2512. return -EINVAL;
  2513. #else
  2514. p->dev->type = ARPHRD_X25; /* change ARP type */
  2515. p->dev->addr_len = 0;
  2516. #endif
  2517. break;
  2518. case ISDN_NET_ENCAP_CISCOHDLCK:
  2519. p->dev->do_ioctl = isdn_ciscohdlck_dev_ioctl;
  2520. break;
  2521. default:
  2522. if( cfg->p_encap >= 0 &&
  2523. cfg->p_encap <= ISDN_NET_ENCAP_MAX_ENCAP )
  2524. break;
  2525. printk(KERN_WARNING
  2526. "%s: encapsulation protocol %d not supported\n",
  2527. p->dev->name, cfg->p_encap);
  2528. return -EINVAL;
  2529. }
  2530. if (strlen(cfg->drvid)) {
  2531. /* A bind has been requested ... */
  2532. char *c,
  2533. *e;
  2534. drvidx = -1;
  2535. chidx = -1;
  2536. strcpy(drvid, cfg->drvid);
  2537. if ((c = strchr(drvid, ','))) {
  2538. /* The channel-number is appended to the driver-Id with a comma */
  2539. chidx = (int) simple_strtoul(c + 1, &e, 10);
  2540. if (e == c)
  2541. chidx = -1;
  2542. *c = '\0';
  2543. }
  2544. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  2545. /* Lookup driver-Id in array */
  2546. if (!(strcmp(dev->drvid[i], drvid))) {
  2547. drvidx = i;
  2548. break;
  2549. }
  2550. if ((drvidx == -1) || (chidx == -1))
  2551. /* Either driver-Id or channel-number invalid */
  2552. return -ENODEV;
  2553. } else {
  2554. /* Parameters are valid, so get them */
  2555. drvidx = lp->pre_device;
  2556. chidx = lp->pre_channel;
  2557. }
  2558. if (cfg->exclusive > 0) {
  2559. unsigned long flags;
  2560. /* If binding is exclusive, try to grab the channel */
  2561. spin_lock_irqsave(&dev->lock, flags);
  2562. if ((i = isdn_get_free_channel(ISDN_USAGE_NET,
  2563. lp->l2_proto, lp->l3_proto, drvidx,
  2564. chidx, lp->msn)) < 0) {
  2565. /* Grab failed, because desired channel is in use */
  2566. lp->exclusive = -1;
  2567. spin_unlock_irqrestore(&dev->lock, flags);
  2568. return -EBUSY;
  2569. }
  2570. /* All went ok, so update isdninfo */
  2571. dev->usage[i] = ISDN_USAGE_EXCLUSIVE;
  2572. isdn_info_update();
  2573. spin_unlock_irqrestore(&dev->lock, flags);
  2574. lp->exclusive = i;
  2575. } else {
  2576. /* Non-exclusive binding or unbind. */
  2577. lp->exclusive = -1;
  2578. if ((lp->pre_device != -1) && (cfg->exclusive == -1)) {
  2579. isdn_unexclusive_channel(lp->pre_device, lp->pre_channel);
  2580. isdn_free_channel(lp->pre_device, lp->pre_channel, ISDN_USAGE_NET);
  2581. drvidx = -1;
  2582. chidx = -1;
  2583. }
  2584. }
  2585. strlcpy(lp->msn, cfg->eaz, sizeof(lp->msn));
  2586. lp->pre_device = drvidx;
  2587. lp->pre_channel = chidx;
  2588. lp->onhtime = cfg->onhtime;
  2589. lp->charge = cfg->charge;
  2590. lp->l2_proto = cfg->l2_proto;
  2591. lp->l3_proto = cfg->l3_proto;
  2592. lp->cbdelay = cfg->cbdelay;
  2593. lp->dialmax = cfg->dialmax;
  2594. lp->triggercps = cfg->triggercps;
  2595. lp->slavedelay = cfg->slavedelay * HZ;
  2596. lp->pppbind = cfg->pppbind;
  2597. lp->dialtimeout = cfg->dialtimeout >= 0 ? cfg->dialtimeout * HZ : -1;
  2598. lp->dialwait = cfg->dialwait * HZ;
  2599. if (cfg->secure)
  2600. lp->flags |= ISDN_NET_SECURE;
  2601. else
  2602. lp->flags &= ~ISDN_NET_SECURE;
  2603. if (cfg->cbhup)
  2604. lp->flags |= ISDN_NET_CBHUP;
  2605. else
  2606. lp->flags &= ~ISDN_NET_CBHUP;
  2607. switch (cfg->callback) {
  2608. case 0:
  2609. lp->flags &= ~(ISDN_NET_CALLBACK | ISDN_NET_CBOUT);
  2610. break;
  2611. case 1:
  2612. lp->flags |= ISDN_NET_CALLBACK;
  2613. lp->flags &= ~ISDN_NET_CBOUT;
  2614. break;
  2615. case 2:
  2616. lp->flags |= ISDN_NET_CBOUT;
  2617. lp->flags &= ~ISDN_NET_CALLBACK;
  2618. break;
  2619. }
  2620. lp->flags &= ~ISDN_NET_DIALMODE_MASK; /* first all bits off */
  2621. if (cfg->dialmode && !(cfg->dialmode & ISDN_NET_DIALMODE_MASK)) {
  2622. /* old isdnctrl version, where only 0 or 1 is given */
  2623. printk(KERN_WARNING
  2624. "Old isdnctrl version detected! Please update.\n");
  2625. lp->flags |= ISDN_NET_DM_OFF; /* turn on `off' bit */
  2626. }
  2627. else {
  2628. lp->flags |= cfg->dialmode; /* turn on selected bits */
  2629. }
  2630. if (cfg->chargehup)
  2631. lp->hupflags |= ISDN_CHARGEHUP;
  2632. else
  2633. lp->hupflags &= ~ISDN_CHARGEHUP;
  2634. if (cfg->ihup)
  2635. lp->hupflags |= ISDN_INHUP;
  2636. else
  2637. lp->hupflags &= ~ISDN_INHUP;
  2638. if (cfg->chargeint > 10) {
  2639. lp->hupflags |= ISDN_CHARGEHUP | ISDN_HAVECHARGE | ISDN_MANCHARGE;
  2640. lp->chargeint = cfg->chargeint * HZ;
  2641. }
  2642. if (cfg->p_encap != lp->p_encap) {
  2643. if (cfg->p_encap == ISDN_NET_ENCAP_RAWIP) {
  2644. p->dev->header_ops = NULL;
  2645. p->dev->flags = IFF_NOARP|IFF_POINTOPOINT;
  2646. } else {
  2647. p->dev->header_ops = &isdn_header_ops;
  2648. if (cfg->p_encap == ISDN_NET_ENCAP_ETHER)
  2649. p->dev->flags = IFF_BROADCAST | IFF_MULTICAST;
  2650. else
  2651. p->dev->flags = IFF_NOARP|IFF_POINTOPOINT;
  2652. }
  2653. }
  2654. lp->p_encap = cfg->p_encap;
  2655. return 0;
  2656. }
  2657. return -ENODEV;
  2658. }
  2659. /*
  2660. * Perform get-interface-parameters.ioctl
  2661. */
  2662. int
  2663. isdn_net_getcfg(isdn_net_ioctl_cfg * cfg)
  2664. {
  2665. isdn_net_dev *p = isdn_net_findif(cfg->name);
  2666. if (p) {
  2667. isdn_net_local *lp = p->local;
  2668. strcpy(cfg->eaz, lp->msn);
  2669. cfg->exclusive = lp->exclusive;
  2670. if (lp->pre_device >= 0) {
  2671. sprintf(cfg->drvid, "%s,%d", dev->drvid[lp->pre_device],
  2672. lp->pre_channel);
  2673. } else
  2674. cfg->drvid[0] = '\0';
  2675. cfg->onhtime = lp->onhtime;
  2676. cfg->charge = lp->charge;
  2677. cfg->l2_proto = lp->l2_proto;
  2678. cfg->l3_proto = lp->l3_proto;
  2679. cfg->p_encap = lp->p_encap;
  2680. cfg->secure = (lp->flags & ISDN_NET_SECURE) ? 1 : 0;
  2681. cfg->callback = 0;
  2682. if (lp->flags & ISDN_NET_CALLBACK)
  2683. cfg->callback = 1;
  2684. if (lp->flags & ISDN_NET_CBOUT)
  2685. cfg->callback = 2;
  2686. cfg->cbhup = (lp->flags & ISDN_NET_CBHUP) ? 1 : 0;
  2687. cfg->dialmode = lp->flags & ISDN_NET_DIALMODE_MASK;
  2688. cfg->chargehup = (lp->hupflags & 4) ? 1 : 0;
  2689. cfg->ihup = (lp->hupflags & 8) ? 1 : 0;
  2690. cfg->cbdelay = lp->cbdelay;
  2691. cfg->dialmax = lp->dialmax;
  2692. cfg->triggercps = lp->triggercps;
  2693. cfg->slavedelay = lp->slavedelay / HZ;
  2694. cfg->chargeint = (lp->hupflags & ISDN_CHARGEHUP) ?
  2695. (lp->chargeint / HZ) : 0;
  2696. cfg->pppbind = lp->pppbind;
  2697. cfg->dialtimeout = lp->dialtimeout >= 0 ? lp->dialtimeout / HZ : -1;
  2698. cfg->dialwait = lp->dialwait / HZ;
  2699. if (lp->slave) {
  2700. if (strlen(lp->slave->name) > 8)
  2701. strcpy(cfg->slave, "too-long");
  2702. else
  2703. strcpy(cfg->slave, lp->slave->name);
  2704. } else
  2705. cfg->slave[0] = '\0';
  2706. if (lp->master) {
  2707. if (strlen(lp->master->name) > 8)
  2708. strcpy(cfg->master, "too-long");
  2709. strcpy(cfg->master, lp->master->name);
  2710. } else
  2711. cfg->master[0] = '\0';
  2712. return 0;
  2713. }
  2714. return -ENODEV;
  2715. }
  2716. /*
  2717. * Add a phone-number to an interface.
  2718. */
  2719. int
  2720. isdn_net_addphone(isdn_net_ioctl_phone * phone)
  2721. {
  2722. isdn_net_dev *p = isdn_net_findif(phone->name);
  2723. isdn_net_phone *n;
  2724. if (p) {
  2725. if (!(n = kmalloc(sizeof(isdn_net_phone), GFP_KERNEL)))
  2726. return -ENOMEM;
  2727. strlcpy(n->num, phone->phone, sizeof(n->num));
  2728. n->next = p->local->phone[phone->outgoing & 1];
  2729. p->local->phone[phone->outgoing & 1] = n;
  2730. return 0;
  2731. }
  2732. return -ENODEV;
  2733. }
  2734. /*
  2735. * Copy a string of all phone-numbers of an interface to user space.
  2736. * This might sleep and must be called with the isdn semaphore down.
  2737. */
  2738. int
  2739. isdn_net_getphones(isdn_net_ioctl_phone * phone, char __user *phones)
  2740. {
  2741. isdn_net_dev *p = isdn_net_findif(phone->name);
  2742. int inout = phone->outgoing & 1;
  2743. int more = 0;
  2744. int count = 0;
  2745. isdn_net_phone *n;
  2746. if (!p)
  2747. return -ENODEV;
  2748. inout &= 1;
  2749. for (n = p->local->phone[inout]; n; n = n->next) {
  2750. if (more) {
  2751. put_user(' ', phones++);
  2752. count++;
  2753. }
  2754. if (copy_to_user(phones, n->num, strlen(n->num) + 1)) {
  2755. return -EFAULT;
  2756. }
  2757. phones += strlen(n->num);
  2758. count += strlen(n->num);
  2759. more = 1;
  2760. }
  2761. put_user(0, phones);
  2762. count++;
  2763. return count;
  2764. }
  2765. /*
  2766. * Copy a string containing the peer's phone number of a connected interface
  2767. * to user space.
  2768. */
  2769. int
  2770. isdn_net_getpeer(isdn_net_ioctl_phone *phone, isdn_net_ioctl_phone __user *peer)
  2771. {
  2772. isdn_net_dev *p = isdn_net_findif(phone->name);
  2773. int ch, dv, idx;
  2774. if (!p)
  2775. return -ENODEV;
  2776. /*
  2777. * Theoretical race: while this executes, the remote number might
  2778. * become invalid (hang up) or change (new connection), resulting
  2779. * in (partially) wrong number copied to user. This race
  2780. * currently ignored.
  2781. */
  2782. ch = p->local->isdn_channel;
  2783. dv = p->local->isdn_device;
  2784. if(ch < 0 && dv < 0)
  2785. return -ENOTCONN;
  2786. idx = isdn_dc2minor(dv, ch);
  2787. if (idx <0 )
  2788. return -ENODEV;
  2789. /* for pre-bound channels, we need this extra check */
  2790. if (strncmp(dev->num[idx], "???", 3) == 0)
  2791. return -ENOTCONN;
  2792. strncpy(phone->phone, dev->num[idx], ISDN_MSNLEN);
  2793. phone->outgoing = USG_OUTGOING(dev->usage[idx]);
  2794. if (copy_to_user(peer, phone, sizeof(*peer)))
  2795. return -EFAULT;
  2796. return 0;
  2797. }
  2798. /*
  2799. * Delete a phone-number from an interface.
  2800. */
  2801. int
  2802. isdn_net_delphone(isdn_net_ioctl_phone * phone)
  2803. {
  2804. isdn_net_dev *p = isdn_net_findif(phone->name);
  2805. int inout = phone->outgoing & 1;
  2806. isdn_net_phone *n;
  2807. isdn_net_phone *m;
  2808. if (p) {
  2809. n = p->local->phone[inout];
  2810. m = NULL;
  2811. while (n) {
  2812. if (!strcmp(n->num, phone->phone)) {
  2813. if (p->local->dial == n)
  2814. p->local->dial = n->next;
  2815. if (m)
  2816. m->next = n->next;
  2817. else
  2818. p->local->phone[inout] = n->next;
  2819. kfree(n);
  2820. return 0;
  2821. }
  2822. m = n;
  2823. n = (isdn_net_phone *) n->next;
  2824. }
  2825. return -EINVAL;
  2826. }
  2827. return -ENODEV;
  2828. }
  2829. /*
  2830. * Delete all phone-numbers of an interface.
  2831. */
  2832. static int
  2833. isdn_net_rmallphone(isdn_net_dev * p)
  2834. {
  2835. isdn_net_phone *n;
  2836. isdn_net_phone *m;
  2837. int i;
  2838. for (i = 0; i < 2; i++) {
  2839. n = p->local->phone[i];
  2840. while (n) {
  2841. m = n->next;
  2842. kfree(n);
  2843. n = m;
  2844. }
  2845. p->local->phone[i] = NULL;
  2846. }
  2847. p->local->dial = NULL;
  2848. return 0;
  2849. }
  2850. /*
  2851. * Force a hangup of a network-interface.
  2852. */
  2853. int
  2854. isdn_net_force_hangup(char *name)
  2855. {
  2856. isdn_net_dev *p = isdn_net_findif(name);
  2857. struct net_device *q;
  2858. if (p) {
  2859. if (p->local->isdn_device < 0)
  2860. return 1;
  2861. q = p->local->slave;
  2862. /* If this interface has slaves, do a hangup for them also. */
  2863. while (q) {
  2864. isdn_net_hangup(q);
  2865. q = MASTER_TO_SLAVE(q);
  2866. }
  2867. isdn_net_hangup(p->dev);
  2868. return 0;
  2869. }
  2870. return -ENODEV;
  2871. }
  2872. /*
  2873. * Helper-function for isdn_net_rm: Do the real work.
  2874. */
  2875. static int
  2876. isdn_net_realrm(isdn_net_dev * p, isdn_net_dev * q)
  2877. {
  2878. u_long flags;
  2879. if (isdn_net_device_started(p)) {
  2880. return -EBUSY;
  2881. }
  2882. #ifdef CONFIG_ISDN_X25
  2883. if( p -> cprot && p -> cprot -> pops )
  2884. p -> cprot -> pops -> proto_del ( p -> cprot );
  2885. #endif
  2886. /* Free all phone-entries */
  2887. isdn_net_rmallphone(p);
  2888. /* If interface is bound exclusive, free channel-usage */
  2889. if (p->local->exclusive != -1)
  2890. isdn_unexclusive_channel(p->local->pre_device, p->local->pre_channel);
  2891. if (p->local->master) {
  2892. /* It's a slave-device, so update master's slave-pointer if necessary */
  2893. if (((isdn_net_local *) ISDN_MASTER_PRIV(p->local))->slave ==
  2894. p->dev)
  2895. ((isdn_net_local *)ISDN_MASTER_PRIV(p->local))->slave =
  2896. p->local->slave;
  2897. } else {
  2898. /* Unregister only if it's a master-device */
  2899. unregister_netdev(p->dev);
  2900. }
  2901. /* Unlink device from chain */
  2902. spin_lock_irqsave(&dev->lock, flags);
  2903. if (q)
  2904. q->next = p->next;
  2905. else
  2906. dev->netdev = p->next;
  2907. if (p->local->slave) {
  2908. /* If this interface has a slave, remove it also */
  2909. char *slavename = p->local->slave->name;
  2910. isdn_net_dev *n = dev->netdev;
  2911. q = NULL;
  2912. while (n) {
  2913. if (!strcmp(n->dev->name, slavename)) {
  2914. spin_unlock_irqrestore(&dev->lock, flags);
  2915. isdn_net_realrm(n, q);
  2916. spin_lock_irqsave(&dev->lock, flags);
  2917. break;
  2918. }
  2919. q = n;
  2920. n = (isdn_net_dev *)n->next;
  2921. }
  2922. }
  2923. spin_unlock_irqrestore(&dev->lock, flags);
  2924. /* If no more net-devices remain, disable auto-hangup timer */
  2925. if (dev->netdev == NULL)
  2926. isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
  2927. free_netdev(p->dev);
  2928. kfree(p);
  2929. return 0;
  2930. }
  2931. /*
  2932. * Remove a single network-interface.
  2933. */
  2934. int
  2935. isdn_net_rm(char *name)
  2936. {
  2937. u_long flags;
  2938. isdn_net_dev *p;
  2939. isdn_net_dev *q;
  2940. /* Search name in netdev-chain */
  2941. spin_lock_irqsave(&dev->lock, flags);
  2942. p = dev->netdev;
  2943. q = NULL;
  2944. while (p) {
  2945. if (!strcmp(p->dev->name, name)) {
  2946. spin_unlock_irqrestore(&dev->lock, flags);
  2947. return (isdn_net_realrm(p, q));
  2948. }
  2949. q = p;
  2950. p = (isdn_net_dev *) p->next;
  2951. }
  2952. spin_unlock_irqrestore(&dev->lock, flags);
  2953. /* If no more net-devices remain, disable auto-hangup timer */
  2954. if (dev->netdev == NULL)
  2955. isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
  2956. return -ENODEV;
  2957. }
  2958. /*
  2959. * Remove all network-interfaces
  2960. */
  2961. int
  2962. isdn_net_rmall(void)
  2963. {
  2964. u_long flags;
  2965. int ret;
  2966. /* Walk through netdev-chain */
  2967. spin_lock_irqsave(&dev->lock, flags);
  2968. while (dev->netdev) {
  2969. if (!dev->netdev->local->master) {
  2970. /* Remove master-devices only, slaves get removed with their master */
  2971. spin_unlock_irqrestore(&dev->lock, flags);
  2972. if ((ret = isdn_net_realrm(dev->netdev, NULL))) {
  2973. return ret;
  2974. }
  2975. spin_lock_irqsave(&dev->lock, flags);
  2976. }
  2977. }
  2978. dev->netdev = NULL;
  2979. spin_unlock_irqrestore(&dev->lock, flags);
  2980. return 0;
  2981. }