isdn_net.c 87 KB

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