isdn_net.c 86 KB

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