12 #include <linux/sched.h>
14 #include <linux/slab.h>
15 #include <asm/unaligned.h>
32 if (self->ppp_open && !self->ttp_open && !self->ttp_connect) {
61 DENTER(CTRL_TRACE,
"(ap=0x%p, event=%d, daddr=%08x, name=``%s'')\n",
62 ap, event, daddr, name);
101 DEXIT(CTRL_TRACE,
"\n");
128 DENTER(IRDA_SR_TRACE,
"(self=0x%p)\n",
self);
148 IRDA_SR_ERROR,
"Unable to allocate TSAP !\n");
151 self->stsap_sel =
self->tsap->stsap_sel;
153 DEXIT(IRDA_SR_TRACE,
" - tsap=0x%p, sel=0x%X\n",
154 self->tsap, self->stsap_sel);
179 DENTER(IRDA_SR_TRACE,
"(self=0x%p)\n",
self);
190 DEBUG(IRDA_SR_INFO,
"IAS object doesn't exist ! (%d)\n", result);
196 DEBUG(IRDA_SR_INFO,
"IAS query failed ! (%d)\n", result);
221 DERROR(IRDA_SR_ERROR,
"bad type ! (0x%X)\n", value->
type);
234 "IrDA bug : result == SUCCESS && value == NULL\n");
238 DEXIT(IRDA_SR_TRACE,
"\n");
259 DENTER(IRDA_SR_TRACE,
"(self=0x%p)\n",
self);
262 DABORT(self->iriap, -
EBUSY, IRDA_SR_ERROR,
"busy with a previous query.\n");
266 irnet_getvalue_confirm);
280 DEXIT(IRDA_SR_TRACE,
"\n");
296 DENTER(IRDA_SR_TRACE,
"(self=0x%p)\n",
self);
299 err = irnet_open_tsap(
self);
303 DERROR(IRDA_SR_ERROR,
"connect aborted!\n");
309 self->rsaddr, self->daddr,
NULL,
310 self->max_sdu_size_rx,
NULL);
314 DERROR(IRDA_SR_ERROR,
"connect aborted!\n");
323 DEXIT(IRDA_SR_TRACE,
"\n");
347 irnet_discovervalue_confirm);
348 if(self->iriap ==
NULL)
355 if(self->disco_index < self->disco_number)
359 self->discoveries[self->disco_index].saddr,
360 self->discoveries[self->disco_index].daddr,
399 DENTER(IRDA_SR_TRACE,
"(self=0x%p)\n",
self);
406 if(self->discoveries ==
NULL)
408 self->disco_number = -1;
412 DEBUG(IRDA_SR_INFO,
"Got the log (0x%p), size is %d\n",
413 self->discoveries, self->disco_number);
416 self->disco_index = -1;
420 ret = irnet_discover_next_daddr(
self);
429 kfree(self->discoveries);
430 self->discoveries =
NULL;
438 DEXIT(IRDA_SR_TRACE,
"\n");
457 DENTER(IRDA_SR_TRACE,
"(self=0x%p)\n",
self);
463 if(discoveries ==
NULL)
471 for(i = 0; i < number; i++)
477 self->daddr = discoveries[
i].
daddr;
478 DEBUG(IRDA_SR_INFO,
"discovered device ``%s'' at address 0x%08x.\n",
479 self->rname, self->daddr);
481 DEXIT(IRDA_SR_TRACE,
"\n");
486 DEBUG(IRDA_SR_INFO,
"cannot discover device ``%s'' !!!\n", self->rname);
505 DENTER(IRDA_SOCK_TRACE,
"(self=0x%p)\n",
self);
510 self->ttp_connect = 0;
511 self->rname[0] =
'\0';
520 #ifdef DISCOVERY_NOMASK
527 INIT_WORK(&self->disconnect_work, irnet_ppp_disconnect);
529 DEXIT(IRDA_SOCK_TRACE,
"\n");
551 DENTER(IRDA_SOCK_TRACE,
"(self=0x%p)\n",
self);
558 DRETURN(-
EBUSY, IRDA_SOCK_INFO,
"Already connecting...\n");
559 if((self->iriap !=
NULL) || (self->tsap !=
NULL))
560 DERROR(IRDA_SOCK_ERROR,
"Socket not cleaned up...\n");
566 if((irnet_server.running) && (self->q.q_next ==
NULL))
568 spin_lock_bh(&irnet_server.spinlock);
570 spin_unlock_bh(&irnet_server.spinlock);
571 DEBUG(IRDA_SOCK_INFO,
"Inserted ``%s'' in hashbin...\n", self->rname);
575 if((self->rdaddr ==
DEV_ADDR_ANY) && (self->rname[0] ==
'\0'))
578 if((err = irnet_discover_daddr_and_lsap_sel(
self)) != 0)
579 DRETURN(err, IRDA_SOCK_INFO,
"auto-connect failed!\n");
587 if((err = irnet_dname_to_daddr(
self)) != 0)
588 DRETURN(err, IRDA_SOCK_INFO,
"name connect failed!\n");
592 self->daddr =
self->rdaddr;
595 irnet_find_lsap_sel(
self);
603 DEXIT(IRDA_SOCK_TRACE,
"\n");
618 DENTER(IRDA_SOCK_TRACE,
"(self=0x%p)\n",
self);
624 if((irnet_server.running) && (self->q.q_next !=
NULL))
627 DEBUG(IRDA_SOCK_INFO,
"Removing from hash..\n");
628 spin_lock_bh(&irnet_server.spinlock);
630 self->q.q_next =
NULL;
631 spin_unlock_bh(&irnet_server.spinlock);
632 DASSERT(entry ==
self, , IRDA_SOCK_ERROR,
"Can't remove from hash.\n");
642 self->saddr, self->daddr, self->rname, 0);
663 if(self->discoveries !=
NULL)
666 kfree(self->discoveries);
667 self->discoveries =
NULL;
673 DEBUG(IRDA_SOCK_INFO,
"Closing our TTP connection.\n");
680 DEXIT(IRDA_SOCK_TRACE,
"\n");
708 DENTER(IRDA_SERV_TRACE,
"(self=0x%p)\n",
self);
714 if (discoveries ==
NULL)
718 for(i = 0; i < number; i++)
721 if(discoveries[i].daddr == self->
daddr)
724 strlcpy(self->rname, discoveries[i].
info,
sizeof(self->rname));
725 self->rname[
sizeof(
self->rname) - 1] =
'\0';
726 DEBUG(IRDA_SERV_INFO,
"Device 0x%08x is in fact ``%s''.\n",
727 self->daddr, self->rname);
729 DEXIT(IRDA_SERV_TRACE,
"\n");
734 DEXIT(IRDA_SERV_INFO,
": cannot discover device 0x%08x !!!\n", self->daddr);
754 DENTER(IRDA_SERV_TRACE,
"(self=0x%p)\n",
self);
757 self->daddr = irttp_get_daddr(self->tsap);
758 self->saddr = irttp_get_saddr(self->tsap);
761 err = irnet_daddr_to_dname(
self);
764 spin_lock_bh(&irnet_server.spinlock);
773 DEBUG(IRDA_SERV_INFO,
"Socket 0x%p matches rname ``%s''.\n",
787 if((new->rdaddr == self->daddr) || (
new->daddr ==
self->daddr))
790 DEBUG(IRDA_SERV_INFO,
"Socket 0x%p matches daddr %#08x.\n",
806 (
new->rname[0] ==
'\0') && (new->ppp_open))
809 DEBUG(IRDA_SERV_INFO,
"Socket 0x%p is free.\n",
818 spin_unlock_bh(&irnet_server.spinlock);
820 DEXIT(IRDA_SERV_TRACE,
" - new = 0x%p\n",
new);
836 __u8 max_header_size)
838 DENTER(IRDA_SERV_TRACE,
"(server=0x%p, new=0x%p)\n",
843 DABORT(new->tsap ==
NULL, -1, IRDA_SERV_ERROR,
"dup failed!\n");
846 new->stsap_sel =
new->tsap->stsap_sel;
847 new->dtsap_sel =
new->tsap->dtsap_sel;
848 new->saddr = irttp_get_saddr(new->tsap);
849 new->daddr = irttp_get_daddr(new->tsap);
851 new->max_header_size = max_header_size;
852 new->max_sdu_size_tx = max_sdu_size;
853 new->max_data_size = max_sdu_size;
856 if(max_sdu_size == 0)
857 new->max_data_size = irttp_get_max_seg_size(new->tsap);
861 irttp_listen(server->
tsap);
877 if(new->discoveries !=
NULL)
879 kfree(new->discoveries);
880 new->discoveries =
NULL;
883 #ifdef CONNECT_INDIC_KICK
893 new->saddr, new->daddr, server->
rname, 0);
895 DEXIT(IRDA_SERV_TRACE,
"\n");
910 DENTER(IRDA_SERV_TRACE,
"(self=0x%p)\n",
self);
915 #ifdef FAIL_SEND_DISCONNECT
924 self->saddr, self->daddr, self->rname, 0);
927 irttp_listen(self->tsap);
929 DEXIT(IRDA_SERV_TRACE,
"\n");
942 irnet_setup_server(
void)
946 DENTER(IRDA_SERV_TRACE,
"()\n");
952 irnet_open_tsap(&irnet_server.s);
955 irnet_server.s.ppp_open = 0;
956 irnet_server.s.chan.private =
NULL;
957 irnet_server.s.file =
NULL;
966 #ifdef ADVERTISE_HINT
977 #ifdef DISCOVERY_EVENTS
980 irnet_discovery_indication, irnet_expiry_indication,
981 (
void *) &irnet_server.s);
984 DEXIT(IRDA_SERV_TRACE,
" - self=0x%p\n", &irnet_server.s);
997 irnet_destroy_server(
void)
999 DENTER(IRDA_SERV_TRACE,
"()\n");
1001 #ifdef ADVERTISE_HINT
1007 if(irnet_server.ias_obj)
1013 DEXIT(IRDA_SERV_TRACE,
"\n");
1032 irnet_data_indication(
void * instance,
1040 DENTER(IRDA_TCB_TRACE,
"(self/ap=0x%p, skb=0x%p)\n",
1042 DASSERT(skb !=
NULL, 0, IRDA_CB_ERROR,
"skb is NULL !!!\n");
1047 DERROR(IRDA_CB_ERROR,
"PPP not ready, dropping packet...\n");
1079 DEXIT(IRDA_TCB_TRACE,
"\n");
1083 DERROR(IRDA_CB_ERROR,
"Packet too small, dropping...\n");
1102 irnet_disconnect_indication(
void * instance,
1111 DENTER(IRDA_TCB_TRACE,
"(self=0x%p)\n",
self);
1112 DASSERT(
self !=
NULL, , IRDA_CB_ERROR,
"Self is NULL !!!\n");
1128 if(!(test_open || test_connect))
1130 DERROR(IRDA_CB_ERROR,
"Race condition detected...\n");
1137 self->saddr, self->daddr, self->rname, 0);
1140 if((self->tsap) && (
self != &irnet_server.s))
1142 self->saddr, self->daddr, self->rname, 0);
1145 if((self->tsap) && (
self != &irnet_server.s))
1147 DEBUG(IRDA_CB_INFO,
"Closing our TTP connection.\n");
1152 self->stsap_sel = 0;
1174 DEXIT(IRDA_TCB_TRACE,
"\n");
1185 irnet_connect_confirm(
void * instance,
1189 __u8 max_header_size,
1194 DENTER(IRDA_TCB_TRACE,
"(self=0x%p)\n",
self);
1197 if(!
test_bit(0, &self->ttp_connect))
1199 DERROR(IRDA_CB_ERROR,
"Socket no longer connecting. Ouch !\n");
1204 self->max_header_size = max_header_size;
1207 self->max_sdu_size_tx = max_sdu_size;
1208 self->max_data_size = max_sdu_size;
1209 #ifdef STREAM_COMPAT
1210 if(max_sdu_size == 0)
1211 self->max_data_size = irttp_get_max_seg_size(self->tsap);
1215 self->saddr = irttp_get_saddr(self->tsap);
1226 #ifdef PASS_CONNECT_PACKETS
1227 DEBUG(IRDA_CB_INFO,
"Passing connect packet to PPP.\n");
1229 irnet_data_indication(instance, sap, skb);
1231 DERROR(IRDA_CB_ERROR,
"Dropping non empty packet.\n");
1240 self->saddr, self->daddr, self->rname, 0);
1242 DEXIT(IRDA_TCB_TRACE,
"\n");
1253 irnet_flow_indication(
void * instance,
1260 DENTER(IRDA_TCB_TRACE,
"(self=0x%p, flow=%d)\n",
self, flow);
1263 self->tx_flow = flow;
1269 DEBUG(IRDA_CB_INFO,
"IrTTP wants us to start again\n");
1274 DEBUG(IRDA_CB_INFO,
"But we were already transmitting !!!\n");
1277 DEBUG(IRDA_CB_INFO,
"IrTTP wants us to slow down\n");
1280 DEBUG(IRDA_CB_INFO,
"Unknown flow command!\n");
1284 DEXIT(IRDA_TCB_TRACE,
"\n");
1295 irnet_status_indication(
void * instance,
1301 DENTER(IRDA_TCB_TRACE,
"(self=0x%p)\n",
self);
1302 DASSERT(
self !=
NULL, , IRDA_CB_ERROR,
"Self is NULL !!!\n");
1309 self->saddr, self->daddr, self->rname, 0);
1312 DEBUG(IRDA_CB_INFO,
"Unknown status...\n");
1315 DEXIT(IRDA_TCB_TRACE,
"\n");
1333 irnet_connect_indication(
void * instance,
1337 __u8 max_header_size,
1343 DENTER(IRDA_TCB_TRACE,
"(server=0x%p)\n", server);
1344 DASSERT(instance == &irnet_server, , IRDA_CB_ERROR,
1345 "Invalid instance (0x%p) !!!\n", instance);
1346 DASSERT(sap == irnet_server.s.tsap, , IRDA_CB_ERROR,
"Invalid sap !!!\n");
1349 new = irnet_find_socket(server);
1354 DEXIT(IRDA_CB_INFO,
": No socket waiting for this connection.\n");
1355 irnet_disconnect_server(server, skb);
1362 DEXIT(IRDA_CB_INFO,
": Socket already connected.\n");
1363 irnet_disconnect_server(server, skb);
1404 || ((irttp_is_primary(server->
tsap) == 1) &&
1409 DERROR(IRDA_CB_ERROR,
"Socket already connecting, but going to reuse it !\n");
1412 if(new->tsap !=
NULL)
1433 if((
test_bit(0, &new->ttp_connect)) || (new->tsap !=
NULL))
1436 DERROR(IRDA_CB_ERROR,
"Race condition detected, socket in use, abort connect...\n");
1437 irnet_disconnect_server(server, skb);
1443 irnet_connect_socket(server,
new, qos, max_sdu_size, max_header_size);
1448 #ifdef PASS_CONNECT_PACKETS
1449 DEBUG(IRDA_CB_INFO,
"Passing connect packet to PPP.\n");
1451 irnet_data_indication(
new, new->tsap, skb);
1453 DERROR(IRDA_CB_ERROR,
"Dropping non empty packet.\n");
1460 DEXIT(IRDA_TCB_TRACE,
"\n");
1482 irnet_getvalue_confirm(
int result,
1489 DENTER(IRDA_OCB_TRACE,
"(self=0x%p)\n",
self);
1490 DASSERT(
self !=
NULL, , IRDA_OCB_ERROR,
"Self is NULL !!!\n");
1494 if(!
test_bit(0, &self->ttp_connect))
1496 DERROR(IRDA_OCB_ERROR,
"Socket no longer connecting. Ouch !\n");
1505 self->dtsap_sel = irnet_ias_to_tsap(
self, result, value);
1511 DERROR(IRDA_OCB_ERROR,
"IAS connect failed ! (0x%X)\n", self->errno);
1515 DEBUG(IRDA_OCB_INFO,
"daddr = %08x, lsap = %d, starting IrTTP connection\n",
1516 self->daddr, self->dtsap_sel);
1519 irnet_connect_tsap(
self);
1521 DEXIT(IRDA_OCB_TRACE,
"\n");
1545 irnet_discovervalue_confirm(
int result,
1553 DENTER(IRDA_OCB_TRACE,
"(self=0x%p)\n",
self);
1554 DASSERT(
self !=
NULL, , IRDA_OCB_ERROR,
"Self is NULL !!!\n");
1558 if(!
test_bit(0, &self->ttp_connect))
1560 DERROR(IRDA_OCB_ERROR,
"Socket no longer connecting. Ouch !\n");
1565 dtsap_sel = irnet_ias_to_tsap(
self, result, value);
1568 if(self->errno == 0)
1573 DERROR(IRDA_OCB_ERROR,
"More than one device in range supports IrNET...\n");
1578 self->daddr =
self->discoveries[
self->disco_index].daddr;
1579 self->dtsap_sel = dtsap_sel;
1589 ret = irnet_discover_next_daddr(
self);
1606 DEBUG(IRDA_OCB_INFO,
"Cleaning up log (0x%p)\n",
1608 if(self->discoveries !=
NULL)
1611 kfree(self->discoveries);
1612 self->discoveries =
NULL;
1614 self->disco_number = -1;
1621 DEXIT(IRDA_OCB_TRACE,
": cannot discover IrNET in any device !!!\n");
1627 DEBUG(IRDA_OCB_INFO,
"daddr = %08x, lsap = %d, starting IrTTP connection\n",
1628 self->daddr, self->dtsap_sel);
1631 irnet_connect_tsap(
self);
1633 DEXIT(IRDA_OCB_TRACE,
"\n");
1636 #ifdef DISCOVERY_EVENTS
1660 irnet_discovery_indication(
discinfo_t * discovery,
1666 DENTER(IRDA_OCB_TRACE,
"(self=0x%p)\n",
self);
1667 DASSERT(priv == &irnet_server, , IRDA_OCB_ERROR,
1668 "Invalid instance (0x%p) !!!\n", priv);
1670 DEBUG(IRDA_OCB_INFO,
"Discovered new IrNET/IrLAN node %s...\n",
1678 DEXIT(IRDA_OCB_TRACE,
"\n");
1697 DENTER(IRDA_OCB_TRACE,
"(self=0x%p)\n",
self);
1698 DASSERT(priv == &irnet_server, , IRDA_OCB_ERROR,
1699 "Invalid instance (0x%p) !!!\n", priv);
1701 DEBUG(IRDA_OCB_INFO,
"IrNET/IrLAN node %s expired...\n",
1709 DEXIT(IRDA_OCB_TRACE,
"\n");
1720 #ifdef CONFIG_PROC_FS
1731 (irnet_server.running ?
"running" :
"dead"));
1732 seq_printf(m,
"stsap_sel: %02x, ", irnet_server.s.stsap_sel);
1733 seq_printf(m,
"dtsap_sel: %02x\n", irnet_server.s.dtsap_sel);
1736 if(!irnet_server.running)
1740 spin_lock_bh(&irnet_server.spinlock);
1750 seq_printf(m,
"Requested IrDA name: \"%s\", ", self->rname);
1751 seq_printf(m,
"daddr: %08x, ", self->rdaddr);
1752 seq_printf(m,
"saddr: %08x\n", self->rsaddr);
1756 (self->ppp_open ?
"registered" :
"unregistered"));
1770 state =
"connected";
1772 if(self->tsap !=
NULL)
1773 state =
"connecting";
1775 if(self->iriap !=
NULL)
1776 state =
"searching";
1778 if(self->ttp_connect)
1784 seq_printf(m,
"stsap_sel: %02x, ", self->stsap_sel);
1785 seq_printf(m,
"dtsap_sel: %02x\n", self->dtsap_sel);
1792 spin_unlock_bh(&irnet_server.spinlock);
1804 .open = irnet_proc_open,
1827 DENTER(MODULE_TRACE,
"()\n");
1835 MODULE_ERROR,
"Can't allocate hashbin!\n");
1845 #ifdef CONFIG_PROC_FS
1847 proc_create(
"irnet", 0,
proc_irda, &irnet_proc_fops);
1851 err = irnet_setup_server();
1855 irnet_server.running = 1;
1857 DEXIT(MODULE_TRACE,
"\n");
1868 DENTER(MODULE_TRACE,
"()\n");
1871 irnet_server.running = 0;
1873 #ifdef CONFIG_PROC_FS
1879 irnet_destroy_server();
1884 DEXIT(MODULE_TRACE,
"\n");