isdn_net.c 85 KB

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