PageRenderTime 255ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/isdn/i4l/isdn_net.c

https://bitbucket.org/ndreys/linux-sunxi
C | 3228 lines | 2447 code | 231 blank | 550 comment | 494 complexity | e4af6b4412a18b08bb4a326450040524 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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 is uses struct net_device
  58. * for masters and slaves. However, only master interface are registered to
  59. * the network layer, and therefore, it only makes sense to call netif_*
  60. * functions on them.
  61. *
  62. * --KG
  63. */
  64. /*
  65. * Find out if the netdevice has been ifup-ed yet.
  66. * For slaves, look at the corresponding master.
  67. */
  68. static __inline__ int isdn_net_device_started(isdn_net_dev *n)
  69. {
  70. isdn_net_local *lp = n->local;
  71. struct net_device *dev;
  72. if (lp->master)
  73. dev = lp->master;
  74. else
  75. dev = n->dev;
  76. return netif_running(dev);
  77. }
  78. /*
  79. * wake up the network -> net_device queue.
  80. * For slaves, wake the corresponding master interface.
  81. */
  82. static __inline__ void isdn_net_device_wake_queue(isdn_net_local *lp)
  83. {
  84. if (lp->master)
  85. netif_wake_queue(lp->master);
  86. else
  87. netif_wake_queue(lp->netdev->dev);
  88. }
  89. /*
  90. * stop the network -> net_device queue.
  91. * For slaves, stop the corresponding master interface.
  92. */
  93. static __inline__ void isdn_net_device_stop_queue(isdn_net_local *lp)
  94. {
  95. if (lp->master)
  96. netif_stop_queue(lp->master);
  97. else
  98. netif_stop_queue(lp->netdev->dev);
  99. }
  100. /*
  101. * find out if the net_device which this lp belongs to (lp can be
  102. * master or slave) is busy. It's busy iff all (master and slave)
  103. * queues are busy
  104. */
  105. static __inline__ int isdn_net_device_busy(isdn_net_local *lp)
  106. {
  107. isdn_net_local *nlp;
  108. isdn_net_dev *nd;
  109. unsigned long flags;
  110. if (!isdn_net_lp_busy(lp))
  111. return 0;
  112. if (lp->master)
  113. nd = ISDN_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->tail) {
  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 (memcmp(eth->h_dest, dev->broadcast, ETH_ALEN) == 0)
  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 (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN))
  1289. skb->pkt_type = PACKET_OTHERHOST;
  1290. }
  1291. if (ntohs(eth->h_proto) >= 1536)
  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. ushort len = 0;
  1749. switch (lp->p_encap) {
  1750. case ISDN_NET_ENCAP_ETHER:
  1751. len = eth_header(skb, dev, type, daddr, saddr, plen);
  1752. break;
  1753. #ifdef CONFIG_ISDN_PPP
  1754. case ISDN_NET_ENCAP_SYNCPPP:
  1755. /* stick on a fake header to keep fragmentation code happy. */
  1756. len = IPPP_MAX_HEADER;
  1757. skb_push(skb,len);
  1758. break;
  1759. #endif
  1760. case ISDN_NET_ENCAP_RAWIP:
  1761. printk(KERN_WARNING "isdn_net_header called with RAW_IP!\n");
  1762. len = 0;
  1763. break;
  1764. case ISDN_NET_ENCAP_IPTYP:
  1765. /* ethernet type field */
  1766. *((__be16 *)skb_push(skb, 2)) = htons(type);
  1767. len = 2;
  1768. break;
  1769. case ISDN_NET_ENCAP_UIHDLC:
  1770. /* HDLC with UI-Frames (for ispa with -h1 option) */
  1771. *((__be16 *)skb_push(skb, 2)) = htons(0x0103);
  1772. len = 2;
  1773. break;
  1774. case ISDN_NET_ENCAP_CISCOHDLC:
  1775. case ISDN_NET_ENCAP_CISCOHDLCK:
  1776. p = skb_push(skb, 4);
  1777. *(u8 *)(p + 0) = CISCO_ADDR_UNICAST;
  1778. *(u8 *)(p + 1) = CISCO_CTRL;
  1779. *(__be16 *)(p + 2) = cpu_to_be16(type);
  1780. p += 4;
  1781. len = 4;
  1782. break;
  1783. #ifdef CONFIG_ISDN_X25
  1784. default:
  1785. /* try if there are generic concap protocol routines */
  1786. if( lp-> netdev -> cprot ){
  1787. printk(KERN_WARNING "isdn_net_header called with concap_proto!\n");
  1788. len = 0;
  1789. break;
  1790. }
  1791. break;
  1792. #endif /* CONFIG_ISDN_X25 */
  1793. }
  1794. return len;
  1795. }
  1796. /* We don't need to send arp, because we have point-to-point connections. */
  1797. static int
  1798. isdn_net_rebuild_header(struct sk_buff *skb)
  1799. {
  1800. struct net_device *dev = skb->dev;
  1801. isdn_net_local *lp = netdev_priv(dev);
  1802. int ret = 0;
  1803. if (lp->p_encap == ISDN_NET_ENCAP_ETHER) {
  1804. struct ethhdr *eth = (struct ethhdr *) skb->data;
  1805. /*
  1806. * Only ARP/IP is currently supported
  1807. */
  1808. if (eth->h_proto != htons(ETH_P_IP)) {
  1809. printk(KERN_WARNING
  1810. "isdn_net: %s don't know how to resolve type %d addresses?\n",
  1811. dev->name, (int) eth->h_proto);
  1812. memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
  1813. return 0;
  1814. }
  1815. /*
  1816. * Try to get ARP to resolve the header.
  1817. */
  1818. #ifdef CONFIG_INET
  1819. ret = arp_find(eth->h_dest, skb);
  1820. #endif
  1821. }
  1822. return ret;
  1823. }
  1824. static int isdn_header_cache(const struct neighbour *neigh, struct hh_cache *hh)
  1825. {
  1826. const struct net_device *dev = neigh->dev;
  1827. isdn_net_local *lp = netdev_priv(dev);
  1828. if (lp->p_encap == ISDN_NET_ENCAP_ETHER)
  1829. return eth_header_cache(neigh, hh);
  1830. return -1;
  1831. }
  1832. static void isdn_header_cache_update(struct hh_cache *hh,
  1833. const struct net_device *dev,
  1834. const unsigned char *haddr)
  1835. {
  1836. isdn_net_local *lp = netdev_priv(dev);
  1837. if (lp->p_encap == ISDN_NET_ENCAP_ETHER)
  1838. eth_header_cache_update(hh, dev, haddr);
  1839. }
  1840. static const struct header_ops isdn_header_ops = {
  1841. .create = isdn_net_header,
  1842. .rebuild = isdn_net_rebuild_header,
  1843. .cache = isdn_header_cache,
  1844. .cache_update = isdn_header_cache_update,
  1845. };
  1846. /*
  1847. * Interface-setup. (just after registering a new interface)
  1848. */
  1849. static int
  1850. isdn_net_init(struct net_device *ndev)
  1851. {
  1852. ushort max_hlhdr_len = 0;
  1853. int drvidx;
  1854. /*
  1855. * up till binding we ask the protocol layer to reserve as much
  1856. * as we might need for HL layer
  1857. */
  1858. for (drvidx = 0; drvidx < ISDN_MAX_DRIVERS; drvidx++)
  1859. if (dev->drv[drvidx])
  1860. if (max_hlhdr_len < dev->drv[drvidx]->interface->hl_hdrlen)
  1861. max_hlhdr_len = dev->drv[drvidx]->interface->hl_hdrlen;
  1862. ndev->hard_header_len = ETH_HLEN + max_hlhdr_len;
  1863. return 0;
  1864. }
  1865. static void
  1866. isdn_net_swapbind(int drvidx)
  1867. {
  1868. isdn_net_dev *p;
  1869. #ifdef ISDN_DEBUG_NET_ICALL
  1870. printk(KERN_DEBUG "n_fi: swapping ch of %d\n", drvidx);
  1871. #endif
  1872. p = dev->netdev;
  1873. while (p) {
  1874. if (p->local->pre_device == drvidx)
  1875. switch (p->local->pre_channel) {
  1876. case 0:
  1877. p->local->pre_channel = 1;
  1878. break;
  1879. case 1:
  1880. p->local->pre_channel = 0;
  1881. break;
  1882. }
  1883. p = (isdn_net_dev *) p->next;
  1884. }
  1885. }
  1886. static void
  1887. isdn_net_swap_usage(int i1, int i2)
  1888. {
  1889. int u1 = dev->usage[i1] & ISDN_USAGE_EXCLUSIVE;
  1890. int u2 = dev->usage[i2] & ISDN_USAGE_EXCLUSIVE;
  1891. #ifdef ISDN_DEBUG_NET_ICALL
  1892. printk(KERN_DEBUG "n_fi: usage of %d and %d\n", i1, i2);
  1893. #endif
  1894. dev->usage[i1] &= ~ISDN_USAGE_EXCLUSIVE;
  1895. dev->usage[i1] |= u2;
  1896. dev->usage[i2] &= ~ISDN_USAGE_EXCLUSIVE;
  1897. dev->usage[i2] |= u1;
  1898. isdn_info_update();
  1899. }
  1900. /*
  1901. * An incoming call-request has arrived.
  1902. * Search the interface-chain for an appropriate interface.
  1903. * If found, connect the interface to the ISDN-channel and initiate
  1904. * D- and B-Channel-setup. If secure-flag is set, accept only
  1905. * configured phone-numbers. If callback-flag is set, initiate
  1906. * callback-dialing.
  1907. *
  1908. * Return-Value: 0 = No appropriate interface for this call.
  1909. * 1 = Call accepted
  1910. * 2 = Reject call, wait cbdelay, then call back
  1911. * 3 = Reject call
  1912. * 4 = Wait cbdelay, then call back
  1913. * 5 = No appropriate interface for this call,
  1914. * would eventually match if CID was longer.
  1915. */
  1916. int
  1917. isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
  1918. {
  1919. char *eaz;
  1920. int si1;
  1921. int si2;
  1922. int ematch;
  1923. int wret;
  1924. int swapped;
  1925. int sidx = 0;
  1926. u_long flags;
  1927. isdn_net_dev *p;
  1928. isdn_net_phone *n;
  1929. char nr[ISDN_MSNLEN];
  1930. char *my_eaz;
  1931. /* Search name in netdev-chain */
  1932. if (!setup->phone[0]) {
  1933. nr[0] = '0';
  1934. nr[1] = '\0';
  1935. printk(KERN_INFO "isdn_net: Incoming call without OAD, assuming '0'\n");
  1936. } else
  1937. strlcpy(nr, setup->phone, ISDN_MSNLEN);
  1938. si1 = (int) setup->si1;
  1939. si2 = (int) setup->si2;
  1940. if (!setup->eazmsn[0]) {
  1941. printk(KERN_WARNING "isdn_net: Incoming call without CPN, assuming '0'\n");
  1942. eaz = "0";
  1943. } else
  1944. eaz = setup->eazmsn;
  1945. if (dev->net_verbose > 1)
  1946. printk(KERN_INFO "isdn_net: call from %s,%d,%d -> %s\n", nr, si1, si2, eaz);
  1947. /* Accept DATA and VOICE calls at this stage
  1948. * local eaz is checked later for allowed call types
  1949. */
  1950. if ((si1 != 7) && (si1 != 1)) {
  1951. if (dev->net_verbose > 1)
  1952. printk(KERN_INFO "isdn_net: Service-Indicator not 1 or 7, ignored\n");
  1953. return 0;
  1954. }
  1955. n = (isdn_net_phone *) 0;
  1956. p = dev->netdev;
  1957. ematch = wret = swapped = 0;
  1958. #ifdef ISDN_DEBUG_NET_ICALL
  1959. printk(KERN_DEBUG "n_fi: di=%d ch=%d idx=%d usg=%d\n", di, ch, idx,
  1960. dev->usage[idx]);
  1961. #endif
  1962. while (p) {
  1963. int matchret;
  1964. isdn_net_local *lp = p->local;
  1965. /* If last check has triggered as binding-swap, revert it */
  1966. switch (swapped) {
  1967. case 2:
  1968. isdn_net_swap_usage(idx, sidx);
  1969. /* fall through */
  1970. case 1:
  1971. isdn_net_swapbind(di);
  1972. break;
  1973. }
  1974. swapped = 0;
  1975. /* check acceptable call types for DOV */
  1976. my_eaz = isdn_map_eaz2msn(lp->msn, di);
  1977. if (si1 == 1) { /* it's a DOV call, check if we allow it */
  1978. if (*my_eaz == 'v' || *my_eaz == 'V' ||
  1979. *my_eaz == 'b' || *my_eaz == 'B')
  1980. my_eaz++; /* skip to allow a match */
  1981. else
  1982. my_eaz = NULL; /* force non match */
  1983. } else { /* it's a DATA call, check if we allow it */
  1984. if (*my_eaz == 'b' || *my_eaz == 'B')
  1985. my_eaz++; /* skip to allow a match */
  1986. }
  1987. if (my_eaz)
  1988. matchret = isdn_msncmp(eaz, my_eaz);
  1989. else
  1990. matchret = 1;
  1991. if (!matchret)
  1992. ematch = 1;
  1993. /* Remember if more numbers eventually can match */
  1994. if (matchret > wret)
  1995. wret = matchret;
  1996. #ifdef ISDN_DEBUG_NET_ICALL
  1997. printk(KERN_DEBUG "n_fi: if='%s', l.msn=%s, l.flags=%d, l.dstate=%d\n",
  1998. p->dev->name, lp->msn, lp->flags, lp->dialstate);
  1999. #endif
  2000. if ((!matchret) && /* EAZ is matching */
  2001. (((!(lp->flags & ISDN_NET_CONNECTED)) && /* but not connected */
  2002. (USG_NONE(dev->usage[idx]))) || /* and ch. unused or */
  2003. ((((lp->dialstate == 4) || (lp->dialstate == 12)) && /* if dialing */
  2004. (!(lp->flags & ISDN_NET_CALLBACK))) /* but no callback */
  2005. )))
  2006. {
  2007. #ifdef ISDN_DEBUG_NET_ICALL
  2008. printk(KERN_DEBUG "n_fi: match1, pdev=%d pch=%d\n",
  2009. lp->pre_device, lp->pre_channel);
  2010. #endif
  2011. if (dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) {
  2012. if ((lp->pre_channel != ch) ||
  2013. (lp->pre_device != di)) {
  2014. /* Here we got a problem:
  2015. * If using an ICN-Card, an incoming call is always signaled on
  2016. * on the first channel of the card, if both channels are
  2017. * down. However this channel may be bound exclusive. If the
  2018. * second channel is free, this call should be accepted.
  2019. * The solution is horribly but it runs, so what:
  2020. * We exchange the exclusive bindings of the two channels, the
  2021. * corresponding variables in the interface-structs.
  2022. */
  2023. if (ch == 0) {
  2024. sidx = isdn_dc2minor(di, 1);
  2025. #ifdef ISDN_DEBUG_NET_ICALL
  2026. printk(KERN_DEBUG "n_fi: ch is 0\n");
  2027. #endif
  2028. if (USG_NONE(dev->usage[sidx])) {
  2029. /* Second Channel is free, now see if it is bound
  2030. * exclusive too. */
  2031. if (dev->usage[sidx] & ISDN_USAGE_EXCLUSIVE) {
  2032. #ifdef ISDN_DEBUG_NET_ICALL
  2033. printk(KERN_DEBUG "n_fi: 2nd channel is down and bound\n");
  2034. #endif
  2035. /* Yes, swap bindings only, if the original
  2036. * binding is bound to channel 1 of this driver */
  2037. if ((lp->pre_device == di) &&
  2038. (lp->pre_channel == 1)) {
  2039. isdn_net_swapbind(di);
  2040. swapped = 1;
  2041. } else {
  2042. /* ... else iterate next device */
  2043. p = (isdn_net_dev *) p->next;
  2044. continue;
  2045. }
  2046. } else {
  2047. #ifdef ISDN_DEBUG_NET_ICALL
  2048. printk(KERN_DEBUG "n_fi: 2nd channel is down and unbound\n");
  2049. #endif
  2050. /* No, swap always and swap excl-usage also */
  2051. isdn_net_swap_usage(idx, sidx);
  2052. isdn_net_swapbind(di);
  2053. swapped = 2;
  2054. }
  2055. /* Now check for exclusive binding again */
  2056. #ifdef ISDN_DEBUG_NET_ICALL
  2057. printk(KERN_DEBUG "n_fi: final check\n");
  2058. #endif
  2059. if ((dev->usage[idx] & ISDN_USAGE_EXCLUSIVE) &&
  2060. ((lp->pre_channel != ch) ||
  2061. (lp->pre_device != di))) {
  2062. #ifdef ISDN_DEBUG_NET_ICALL
  2063. printk(KERN_DEBUG "n_fi: final check failed\n");
  2064. #endif
  2065. p = (isdn_net_dev *) p->next;
  2066. continue;
  2067. }
  2068. }
  2069. } else {
  2070. /* We are already on the second channel, so nothing to do */
  2071. #ifdef ISDN_DEBUG_NET_ICALL
  2072. printk(KERN_DEBUG "n_fi: already on 2nd channel\n");
  2073. #endif
  2074. }
  2075. }
  2076. }
  2077. #ifdef ISDN_DEBUG_NET_ICALL
  2078. printk(KERN_DEBUG "n_fi: match2\n");
  2079. #endif
  2080. n = lp->phone[0];
  2081. if (lp->flags & ISDN_NET_SECURE) {
  2082. while (n) {
  2083. if (!isdn_msncmp(nr, n->num))
  2084. break;
  2085. n = (isdn_net_phone *) n->next;
  2086. }
  2087. }
  2088. if (n || (!(lp->flags & ISDN_NET_SECURE))) {
  2089. #ifdef ISDN_DEBUG_NET_ICALL
  2090. printk(KERN_DEBUG "n_fi: match3\n");
  2091. #endif
  2092. /* matching interface found */
  2093. /*
  2094. * Is the state STOPPED?
  2095. * If so, no dialin is allowed,
  2096. * so reject actively.
  2097. * */
  2098. if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
  2099. printk(KERN_INFO "incoming call, interface %s `stopped' -> rejected\n",
  2100. p->dev->name);
  2101. return 3;
  2102. }
  2103. /*
  2104. * Is the interface up?
  2105. * If not, reject the call actively.
  2106. */
  2107. if (!isdn_net_device_started(p)) {
  2108. printk(KERN_INFO "%s: incoming call, interface down -> rejected\n",
  2109. p->dev->name);
  2110. return 3;
  2111. }
  2112. /* Interface is up, now see if it's a slave. If so, see if
  2113. * it's master and parent slave is online. If not, reject the call.
  2114. */
  2115. if (lp->master) {
  2116. isdn_net_local *mlp = ISDN_MASTER_PRIV(lp);
  2117. printk(KERN_DEBUG "ICALLslv: %s\n", p->dev->name);
  2118. printk(KERN_DEBUG "master=%s\n", lp->master->name);
  2119. if (mlp->flags & ISDN_NET_CONNECTED) {
  2120. printk(KERN_DEBUG "master online\n");
  2121. /* Master is online, find parent-slave (master if first slave) */
  2122. while (mlp->slave) {
  2123. if (ISDN_SLAVE_PRIV(mlp) == lp)
  2124. break;
  2125. mlp = ISDN_SLAVE_PRIV(mlp);
  2126. }
  2127. } else
  2128. printk(KERN_DEBUG "master offline\n");
  2129. /* Found parent, if it's offline iterate next device */
  2130. printk(KERN_DEBUG "mlpf: %d\n", mlp->flags & ISDN_NET_CONNECTED);
  2131. if (!(mlp->flags & ISDN_NET_CONNECTED)) {
  2132. p = (isdn_net_dev *) p->next;
  2133. continue;
  2134. }
  2135. }
  2136. if (lp->flags & ISDN_NET_CALLBACK) {
  2137. int chi;
  2138. /*
  2139. * Is the state MANUAL?
  2140. * If so, no callback can be made,
  2141. * so reject actively.
  2142. * */
  2143. if (ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_OFF) {
  2144. printk(KERN_INFO "incoming call for callback, interface %s `off' -> rejected\n",
  2145. p->dev->name);
  2146. return 3;
  2147. }
  2148. printk(KERN_DEBUG "%s: call from %s -> %s, start callback\n",
  2149. p->dev->name, nr, eaz);
  2150. if (lp->phone[1]) {
  2151. /* Grab a free ISDN-Channel */
  2152. spin_lock_irqsave(&dev->lock, flags);
  2153. if ((chi =
  2154. isdn_get_free_channel(
  2155. ISDN_USAGE_NET,
  2156. lp->l2_proto,
  2157. lp->l3_proto,
  2158. lp->pre_device,
  2159. lp->pre_channel,
  2160. lp->msn)
  2161. ) < 0) {
  2162. printk(KERN_WARNING "isdn_net_find_icall: No channel for %s\n",
  2163. p->dev->name);
  2164. spin_unlock_irqrestore(&dev->lock, flags);
  2165. return 0;
  2166. }
  2167. /* Setup dialstate. */
  2168. lp->dtimer = 0;
  2169. lp->dialstate = 11;
  2170. /* Connect interface with channel */
  2171. isdn_net_bind_channel(lp, chi);
  2172. #ifdef CONFIG_ISDN_PPP
  2173. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  2174. if (isdn_ppp_bind(lp) < 0) {
  2175. spin_unlock_irqrestore(&dev->lock, flags);
  2176. isdn_net_unbind_channel(lp);
  2177. return 0;
  2178. }
  2179. #endif
  2180. spin_unlock_irqrestore(&dev->lock, flags);
  2181. /* Initiate dialing by returning 2 or 4 */
  2182. return (lp->flags & ISDN_NET_CBHUP) ? 2 : 4;
  2183. } else
  2184. printk(KERN_WARNING "isdn_net: %s: No phone number\n",
  2185. p->dev->name);
  2186. return 0;
  2187. } else {
  2188. printk(KERN_DEBUG "%s: call from %s -> %s accepted\n",
  2189. p->dev->name, nr, eaz);
  2190. /* if this interface is dialing, it does it probably on a different
  2191. device, so free this device */
  2192. if ((lp->dialstate == 4) || (lp->dialstate == 12)) {
  2193. #ifdef CONFIG_ISDN_PPP
  2194. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  2195. isdn_ppp_free(lp);
  2196. #endif
  2197. isdn_net_lp_disconnected(lp);
  2198. isdn_free_channel(lp->isdn_device, lp->isdn_channel,
  2199. ISDN_USAGE_NET);
  2200. }
  2201. spin_lock_irqsave(&dev->lock, flags);
  2202. dev->usage[idx] &= ISDN_USAGE_EXCLUSIVE;
  2203. dev->usage[idx] |= ISDN_USAGE_NET;
  2204. strcpy(dev->num[idx], nr);
  2205. isdn_info_update();
  2206. dev->st_netdev[idx] = lp->netdev;
  2207. lp->isdn_device = di;
  2208. lp->isdn_channel = ch;
  2209. lp->ppp_slot = -1;
  2210. lp->flags |= ISDN_NET_CONNECTED;
  2211. lp->dialstate = 7;
  2212. lp->dtimer = 0;
  2213. lp->outgoing = 0;
  2214. lp->huptimer = 0;
  2215. lp->hupflags |= ISDN_WAITCHARGE;
  2216. lp->hupflags &= ~ISDN_HAVECHARGE;
  2217. #ifdef CONFIG_ISDN_PPP
  2218. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP) {
  2219. if (isdn_ppp_bind(lp) < 0) {
  2220. isdn_net_unbind_channel(lp);
  2221. spin_unlock_irqrestore(&dev->lock, flags);
  2222. return 0;
  2223. }
  2224. }
  2225. #endif
  2226. spin_unlock_irqrestore(&dev->lock, flags);
  2227. return 1;
  2228. }
  2229. }
  2230. }
  2231. p = (isdn_net_dev *) p->next;
  2232. }
  2233. /* If none of configured EAZ/MSN matched and not verbose, be silent */
  2234. if (!ematch || dev->net_verbose)
  2235. printk(KERN_INFO "isdn_net: call from %s -> %d %s ignored\n", nr, di, eaz);
  2236. return (wret == 2)?5:0;
  2237. }
  2238. /*
  2239. * Search list of net-interfaces for an interface with given name.
  2240. */
  2241. isdn_net_dev *
  2242. isdn_net_findif(char *name)
  2243. {
  2244. isdn_net_dev *p = dev->netdev;
  2245. while (p) {
  2246. if (!strcmp(p->dev->name, name))
  2247. return p;
  2248. p = (isdn_net_dev *) p->next;
  2249. }
  2250. return (isdn_net_dev *) NULL;
  2251. }
  2252. /*
  2253. * Force a net-interface to dial out.
  2254. * This is called from the userlevel-routine below or
  2255. * from isdn_net_start_xmit().
  2256. */
  2257. static int
  2258. isdn_net_force_dial_lp(isdn_net_local * lp)
  2259. {
  2260. if ((!(lp->flags & ISDN_NET_CONNECTED)) && !lp->dialstate) {
  2261. int chi;
  2262. if (lp->phone[1]) {
  2263. ulong flags;
  2264. /* Grab a free ISDN-Channel */
  2265. spin_lock_irqsave(&dev->lock, flags);
  2266. if ((chi = isdn_get_free_channel(
  2267. ISDN_USAGE_NET,
  2268. lp->l2_proto,
  2269. lp->l3_proto,
  2270. lp->pre_device,
  2271. lp->pre_channel,
  2272. lp->msn)) < 0) {
  2273. printk(KERN_WARNING "isdn_net_force_dial: No channel for %s\n",
  2274. lp->netdev->dev->name);
  2275. spin_unlock_irqrestore(&dev->lock, flags);
  2276. return -EAGAIN;
  2277. }
  2278. lp->dialstate = 1;
  2279. /* Connect interface with channel */
  2280. isdn_net_bind_channel(lp, chi);
  2281. #ifdef CONFIG_ISDN_PPP
  2282. if (lp->p_encap == ISDN_NET_ENCAP_SYNCPPP)
  2283. if (isdn_ppp_bind(lp) < 0) {
  2284. isdn_net_unbind_channel(lp);
  2285. spin_unlock_irqrestore(&dev->lock, flags);
  2286. return -EAGAIN;
  2287. }
  2288. #endif
  2289. /* Initiate dialing */
  2290. spin_unlock_irqrestore(&dev->lock, flags);
  2291. isdn_net_dial();
  2292. return 0;
  2293. } else
  2294. return -EINVAL;
  2295. } else
  2296. return -EBUSY;
  2297. }
  2298. /*
  2299. * This is called from certain upper protocol layers (multilink ppp
  2300. * and x25iface encapsulation module) that want to initiate dialing
  2301. * themselves.
  2302. */
  2303. int
  2304. isdn_net_dial_req(isdn_net_local * lp)
  2305. {
  2306. /* is there a better error code? */
  2307. if (!(ISDN_NET_DIALMODE(*lp) == ISDN_NET_DM_AUTO)) return -EBUSY;
  2308. return isdn_net_force_dial_lp(lp);
  2309. }
  2310. /*
  2311. * Force a net-interface to dial out.
  2312. * This is always called from within userspace (ISDN_IOCTL_NET_DIAL).
  2313. */
  2314. int
  2315. isdn_net_force_dial(char *name)
  2316. {
  2317. isdn_net_dev *p = isdn_net_findif(name);
  2318. if (!p)
  2319. return -ENODEV;
  2320. return (isdn_net_force_dial_lp(p->local));
  2321. }
  2322. /* The ISDN-specific entries in the device structure. */
  2323. static const struct net_device_ops isdn_netdev_ops = {
  2324. .ndo_init = isdn_net_init,
  2325. .ndo_open = isdn_net_open,
  2326. .ndo_stop = isdn_net_close,
  2327. .ndo_do_ioctl = isdn_net_ioctl,
  2328. .ndo_start_xmit = isdn_net_start_xmit,
  2329. .ndo_get_stats = isdn_net_get_stats,
  2330. .ndo_tx_timeout = isdn_net_tx_timeout,
  2331. };
  2332. /*
  2333. * Helper for alloc_netdev()
  2334. */
  2335. static void _isdn_setup(struct net_device *dev)
  2336. {
  2337. isdn_net_local *lp = netdev_priv(dev);
  2338. ether_setup(dev);
  2339. /* Setup the generic properties */
  2340. dev->flags = IFF_NOARP|IFF_POINTOPOINT;
  2341. /* isdn prepends a header in the tx path, can't share skbs */
  2342. dev->priv_flags &= ~IFF_TX_SKB_SHARING;
  2343. dev->header_ops = NULL;
  2344. dev->netdev_ops = &isdn_netdev_ops;
  2345. /* for clients with MPPP maybe higher values better */
  2346. dev->tx_queue_len = 30;
  2347. lp->p_encap = ISDN_NET_ENCAP_RAWIP;
  2348. lp->magic = ISDN_NET_MAGIC;
  2349. lp->last = lp;
  2350. lp->next = lp;
  2351. lp->isdn_device = -1;
  2352. lp->isdn_channel = -1;
  2353. lp->pre_device = -1;
  2354. lp->pre_channel = -1;
  2355. lp->exclusive = -1;
  2356. lp->ppp_slot = -1;
  2357. lp->pppbind = -1;
  2358. skb_queue_head_init(&lp->super_tx_queue);
  2359. lp->l2_proto = ISDN_PROTO_L2_X75I;
  2360. lp->l3_proto = ISDN_PROTO_L3_TRANS;
  2361. lp->triggercps = 6000;
  2362. lp->slavedelay = 10 * HZ;
  2363. lp->hupflags = ISDN_INHUP; /* Do hangup even on incoming calls */
  2364. lp->onhtime = 10; /* Default hangup-time for saving costs */
  2365. lp->dialmax = 1;
  2366. /* Hangup before Callback, manual dial */
  2367. lp->flags = ISDN_NET_CBHUP | ISDN_NET_DM_MANUAL;
  2368. lp->cbdelay = 25; /* Wait 5 secs before Callback */
  2369. lp->dialtimeout = -1; /* Infinite Dial-Timeout */
  2370. lp->dialwait = 5 * HZ; /* Wait 5 sec. after failed dial */
  2371. lp->dialstarted = 0; /* Jiffies of last dial-start */
  2372. lp->dialwait_timer = 0; /* Jiffies of earliest next dial-start */
  2373. }
  2374. /*
  2375. * Allocate a new network-interface and initialize its data structures.
  2376. */
  2377. char *
  2378. isdn_net_new(char *name, struct net_device *master)
  2379. {
  2380. isdn_net_dev *netdev;
  2381. /* Avoid creating an existing interface */
  2382. if (isdn_net_findif(name)) {
  2383. printk(KERN_WARNING "isdn_net: interface %s already exists\n", name);
  2384. return NULL;
  2385. }
  2386. if (name == NULL)
  2387. return NULL;
  2388. if (!(netdev = kzalloc(sizeof(isdn_net_dev), GFP_KERNEL))) {
  2389. printk(KERN_WARNING "isdn_net: Could not allocate net-device\n");
  2390. return NULL;
  2391. }
  2392. netdev->dev = alloc_netdev(sizeof(isdn_net_local), name, _isdn_setup);
  2393. if (!netdev->dev) {
  2394. printk(KERN_WARNING "isdn_net: Could not allocate network device\n");
  2395. kfree(netdev);
  2396. return NULL;
  2397. }
  2398. netdev->local = netdev_priv(netdev->dev);
  2399. if (master) {
  2400. /* Device shall be a slave */
  2401. struct net_device *p = MASTER_TO_SLAVE(master);
  2402. struct net_device *q = master;
  2403. netdev->local->master = master;
  2404. /* Put device at end of slave-chain */
  2405. while (p) {
  2406. q = p;
  2407. p = MASTER_TO_SLAVE(p);
  2408. }
  2409. MASTER_TO_SLAVE(q) = netdev->dev;
  2410. } else {
  2411. /* Device shall be a master */
  2412. /*
  2413. * Watchdog timer (currently) for master only.
  2414. */
  2415. netdev->dev->watchdog_timeo = ISDN_NET_TX_TIMEOUT;
  2416. if (register_netdev(netdev->dev) != 0) {
  2417. printk(KERN_WARNING "isdn_net: Could not register net-device\n");
  2418. free_netdev(netdev->dev);
  2419. kfree(netdev);
  2420. return NULL;
  2421. }
  2422. }
  2423. netdev->queue = netdev->local;
  2424. spin_lock_init(&netdev->queue_lock);
  2425. netdev->local->netdev = netdev;
  2426. INIT_WORK(&netdev->local->tqueue, isdn_net_softint);
  2427. spin_lock_init(&netdev->local->xmit_lock);
  2428. /* Put into to netdev-chain */
  2429. netdev->next = (void *) dev->netdev;
  2430. dev->netdev = netdev;
  2431. return netdev->dev->name;
  2432. }
  2433. char *
  2434. isdn_net_newslave(char *parm)
  2435. {
  2436. char *p = strchr(parm, ',');
  2437. isdn_net_dev *n;
  2438. char newname[10];
  2439. if (p) {
  2440. /* Slave-Name MUST not be empty */
  2441. if (!strlen(p + 1))
  2442. return NULL;
  2443. strcpy(newname, p + 1);
  2444. *p = 0;
  2445. /* Master must already exist */
  2446. if (!(n = isdn_net_findif(parm)))
  2447. return NULL;
  2448. /* Master must be a real interface, not a slave */
  2449. if (n->local->master)
  2450. return NULL;
  2451. /* Master must not be started yet */
  2452. if (isdn_net_device_started(n))
  2453. return NULL;
  2454. return (isdn_net_new(newname, n->dev));
  2455. }
  2456. return NULL;
  2457. }
  2458. /*
  2459. * Set interface-parameters.
  2460. * Always set all parameters, so the user-level application is responsible
  2461. * for not overwriting existing setups. It has to get the current
  2462. * setup first, if only selected parameters are to be changed.
  2463. */
  2464. int
  2465. isdn_net_setcfg(isdn_net_ioctl_cfg * cfg)
  2466. {
  2467. isdn_net_dev *p = isdn_net_findif(cfg->name);
  2468. ulong features;
  2469. int i;
  2470. int drvidx;
  2471. int chidx;
  2472. char drvid[25];
  2473. if (p) {
  2474. isdn_net_local *lp = p->local;
  2475. /* See if any registered driver supports the features we want */
  2476. features = ((1 << cfg->l2_proto) << ISDN_FEATURE_L2_SHIFT) |
  2477. ((1 << cfg->l3_proto) << ISDN_FEATURE_L3_SHIFT);
  2478. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  2479. if (dev->drv[i])
  2480. if ((dev->drv[i]->interface->features & features) == features)
  2481. break;
  2482. if (i == ISDN_MAX_DRIVERS) {
  2483. printk(KERN_WARNING "isdn_net: No driver with selected features\n");
  2484. return -ENODEV;
  2485. }
  2486. if (lp->p_encap != cfg->p_encap){
  2487. #ifdef CONFIG_ISDN_X25
  2488. struct concap_proto * cprot = p -> cprot;
  2489. #endif
  2490. if (isdn_net_device_started(p)) {
  2491. printk(KERN_WARNING "%s: cannot change encap when if is up\n",
  2492. p->dev->name);
  2493. return -EBUSY;
  2494. }
  2495. #ifdef CONFIG_ISDN_X25
  2496. if( cprot && cprot -> pops )
  2497. cprot -> pops -> proto_del ( cprot );
  2498. p -> cprot = NULL;
  2499. lp -> dops = NULL;
  2500. /* ... , prepare for configuration of new one ... */
  2501. switch ( cfg -> p_encap ){
  2502. case ISDN_NET_ENCAP_X25IFACE:
  2503. lp -> dops = &isdn_concap_reliable_dl_dops;
  2504. }
  2505. /* ... and allocate new one ... */
  2506. p -> cprot = isdn_concap_new( cfg -> p_encap );
  2507. /* p -> cprot == NULL now if p_encap is not supported
  2508. by means of the concap_proto mechanism */
  2509. /* the protocol is not configured yet; this will
  2510. happen later when isdn_net_reset() is called */
  2511. #endif
  2512. }
  2513. switch ( cfg->p_encap ) {
  2514. case ISDN_NET_ENCAP_SYNCPPP:
  2515. #ifndef CONFIG_ISDN_PPP
  2516. printk(KERN_WARNING "%s: SyncPPP support not configured\n",
  2517. p->dev->name);
  2518. return -EINVAL;
  2519. #else
  2520. p->dev->type = ARPHRD_PPP; /* change ARP type */
  2521. p->dev->addr_len = 0;
  2522. #endif
  2523. break;
  2524. case ISDN_NET_ENCAP_X25IFACE:
  2525. #ifndef CONFIG_ISDN_X25
  2526. printk(KERN_WARNING "%s: isdn-x25 support not configured\n",
  2527. p->dev->name);
  2528. return -EINVAL;
  2529. #else
  2530. p->dev->type = ARPHRD_X25; /* change ARP type */
  2531. p->dev->addr_len = 0;
  2532. #endif
  2533. break;
  2534. case ISDN_NET_ENCAP_CISCOHDLCK:
  2535. break;
  2536. default:
  2537. if( cfg->p_encap >= 0 &&
  2538. cfg->p_encap <= ISDN_NET_ENCAP_MAX_ENCAP )
  2539. break;
  2540. printk(KERN_WARNING
  2541. "%s: encapsulation protocol %d not supported\n",
  2542. p->dev->name, cfg->p_encap);
  2543. return -EINVAL;
  2544. }
  2545. if (strlen(cfg->drvid)) {
  2546. /* A bind has been requested ... */
  2547. char *c,
  2548. *e;
  2549. drvidx = -1;
  2550. chidx = -1;
  2551. strcpy(drvid, cfg->drvid);
  2552. if ((c = strchr(drvid, ','))) {
  2553. /* The channel-number is appended to the driver-Id with a comma */
  2554. chidx = (int) simple_strtoul(c + 1, &e, 10);
  2555. if (e == c)
  2556. chidx = -1;
  2557. *c = '\0';
  2558. }
  2559. for (i = 0; i < ISDN_MAX_DRIVERS; i++)
  2560. /* Lookup driver-Id in array */
  2561. if (!(strcmp(dev->drvid[i], drvid))) {
  2562. drvidx = i;
  2563. break;
  2564. }
  2565. if ((drvidx == -1) || (chidx == -1))
  2566. /* Either driver-Id or channel-number invalid */
  2567. return -ENODEV;
  2568. } else {
  2569. /* Parameters are valid, so get them */
  2570. drvidx = lp->pre_device;
  2571. chidx = lp->pre_channel;
  2572. }
  2573. if (cfg->exclusive > 0) {
  2574. unsigned long flags;
  2575. /* If binding is exclusive, try to grab the channel */
  2576. spin_lock_irqsave(&dev->lock, flags);
  2577. if ((i = isdn_get_free_channel(ISDN_USAGE_NET,
  2578. lp->l2_proto, lp->l3_proto, drvidx,
  2579. chidx, lp->msn)) < 0) {
  2580. /* Grab failed, because desired channel is in use */
  2581. lp->exclusive = -1;
  2582. spin_unlock_irqrestore(&dev->lock, flags);
  2583. return -EBUSY;
  2584. }
  2585. /* All went ok, so update isdninfo */
  2586. dev->usage[i] = ISDN_USAGE_EXCLUSIVE;
  2587. isdn_info_update();
  2588. spin_unlock_irqrestore(&dev->lock, flags);
  2589. lp->exclusive = i;
  2590. } else {
  2591. /* Non-exclusive binding or unbind. */
  2592. lp->exclusive = -1;
  2593. if ((lp->pre_device != -1) && (cfg->exclusive == -1)) {
  2594. isdn_unexclusive_channel(lp->pre_device, lp->pre_channel);
  2595. isdn_free_channel(lp->pre_device, lp->pre_channel, ISDN_USAGE_NET);
  2596. drvidx = -1;
  2597. chidx = -1;
  2598. }
  2599. }
  2600. strlcpy(lp->msn, cfg->eaz, sizeof(lp->msn));
  2601. lp->pre_device = drvidx;
  2602. lp->pre_channel = chidx;
  2603. lp->onhtime = cfg->onhtime;
  2604. lp->charge = cfg->charge;
  2605. lp->l2_proto = cfg->l2_proto;
  2606. lp->l3_proto = cfg->l3_proto;
  2607. lp->cbdelay = cfg->cbdelay;
  2608. lp->dialmax = cfg->dialmax;
  2609. lp->triggercps = cfg->triggercps;
  2610. lp->slavedelay = cfg->slavedelay * HZ;
  2611. lp->pppbind = cfg->pppbind;
  2612. lp->dialtimeout = cfg->dialtimeout >= 0 ? cfg->dialtimeout * HZ : -1;
  2613. lp->dialwait = cfg->dialwait * HZ;
  2614. if (cfg->secure)
  2615. lp->flags |= ISDN_NET_SECURE;
  2616. else
  2617. lp->flags &= ~ISDN_NET_SECURE;
  2618. if (cfg->cbhup)
  2619. lp->flags |= ISDN_NET_CBHUP;
  2620. else
  2621. lp->flags &= ~ISDN_NET_CBHUP;
  2622. switch (cfg->callback) {
  2623. case 0:
  2624. lp->flags &= ~(ISDN_NET_CALLBACK | ISDN_NET_CBOUT);
  2625. break;
  2626. case 1:
  2627. lp->flags |= ISDN_NET_CALLBACK;
  2628. lp->flags &= ~ISDN_NET_CBOUT;
  2629. break;
  2630. case 2:
  2631. lp->flags |= ISDN_NET_CBOUT;
  2632. lp->flags &= ~ISDN_NET_CALLBACK;
  2633. break;
  2634. }
  2635. lp->flags &= ~ISDN_NET_DIALMODE_MASK; /* first all bits off */
  2636. if (cfg->dialmode && !(cfg->dialmode & ISDN_NET_DIALMODE_MASK)) {
  2637. /* old isdnctrl version, where only 0 or 1 is given */
  2638. printk(KERN_WARNING
  2639. "Old isdnctrl version detected! Please update.\n");
  2640. lp->flags |= ISDN_NET_DM_OFF; /* turn on `off' bit */
  2641. }
  2642. else {
  2643. lp->flags |= cfg->dialmode; /* turn on selected bits */
  2644. }
  2645. if (cfg->chargehup)
  2646. lp->hupflags |= ISDN_CHARGEHUP;
  2647. else
  2648. lp->hupflags &= ~ISDN_CHARGEHUP;
  2649. if (cfg->ihup)
  2650. lp->hupflags |= ISDN_INHUP;
  2651. else
  2652. lp->hupflags &= ~ISDN_INHUP;
  2653. if (cfg->chargeint > 10) {
  2654. lp->hupflags |= ISDN_CHARGEHUP | ISDN_HAVECHARGE | ISDN_MANCHARGE;
  2655. lp->chargeint = cfg->chargeint * HZ;
  2656. }
  2657. if (cfg->p_encap != lp->p_encap) {
  2658. if (cfg->p_encap == ISDN_NET_ENCAP_RAWIP) {
  2659. p->dev->header_ops = NULL;
  2660. p->dev->flags = IFF_NOARP|IFF_POINTOPOINT;
  2661. } else {
  2662. p->dev->header_ops = &isdn_header_ops;
  2663. if (cfg->p_encap == ISDN_NET_ENCAP_ETHER)
  2664. p->dev->flags = IFF_BROADCAST | IFF_MULTICAST;
  2665. else
  2666. p->dev->flags = IFF_NOARP|IFF_POINTOPOINT;
  2667. }
  2668. }
  2669. lp->p_encap = cfg->p_encap;
  2670. return 0;
  2671. }
  2672. return -ENODEV;
  2673. }
  2674. /*
  2675. * Perform get-interface-parameters.ioctl
  2676. */
  2677. int
  2678. isdn_net_getcfg(isdn_net_ioctl_cfg * cfg)
  2679. {
  2680. isdn_net_dev *p = isdn_net_findif(cfg->name);
  2681. if (p) {
  2682. isdn_net_local *lp = p->local;
  2683. strcpy(cfg->eaz, lp->msn);
  2684. cfg->exclusive = lp->exclusive;
  2685. if (lp->pre_device >= 0) {
  2686. sprintf(cfg->drvid, "%s,%d", dev->drvid[lp->pre_device],
  2687. lp->pre_channel);
  2688. } else
  2689. cfg->drvid[0] = '\0';
  2690. cfg->onhtime = lp->onhtime;
  2691. cfg->charge = lp->charge;
  2692. cfg->l2_proto = lp->l2_proto;
  2693. cfg->l3_proto = lp->l3_proto;
  2694. cfg->p_encap = lp->p_encap;
  2695. cfg->secure = (lp->flags & ISDN_NET_SECURE) ? 1 : 0;
  2696. cfg->callback = 0;
  2697. if (lp->flags & ISDN_NET_CALLBACK)
  2698. cfg->callback = 1;
  2699. if (lp->flags & ISDN_NET_CBOUT)
  2700. cfg->callback = 2;
  2701. cfg->cbhup = (lp->flags & ISDN_NET_CBHUP) ? 1 : 0;
  2702. cfg->dialmode = lp->flags & ISDN_NET_DIALMODE_MASK;
  2703. cfg->chargehup = (lp->hupflags & 4) ? 1 : 0;
  2704. cfg->ihup = (lp->hupflags & 8) ? 1 : 0;
  2705. cfg->cbdelay = lp->cbdelay;
  2706. cfg->dialmax = lp->dialmax;
  2707. cfg->triggercps = lp->triggercps;
  2708. cfg->slavedelay = lp->slavedelay / HZ;
  2709. cfg->chargeint = (lp->hupflags & ISDN_CHARGEHUP) ?
  2710. (lp->chargeint / HZ) : 0;
  2711. cfg->pppbind = lp->pppbind;
  2712. cfg->dialtimeout = lp->dialtimeout >= 0 ? lp->dialtimeout / HZ : -1;
  2713. cfg->dialwait = lp->dialwait / HZ;
  2714. if (lp->slave) {
  2715. if (strlen(lp->slave->name) >= 10)
  2716. strcpy(cfg->slave, "too-long");
  2717. else
  2718. strcpy(cfg->slave, lp->slave->name);
  2719. } else
  2720. cfg->slave[0] = '\0';
  2721. if (lp->master) {
  2722. if (strlen(lp->master->name) >= 10)
  2723. strcpy(cfg->master, "too-long");
  2724. else
  2725. strcpy(cfg->master, lp->master->name);
  2726. } else
  2727. cfg->master[0] = '\0';
  2728. return 0;
  2729. }
  2730. return -ENODEV;
  2731. }
  2732. /*
  2733. * Add a phone-number to an interface.
  2734. */
  2735. int
  2736. isdn_net_addphone(isdn_net_ioctl_phone * phone)
  2737. {
  2738. isdn_net_dev *p = isdn_net_findif(phone->name);
  2739. isdn_net_phone *n;
  2740. if (p) {
  2741. if (!(n = kmalloc(sizeof(isdn_net_phone), GFP_KERNEL)))
  2742. return -ENOMEM;
  2743. strlcpy(n->num, phone->phone, sizeof(n->num));
  2744. n->next = p->local->phone[phone->outgoing & 1];
  2745. p->local->phone[phone->outgoing & 1] = n;
  2746. return 0;
  2747. }
  2748. return -ENODEV;
  2749. }
  2750. /*
  2751. * Copy a string of all phone-numbers of an interface to user space.
  2752. * This might sleep and must be called with the isdn semaphore down.
  2753. */
  2754. int
  2755. isdn_net_getphones(isdn_net_ioctl_phone * phone, char __user *phones)
  2756. {
  2757. isdn_net_dev *p = isdn_net_findif(phone->name);
  2758. int inout = phone->outgoing & 1;
  2759. int more = 0;
  2760. int count = 0;
  2761. isdn_net_phone *n;
  2762. if (!p)
  2763. return -ENODEV;
  2764. inout &= 1;
  2765. for (n = p->local->phone[inout]; n; n = n->next) {
  2766. if (more) {
  2767. put_user(' ', phones++);
  2768. count++;
  2769. }
  2770. if (copy_to_user(phones, n->num, strlen(n->num) + 1)) {
  2771. return -EFAULT;
  2772. }
  2773. phones += strlen(n->num);
  2774. count += strlen(n->num);
  2775. more = 1;
  2776. }
  2777. put_user(0, phones);
  2778. count++;
  2779. return count;
  2780. }
  2781. /*
  2782. * Copy a string containing the peer's phone number of a connected interface
  2783. * to user space.
  2784. */
  2785. int
  2786. isdn_net_getpeer(isdn_net_ioctl_phone *phone, isdn_net_ioctl_phone __user *peer)
  2787. {
  2788. isdn_net_dev *p = isdn_net_findif(phone->name);
  2789. int ch, dv, idx;
  2790. if (!p)
  2791. return -ENODEV;
  2792. /*
  2793. * Theoretical race: while this executes, the remote number might
  2794. * become invalid (hang up) or change (new connection), resulting
  2795. * in (partially) wrong number copied to user. This race
  2796. * currently ignored.
  2797. */
  2798. ch = p->local->isdn_channel;
  2799. dv = p->local->isdn_device;
  2800. if(ch < 0 && dv < 0)
  2801. return -ENOTCONN;
  2802. idx = isdn_dc2minor(dv, ch);
  2803. if (idx <0 )
  2804. return -ENODEV;
  2805. /* for pre-bound channels, we need this extra check */
  2806. if (strncmp(dev->num[idx], "???", 3) == 0)
  2807. return -ENOTCONN;
  2808. strncpy(phone->phone, dev->num[idx], ISDN_MSNLEN);
  2809. phone->outgoing = USG_OUTGOING(dev->usage[idx]);
  2810. if (copy_to_user(peer, phone, sizeof(*peer)))
  2811. return -EFAULT;
  2812. return 0;
  2813. }
  2814. /*
  2815. * Delete a phone-number from an interface.
  2816. */
  2817. int
  2818. isdn_net_delphone(isdn_net_ioctl_phone * phone)
  2819. {
  2820. isdn_net_dev *p = isdn_net_findif(phone->name);
  2821. int inout = phone->outgoing & 1;
  2822. isdn_net_phone *n;
  2823. isdn_net_phone *m;
  2824. if (p) {
  2825. n = p->local->phone[inout];
  2826. m = NULL;
  2827. while (n) {
  2828. if (!strcmp(n->num, phone->phone)) {
  2829. if (p->local->dial == n)
  2830. p->local->dial = n->next;
  2831. if (m)
  2832. m->next = n->next;
  2833. else
  2834. p->local->phone[inout] = n->next;
  2835. kfree(n);
  2836. return 0;
  2837. }
  2838. m = n;
  2839. n = (isdn_net_phone *) n->next;
  2840. }
  2841. return -EINVAL;
  2842. }
  2843. return -ENODEV;
  2844. }
  2845. /*
  2846. * Delete all phone-numbers of an interface.
  2847. */
  2848. static int
  2849. isdn_net_rmallphone(isdn_net_dev * p)
  2850. {
  2851. isdn_net_phone *n;
  2852. isdn_net_phone *m;
  2853. int i;
  2854. for (i = 0; i < 2; i++) {
  2855. n = p->local->phone[i];
  2856. while (n) {
  2857. m = n->next;
  2858. kfree(n);
  2859. n = m;
  2860. }
  2861. p->local->phone[i] = NULL;
  2862. }
  2863. p->local->dial = NULL;
  2864. return 0;
  2865. }
  2866. /*
  2867. * Force a hangup of a network-interface.
  2868. */
  2869. int
  2870. isdn_net_force_hangup(char *name)
  2871. {
  2872. isdn_net_dev *p = isdn_net_findif(name);
  2873. struct net_device *q;
  2874. if (p) {
  2875. if (p->local->isdn_device < 0)
  2876. return 1;
  2877. q = p->local->slave;
  2878. /* If this interface has slaves, do a hangup for them also. */
  2879. while (q) {
  2880. isdn_net_hangup(q);
  2881. q = MASTER_TO_SLAVE(q);
  2882. }
  2883. isdn_net_hangup(p->dev);
  2884. return 0;
  2885. }
  2886. return -ENODEV;
  2887. }
  2888. /*
  2889. * Helper-function for isdn_net_rm: Do the real work.
  2890. */
  2891. static int
  2892. isdn_net_realrm(isdn_net_dev * p, isdn_net_dev * q)
  2893. {
  2894. u_long flags;
  2895. if (isdn_net_device_started(p)) {
  2896. return -EBUSY;
  2897. }
  2898. #ifdef CONFIG_ISDN_X25
  2899. if( p -> cprot && p -> cprot -> pops )
  2900. p -> cprot -> pops -> proto_del ( p -> cprot );
  2901. #endif
  2902. /* Free all phone-entries */
  2903. isdn_net_rmallphone(p);
  2904. /* If interface is bound exclusive, free channel-usage */
  2905. if (p->local->exclusive != -1)
  2906. isdn_unexclusive_channel(p->local->pre_device, p->local->pre_channel);
  2907. if (p->local->master) {
  2908. /* It's a slave-device, so update master's slave-pointer if necessary */
  2909. if (((isdn_net_local *) ISDN_MASTER_PRIV(p->local))->slave ==
  2910. p->dev)
  2911. ((isdn_net_local *)ISDN_MASTER_PRIV(p->local))->slave =
  2912. p->local->slave;
  2913. } else {
  2914. /* Unregister only if it's a master-device */
  2915. unregister_netdev(p->dev);
  2916. }
  2917. /* Unlink device from chain */
  2918. spin_lock_irqsave(&dev->lock, flags);
  2919. if (q)
  2920. q->next = p->next;
  2921. else
  2922. dev->netdev = p->next;
  2923. if (p->local->slave) {
  2924. /* If this interface has a slave, remove it also */
  2925. char *slavename = p->local->slave->name;
  2926. isdn_net_dev *n = dev->netdev;
  2927. q = NULL;
  2928. while (n) {
  2929. if (!strcmp(n->dev->name, slavename)) {
  2930. spin_unlock_irqrestore(&dev->lock, flags);
  2931. isdn_net_realrm(n, q);
  2932. spin_lock_irqsave(&dev->lock, flags);
  2933. break;
  2934. }
  2935. q = n;
  2936. n = (isdn_net_dev *)n->next;
  2937. }
  2938. }
  2939. spin_unlock_irqrestore(&dev->lock, flags);
  2940. /* If no more net-devices remain, disable auto-hangup timer */
  2941. if (dev->netdev == NULL)
  2942. isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
  2943. free_netdev(p->dev);
  2944. kfree(p);
  2945. return 0;
  2946. }
  2947. /*
  2948. * Remove a single network-interface.
  2949. */
  2950. int
  2951. isdn_net_rm(char *name)
  2952. {
  2953. u_long flags;
  2954. isdn_net_dev *p;
  2955. isdn_net_dev *q;
  2956. /* Search name in netdev-chain */
  2957. spin_lock_irqsave(&dev->lock, flags);
  2958. p = dev->netdev;
  2959. q = NULL;
  2960. while (p) {
  2961. if (!strcmp(p->dev->name, name)) {
  2962. spin_unlock_irqrestore(&dev->lock, flags);
  2963. return (isdn_net_realrm(p, q));
  2964. }
  2965. q = p;
  2966. p = (isdn_net_dev *) p->next;
  2967. }
  2968. spin_unlock_irqrestore(&dev->lock, flags);
  2969. /* If no more net-devices remain, disable auto-hangup timer */
  2970. if (dev->netdev == NULL)
  2971. isdn_timer_ctrl(ISDN_TIMER_NETHANGUP, 0);
  2972. return -ENODEV;
  2973. }
  2974. /*
  2975. * Remove all network-interfaces
  2976. */
  2977. int
  2978. isdn_net_rmall(void)
  2979. {
  2980. u_long flags;
  2981. int ret;
  2982. /* Walk through netdev-chain */
  2983. spin_lock_irqsave(&dev->lock, flags);
  2984. while (dev->netdev) {
  2985. if (!dev->netdev->local->master) {
  2986. /* Remove master-devices only, slaves get removed with their master */
  2987. spin_unlock_irqrestore(&dev->lock, flags);
  2988. if ((ret = isdn_net_realrm(dev->netdev, NULL))) {
  2989. return ret;
  2990. }
  2991. spin_lock_irqsave(&dev->lock, flags);
  2992. }
  2993. }
  2994. dev->netdev = NULL;
  2995. spin_unlock_irqrestore(&dev->lock, flags);
  2996. return 0;
  2997. }