if_ct.c (158651) | if_ct.c (164033) |
---|---|
1/*- 2 * Cronyx-Tau adapter driver for FreeBSD. 3 * Supports PPP/HDLC and Cisco/HDLC protocol in synchronous mode, 4 * and asyncronous channels with full modem control. 5 * Keepalive protocol implemented in both Cisco and PPP modes. 6 * 7 * Copyright (C) 1994-2002 Cronyx Engineering. 8 * Author: Serge Vakulenko, <vak@cronyx.ru> --- 8 unchanged lines hidden (view full) --- 17 * modify and redistribute this software in source and binary forms, 18 * as long as this message is kept with the software, all derivative 19 * works or modified versions. 20 * 21 * Cronyx Id: if_ct.c,v 1.1.2.31 2004/06/23 17:09:13 rik Exp $ 22 */ 23 24#include <sys/cdefs.h> | 1/*- 2 * Cronyx-Tau adapter driver for FreeBSD. 3 * Supports PPP/HDLC and Cisco/HDLC protocol in synchronous mode, 4 * and asyncronous channels with full modem control. 5 * Keepalive protocol implemented in both Cisco and PPP modes. 6 * 7 * Copyright (C) 1994-2002 Cronyx Engineering. 8 * Author: Serge Vakulenko, <vak@cronyx.ru> --- 8 unchanged lines hidden (view full) --- 17 * modify and redistribute this software in source and binary forms, 18 * as long as this message is kept with the software, all derivative 19 * works or modified versions. 20 * 21 * Cronyx Id: if_ct.c,v 1.1.2.31 2004/06/23 17:09:13 rik Exp $ 22 */ 23 24#include <sys/cdefs.h> |
25__FBSDID("$FreeBSD: head/sys/dev/ctau/if_ct.c 158651 2006-05-16 14:37:58Z phk $"); | 25__FBSDID("$FreeBSD: head/sys/dev/ctau/if_ct.c 164033 2006-11-06 13:42:10Z rwatson $"); |
26 27#include <sys/param.h> 28#include <sys/proc.h> 29#include <sys/systm.h> 30#include <sys/kernel.h> 31#include <sys/module.h> 32#include <sys/mbuf.h> 33#include <sys/sockio.h> 34#include <sys/malloc.h> | 26 27#include <sys/param.h> 28#include <sys/proc.h> 29#include <sys/systm.h> 30#include <sys/kernel.h> 31#include <sys/module.h> 32#include <sys/mbuf.h> 33#include <sys/sockio.h> 34#include <sys/malloc.h> |
35#include <sys/priv.h> |
|
35#include <sys/socket.h> 36#include <sys/sysctl.h> 37#include <sys/conf.h> 38#include <sys/errno.h> 39#include <sys/tty.h> 40#include <sys/bus.h> 41#include <machine/bus.h> 42#include <sys/rman.h> --- 1252 unchanged lines hidden (view full) --- 1295#ifndef NETGRAPH 1296 case SERIAL_GETPROTO: 1297 strcpy ((char*)data, (IFP2SP(d->ifp)->pp_flags & PP_FR) ? "fr" : 1298 (d->ifp->if_flags & PP_CISCO) ? "cisco" : "ppp"); 1299 return 0; 1300 1301 case SERIAL_SETPROTO: 1302 /* Only for superuser! */ | 36#include <sys/socket.h> 37#include <sys/sysctl.h> 38#include <sys/conf.h> 39#include <sys/errno.h> 40#include <sys/tty.h> 41#include <sys/bus.h> 42#include <machine/bus.h> 43#include <sys/rman.h> --- 1252 unchanged lines hidden (view full) --- 1296#ifndef NETGRAPH 1297 case SERIAL_GETPROTO: 1298 strcpy ((char*)data, (IFP2SP(d->ifp)->pp_flags & PP_FR) ? "fr" : 1299 (d->ifp->if_flags & PP_CISCO) ? "cisco" : "ppp"); 1300 return 0; 1301 1302 case SERIAL_SETPROTO: 1303 /* Only for superuser! */ |
1303 error = suser (td); | 1304 error = priv_check (td, PRIV_DRIVER); |
1304 if (error) 1305 return error; 1306 if (d->ifp->if_drv_flags & IFF_DRV_RUNNING) 1307 return EBUSY; 1308 if (! strcmp ("cisco", (char*)data)) { 1309 IFP2SP(d->ifp)->pp_flags &= ~(PP_FR); 1310 IFP2SP(d->ifp)->pp_flags |= PP_KEEPALIVE; 1311 d->ifp->if_flags |= PP_CISCO; --- 11 unchanged lines hidden (view full) --- 1323 if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || 1324 (d->ifp->if_flags & PP_CISCO)) 1325 return EINVAL; 1326 *(int*)data = (IFP2SP(d->ifp)->pp_flags & PP_KEEPALIVE) ? 1 : 0; 1327 return 0; 1328 1329 case SERIAL_SETKEEPALIVE: 1330 /* Only for superuser! */ | 1305 if (error) 1306 return error; 1307 if (d->ifp->if_drv_flags & IFF_DRV_RUNNING) 1308 return EBUSY; 1309 if (! strcmp ("cisco", (char*)data)) { 1310 IFP2SP(d->ifp)->pp_flags &= ~(PP_FR); 1311 IFP2SP(d->ifp)->pp_flags |= PP_KEEPALIVE; 1312 d->ifp->if_flags |= PP_CISCO; --- 11 unchanged lines hidden (view full) --- 1324 if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || 1325 (d->ifp->if_flags & PP_CISCO)) 1326 return EINVAL; 1327 *(int*)data = (IFP2SP(d->ifp)->pp_flags & PP_KEEPALIVE) ? 1 : 0; 1328 return 0; 1329 1330 case SERIAL_SETKEEPALIVE: 1331 /* Only for superuser! */ |
1331 error = suser (td); | 1332 error = priv_check (td, PRIV_DRIVER); |
1332 if (error) 1333 return error; 1334 if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || 1335 (d->ifp->if_flags & PP_CISCO)) 1336 return EINVAL; 1337 if (*(int*)data) 1338 IFP2SP(d->ifp)->pp_flags |= PP_KEEPALIVE; 1339 else --- 12 unchanged lines hidden (view full) --- 1352 default: *(char*)data = 'a'; break; 1353 case CFG_B: *(char*)data = 'b'; break; 1354 case CFG_C: *(char*)data = 'c'; break; 1355 } 1356 return 0; 1357 1358 case SERIAL_SETCFG: 1359 /* Only for superuser! */ | 1333 if (error) 1334 return error; 1335 if ((IFP2SP(d->ifp)->pp_flags & PP_FR) || 1336 (d->ifp->if_flags & PP_CISCO)) 1337 return EINVAL; 1338 if (*(int*)data) 1339 IFP2SP(d->ifp)->pp_flags |= PP_KEEPALIVE; 1340 else --- 12 unchanged lines hidden (view full) --- 1353 default: *(char*)data = 'a'; break; 1354 case CFG_B: *(char*)data = 'b'; break; 1355 case CFG_C: *(char*)data = 'c'; break; 1356 } 1357 return 0; 1358 1359 case SERIAL_SETCFG: 1360 /* Only for superuser! */ |
1360 error = suser (td); | 1361 error = priv_check (td, PRIV_DRIVER); |
1361 if (error) 1362 return error; 1363 if (c->mode == M_HDLC) 1364 return EINVAL; 1365 s = splimp (); 1366 CT_LOCK (bd); 1367 switch (*(char*)data) { 1368 case 'a': ct_set_config (c->board, CFG_A); break; --- 61 unchanged lines hidden (view full) --- 1430 opte1->interval[s].oofs = c->interval[s].oofs; 1431 opte1->interval[s].css = c->interval[s].css; 1432 opte1->interval[s].dm = c->interval[s].dm; 1433 } 1434 return 0; 1435 1436 case SERIAL_CLRSTAT: 1437 /* Only for superuser! */ | 1362 if (error) 1363 return error; 1364 if (c->mode == M_HDLC) 1365 return EINVAL; 1366 s = splimp (); 1367 CT_LOCK (bd); 1368 switch (*(char*)data) { 1369 case 'a': ct_set_config (c->board, CFG_A); break; --- 61 unchanged lines hidden (view full) --- 1431 opte1->interval[s].oofs = c->interval[s].oofs; 1432 opte1->interval[s].css = c->interval[s].css; 1433 opte1->interval[s].dm = c->interval[s].dm; 1434 } 1435 return 0; 1436 1437 case SERIAL_CLRSTAT: 1438 /* Only for superuser! */ |
1438 error = suser (td); | 1439 error = priv_check (td, PRIV_DRIVER); |
1439 if (error) 1440 return error; 1441 c->rintr = 0; 1442 c->tintr = 0; 1443 c->mintr = 0; 1444 c->ibytes = 0; 1445 c->ipkts = 0; 1446 c->ierrs = 0; --- 6 unchanged lines hidden (view full) --- 1453 return 0; 1454 1455 case SERIAL_GETBAUD: 1456 *(long*)data = ct_get_baud(c); 1457 return 0; 1458 1459 case SERIAL_SETBAUD: 1460 /* Only for superuser! */ | 1440 if (error) 1441 return error; 1442 c->rintr = 0; 1443 c->tintr = 0; 1444 c->mintr = 0; 1445 c->ibytes = 0; 1446 c->ipkts = 0; 1447 c->ierrs = 0; --- 6 unchanged lines hidden (view full) --- 1454 return 0; 1455 1456 case SERIAL_GETBAUD: 1457 *(long*)data = ct_get_baud(c); 1458 return 0; 1459 1460 case SERIAL_SETBAUD: 1461 /* Only for superuser! */ |
1461 error = suser (td); | 1462 error = priv_check (td, PRIV_DRIVER); |
1462 if (error) 1463 return error; 1464 s = splimp (); 1465 CT_LOCK (bd); 1466 ct_set_baud (c, *(long*)data); 1467 CT_UNLOCK (bd); 1468 splx (s); 1469 return 0; 1470 1471 case SERIAL_GETLOOP: 1472 *(int*)data = ct_get_loop (c); 1473 return 0; 1474 1475 case SERIAL_SETLOOP: 1476 /* Only for superuser! */ | 1463 if (error) 1464 return error; 1465 s = splimp (); 1466 CT_LOCK (bd); 1467 ct_set_baud (c, *(long*)data); 1468 CT_UNLOCK (bd); 1469 splx (s); 1470 return 0; 1471 1472 case SERIAL_GETLOOP: 1473 *(int*)data = ct_get_loop (c); 1474 return 0; 1475 1476 case SERIAL_SETLOOP: 1477 /* Only for superuser! */ |
1477 error = suser (td); | 1478 error = priv_check (td, PRIV_DRIVER); |
1478 if (error) 1479 return error; 1480 s = splimp (); 1481 CT_LOCK (bd); 1482 ct_set_loop (c, *(int*)data); 1483 CT_UNLOCK (bd); 1484 splx (s); 1485 return 0; 1486 1487 case SERIAL_GETDPLL: 1488 if (c->mode == M_E1 || c->mode == M_G703) 1489 return EINVAL; 1490 *(int*)data = ct_get_dpll (c); 1491 return 0; 1492 1493 case SERIAL_SETDPLL: 1494 /* Only for superuser! */ | 1479 if (error) 1480 return error; 1481 s = splimp (); 1482 CT_LOCK (bd); 1483 ct_set_loop (c, *(int*)data); 1484 CT_UNLOCK (bd); 1485 splx (s); 1486 return 0; 1487 1488 case SERIAL_GETDPLL: 1489 if (c->mode == M_E1 || c->mode == M_G703) 1490 return EINVAL; 1491 *(int*)data = ct_get_dpll (c); 1492 return 0; 1493 1494 case SERIAL_SETDPLL: 1495 /* Only for superuser! */ |
1495 error = suser (td); | 1496 error = priv_check (td, PRIV_DRIVER); |
1496 if (error) 1497 return error; 1498 if (c->mode == M_E1 || c->mode == M_G703) 1499 return EINVAL; 1500 s = splimp (); 1501 CT_LOCK (bd); 1502 ct_set_dpll (c, *(int*)data); 1503 CT_UNLOCK (bd); 1504 splx (s); 1505 return 0; 1506 1507 case SERIAL_GETNRZI: 1508 if (c->mode == M_E1 || c->mode == M_G703) 1509 return EINVAL; 1510 *(int*)data = ct_get_nrzi (c); 1511 return 0; 1512 1513 case SERIAL_SETNRZI: 1514 /* Only for superuser! */ | 1497 if (error) 1498 return error; 1499 if (c->mode == M_E1 || c->mode == M_G703) 1500 return EINVAL; 1501 s = splimp (); 1502 CT_LOCK (bd); 1503 ct_set_dpll (c, *(int*)data); 1504 CT_UNLOCK (bd); 1505 splx (s); 1506 return 0; 1507 1508 case SERIAL_GETNRZI: 1509 if (c->mode == M_E1 || c->mode == M_G703) 1510 return EINVAL; 1511 *(int*)data = ct_get_nrzi (c); 1512 return 0; 1513 1514 case SERIAL_SETNRZI: 1515 /* Only for superuser! */ |
1515 error = suser (td); | 1516 error = priv_check (td, PRIV_DRIVER); |
1516 if (error) 1517 return error; 1518 if (c->mode == M_E1 || c->mode == M_G703) 1519 return EINVAL; 1520 s = splimp (); 1521 CT_LOCK (bd); 1522 ct_set_nrzi (c, *(int*)data); 1523 CT_UNLOCK (bd); 1524 splx (s); 1525 return 0; 1526 1527 case SERIAL_GETDEBUG: 1528 *(int*)data = c->debug; 1529 return 0; 1530 1531 case SERIAL_SETDEBUG: 1532 /* Only for superuser! */ | 1517 if (error) 1518 return error; 1519 if (c->mode == M_E1 || c->mode == M_G703) 1520 return EINVAL; 1521 s = splimp (); 1522 CT_LOCK (bd); 1523 ct_set_nrzi (c, *(int*)data); 1524 CT_UNLOCK (bd); 1525 splx (s); 1526 return 0; 1527 1528 case SERIAL_GETDEBUG: 1529 *(int*)data = c->debug; 1530 return 0; 1531 1532 case SERIAL_SETDEBUG: 1533 /* Only for superuser! */ |
1533 error = suser (td); | 1534 error = priv_check (td, PRIV_DRIVER); |
1534 if (error) 1535 return error; 1536 c->debug = *(int*)data; 1537#ifndef NETGRAPH 1538 if (d->chan->debug) 1539 d->ifp->if_flags |= IFF_DEBUG; 1540 else 1541 d->ifp->if_flags &= (~IFF_DEBUG); 1542#endif 1543 return 0; 1544 1545 case SERIAL_GETHIGAIN: 1546 if (c->mode != M_E1) 1547 return EINVAL; 1548 *(int*)data = ct_get_higain (c); 1549 return 0; 1550 1551 case SERIAL_SETHIGAIN: 1552 /* Only for superuser! */ | 1535 if (error) 1536 return error; 1537 c->debug = *(int*)data; 1538#ifndef NETGRAPH 1539 if (d->chan->debug) 1540 d->ifp->if_flags |= IFF_DEBUG; 1541 else 1542 d->ifp->if_flags &= (~IFF_DEBUG); 1543#endif 1544 return 0; 1545 1546 case SERIAL_GETHIGAIN: 1547 if (c->mode != M_E1) 1548 return EINVAL; 1549 *(int*)data = ct_get_higain (c); 1550 return 0; 1551 1552 case SERIAL_SETHIGAIN: 1553 /* Only for superuser! */ |
1553 error = suser (td); | 1554 error = priv_check (td, PRIV_DRIVER); |
1554 if (error) 1555 return error; 1556 s = splimp (); 1557 CT_LOCK (bd); 1558 ct_set_higain (c, *(int*)data); 1559 CT_UNLOCK (bd); 1560 splx (s); 1561 return 0; --- 5 unchanged lines hidden (view full) --- 1567 *(int*)data = c->gopt.phony; 1568 return 0; 1569 1570 case SERIAL_SETPHONY: 1571 CT_DEBUG2 (d, ("ioctl: setphony\n")); 1572 if (c->mode != M_E1) 1573 return EINVAL; 1574 /* Only for superuser! */ | 1555 if (error) 1556 return error; 1557 s = splimp (); 1558 CT_LOCK (bd); 1559 ct_set_higain (c, *(int*)data); 1560 CT_UNLOCK (bd); 1561 splx (s); 1562 return 0; --- 5 unchanged lines hidden (view full) --- 1568 *(int*)data = c->gopt.phony; 1569 return 0; 1570 1571 case SERIAL_SETPHONY: 1572 CT_DEBUG2 (d, ("ioctl: setphony\n")); 1573 if (c->mode != M_E1) 1574 return EINVAL; 1575 /* Only for superuser! */ |
1575 error = suser (td); | 1576 error = priv_check (td, PRIV_DRIVER); |
1576 if (error) 1577 return error; 1578 s = splimp (); 1579 CT_LOCK (bd); 1580 ct_set_phony (c, *(int*)data); 1581 CT_UNLOCK (bd); 1582 splx (s); 1583 return 0; --- 6 unchanged lines hidden (view full) --- 1590 case GCLK_RCV: *(int*)data = E1CLK_RECEIVE; break; 1591 case GCLK_RCLKO: *(int*)data = c->num ? 1592 E1CLK_RECEIVE_CHAN0 : E1CLK_RECEIVE_CHAN1; break; 1593 } 1594 return 0; 1595 1596 case SERIAL_SETCLK: 1597 /* Only for superuser! */ | 1577 if (error) 1578 return error; 1579 s = splimp (); 1580 CT_LOCK (bd); 1581 ct_set_phony (c, *(int*)data); 1582 CT_UNLOCK (bd); 1583 splx (s); 1584 return 0; --- 6 unchanged lines hidden (view full) --- 1591 case GCLK_RCV: *(int*)data = E1CLK_RECEIVE; break; 1592 case GCLK_RCLKO: *(int*)data = c->num ? 1593 E1CLK_RECEIVE_CHAN0 : E1CLK_RECEIVE_CHAN1; break; 1594 } 1595 return 0; 1596 1597 case SERIAL_SETCLK: 1598 /* Only for superuser! */ |
1598 error = suser (td); | 1599 error = priv_check (td, PRIV_DRIVER); |
1599 if (error) 1600 return error; 1601 s = splimp (); 1602 CT_LOCK (bd); 1603 switch (*(int*)data) { 1604 default: ct_set_clk (c, GCLK_INT); break; 1605 case E1CLK_RECEIVE: ct_set_clk (c, GCLK_RCV); break; 1606 case E1CLK_RECEIVE_CHAN0: --- 7 unchanged lines hidden (view full) --- 1614 case SERIAL_GETTIMESLOTS: 1615 if (c->mode != M_E1) 1616 return EINVAL; 1617 *(long*)data = ct_get_ts (c); 1618 return 0; 1619 1620 case SERIAL_SETTIMESLOTS: 1621 /* Only for superuser! */ | 1600 if (error) 1601 return error; 1602 s = splimp (); 1603 CT_LOCK (bd); 1604 switch (*(int*)data) { 1605 default: ct_set_clk (c, GCLK_INT); break; 1606 case E1CLK_RECEIVE: ct_set_clk (c, GCLK_RCV); break; 1607 case E1CLK_RECEIVE_CHAN0: --- 7 unchanged lines hidden (view full) --- 1615 case SERIAL_GETTIMESLOTS: 1616 if (c->mode != M_E1) 1617 return EINVAL; 1618 *(long*)data = ct_get_ts (c); 1619 return 0; 1620 1621 case SERIAL_SETTIMESLOTS: 1622 /* Only for superuser! */ |
1622 error = suser (td); | 1623 error = priv_check (td, PRIV_DRIVER); |
1623 if (error) 1624 return error; 1625 s = splimp (); 1626 CT_LOCK (bd); 1627 ct_set_ts (c, *(long*)data); 1628 CT_UNLOCK (bd); 1629 splx (s); 1630 return 0; 1631 1632 case SERIAL_GETSUBCHAN: 1633 if (c->mode != M_E1) 1634 return EINVAL; 1635 *(long*)data = ct_get_subchan (c->board); 1636 return 0; 1637 1638 case SERIAL_SETSUBCHAN: 1639 /* Only for superuser! */ | 1624 if (error) 1625 return error; 1626 s = splimp (); 1627 CT_LOCK (bd); 1628 ct_set_ts (c, *(long*)data); 1629 CT_UNLOCK (bd); 1630 splx (s); 1631 return 0; 1632 1633 case SERIAL_GETSUBCHAN: 1634 if (c->mode != M_E1) 1635 return EINVAL; 1636 *(long*)data = ct_get_subchan (c->board); 1637 return 0; 1638 1639 case SERIAL_SETSUBCHAN: 1640 /* Only for superuser! */ |
1640 error = suser (td); | 1641 error = priv_check (td, PRIV_DRIVER); |
1641 if (error) 1642 return error; 1643 s = splimp (); 1644 CT_LOCK (bd); 1645 ct_set_subchan (c->board, *(long*)data); 1646 CT_UNLOCK (bd); 1647 splx (s); 1648 return 0; --- 9 unchanged lines hidden (view full) --- 1658 if (c->mode == M_E1 || c->mode == M_G703) 1659 return EINVAL; 1660 *(int*)data = ct_get_invrxc (c); 1661 return 0; 1662 1663 case SERIAL_SETINVCLK: 1664 case SERIAL_SETINVTCLK: 1665 /* Only for superuser! */ | 1642 if (error) 1643 return error; 1644 s = splimp (); 1645 CT_LOCK (bd); 1646 ct_set_subchan (c->board, *(long*)data); 1647 CT_UNLOCK (bd); 1648 splx (s); 1649 return 0; --- 9 unchanged lines hidden (view full) --- 1659 if (c->mode == M_E1 || c->mode == M_G703) 1660 return EINVAL; 1661 *(int*)data = ct_get_invrxc (c); 1662 return 0; 1663 1664 case SERIAL_SETINVCLK: 1665 case SERIAL_SETINVTCLK: 1666 /* Only for superuser! */ |
1666 error = suser (td); | 1667 error = priv_check (td, PRIV_DRIVER); |
1667 if (error) 1668 return error; 1669 if (c->mode == M_E1 || c->mode == M_G703) 1670 return EINVAL; 1671 s = splimp (); 1672 CT_LOCK (bd); 1673 ct_set_invtxc (c, *(int*)data); 1674 CT_UNLOCK (bd); 1675 splx (s); 1676 return 0; 1677 1678 case SERIAL_SETINVRCLK: 1679 /* Only for superuser! */ | 1668 if (error) 1669 return error; 1670 if (c->mode == M_E1 || c->mode == M_G703) 1671 return EINVAL; 1672 s = splimp (); 1673 CT_LOCK (bd); 1674 ct_set_invtxc (c, *(int*)data); 1675 CT_UNLOCK (bd); 1676 splx (s); 1677 return 0; 1678 1679 case SERIAL_SETINVRCLK: 1680 /* Only for superuser! */ |
1680 error = suser (td); | 1681 error = priv_check (td, PRIV_DRIVER); |
1681 if (error) 1682 return error; 1683 if (c->mode == M_E1 || c->mode == M_G703) 1684 return EINVAL; 1685 s = splimp (); 1686 CT_LOCK (bd); 1687 ct_set_invrxc (c, *(int*)data); 1688 CT_UNLOCK (bd); --- 581 unchanged lines hidden --- | 1682 if (error) 1683 return error; 1684 if (c->mode == M_E1 || c->mode == M_G703) 1685 return EINVAL; 1686 s = splimp (); 1687 CT_LOCK (bd); 1688 ct_set_invrxc (c, *(int*)data); 1689 CT_UNLOCK (bd); --- 581 unchanged lines hidden --- |