isdn_net.c 86 KB

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