static inline int irnet_open_tsap(irnet_socket * self) { notify_t notify; DENTER(IRDA_SR_TRACE, "(self=0x%p)\n", self); DABORT(self->tsap != NULL, -EBUSY, IRDA_SR_ERROR, "Already busy !\n"); irda_notify_init(¬ify); notify.connect_confirm = irnet_connect_confirm; notify.connect_indication = irnet_connect_indication; notify.disconnect_indication = irnet_disconnect_indication; notify.data_indication = irnet_data_indication; notify.flow_indication = irnet_flow_indication; notify.status_indication = irnet_status_indication; notify.instance = self; strlcpy(notify.name, IRNET_NOTIFY_NAME, sizeof(notify.name)); self->tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, ¬ify); DABORT(self->tsap == NULL, -ENOMEM, IRDA_SR_ERROR, "Unable to allocate TSAP !\n"); self->stsap_sel = self->tsap->stsap_sel; DEXIT(IRDA_SR_TRACE, " - tsap=0x%p, sel=0x%X\n", self->tsap, self->stsap_sel); return 0; }
/* * Function irda_open_tsap (self) * * Open local Transport Service Access Point (TSAP) * * Create a IrTTP instance for us and set all the IrTTP callbacks. */ static inline int irnet_open_tsap(irnet_socket * self) { notify_t notify; /* Callback structure */ DENTER(IRDA_SR_TRACE, "(self=0x%X)\n", (unsigned int) self); DABORT(self->tsap != NULL, -EBUSY, IRDA_SR_ERROR, "Already busy !\n"); /* Initialize IrTTP callbacks to be used by the IrDA stack */ irda_notify_init(¬ify); notify.connect_confirm = irnet_connect_confirm; notify.connect_indication = irnet_connect_indication; notify.disconnect_indication = irnet_disconnect_indication; notify.data_indication = irnet_data_indication; /*notify.udata_indication = NULL;*/ notify.flow_indication = irnet_flow_indication; notify.status_indication = irnet_status_indication; notify.instance = self; strncpy(notify.name, IRNET_NOTIFY_NAME, NOTIFY_MAX_NAME); /* Open an IrTTP instance */ self->tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, ¬ify); DABORT(self->tsap == NULL, -ENOMEM, IRDA_SR_ERROR, "Unable to allocate TSAP !\n"); /* Remember which TSAP selector we actually got */ self->stsap_sel = self->tsap->stsap_sel; DEXIT(IRDA_SR_TRACE, " - tsap=0x%X, sel=0x%X\n", (unsigned int) self->tsap, self->stsap_sel); return 0; }
void init_func_command_work_queue( void ) { bool is_su = false; is_su = controll_init( &fcwork_queue.control ); if( !is_su ) DABORT( is_su ); init_queue( &fcwork_queue.work ); is_su = controll_activate( &fcwork_queue.control ); if( !is_su ); DABORT( is_su ); }
/* * Function irnet_find_lsap_sel (self) * * Try to lookup LSAP selector in remote LM-IAS * * Basically, we start a IAP query, and then go to sleep. When the query * return, irnet_getvalue_confirm will wake us up, and we can examine the * result of the query... * Note that in some case, the query fail even before we go to sleep, * creating some races... */ static int irnet_find_lsap_sel(irnet_socket * self) { DENTER(IRDA_SR_TRACE, "(self=0x%X)\n", (unsigned int) self); /* This should not happen */ DABORT(self->iriap, -EBUSY, IRDA_SR_ERROR, "busy with a previous query.\n"); /* Create an IAP instance, will be closed in irnet_getvalue_confirm() */ self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, irnet_getvalue_confirm); /* Treat unexpected signals as disconnect */ self->errno = -EHOSTUNREACH; /* Query remote LM-IAS */ iriap_getvaluebyclass_request(self->iriap, self->saddr, self->daddr, IRNET_SERVICE_NAME, IRNET_IAS_VALUE); /* Wait for answer (if not already failed) */ if(self->iriap != NULL) interruptible_sleep_on(&self->query_wait); /* Check what happened */ if(self->errno) { DEBUG(IRDA_SR_INFO, "IAS query failed! (%d)\n", self->errno); /* Requested object/attribute doesn't exist */ if((self->errno == IAS_CLASS_UNKNOWN) || (self->errno == IAS_ATTRIB_UNKNOWN)) return (-EADDRNOTAVAIL); else return (-EHOSTUNREACH); } /* Get the remote TSAP selector */ switch(self->ias_result->type) { case IAS_INTEGER: DEBUG(IRDA_SR_INFO, "result=%d\n", self->ias_result->t.integer); if(self->ias_result->t.integer != -1) self->dtsap_sel = self->ias_result->t.integer; else self->dtsap_sel = 0; break; default: self->dtsap_sel = 0; DERROR(IRDA_SR_ERROR, "bad type ! (0x%X)\n", self->ias_result->type); break; } /* Cleanup */ if(self->ias_result) irias_delete_value(self->ias_result); DEXIT(IRDA_SR_TRACE, "\n"); if(self->dtsap_sel) return 0; return -EADDRNOTAVAIL; }
static inline int irnet_find_lsap_sel(irnet_socket * self) { DENTER(IRDA_SR_TRACE, "(self=0x%p)\n", self); DABORT(self->iriap, -EBUSY, IRDA_SR_ERROR, "busy with a previous query.\n"); self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, irnet_getvalue_confirm); self->errno = -EHOSTUNREACH; iriap_getvaluebyclass_request(self->iriap, self->rsaddr, self->daddr, IRNET_SERVICE_NAME, IRNET_IAS_VALUE); DEXIT(IRDA_SR_TRACE, "\n"); return 0; }
/* * Connect to the other side : * o convert device name to an address * o find the socket number (dlsap) * o Establish the connection */ int irda_irnet_connect(irnet_socket * self) { int err; DENTER(IRDA_SOCK_TRACE, "(self=0x%X)\n", (unsigned int) self); /* Check if we have opened a local TSAP : * If we have already opened a TSAP, it means that either we are already * connected or in the process of doing so... */ if(self->tsap != NULL) DRETURN(-EBUSY, IRDA_SOCK_INFO, "Already connecting...\n"); /* Insert ourselves in the hashbin so that the IrNET server can find us. * Notes : 4th arg is string of 32 char max and must be null terminated * When 4th arg is used (string), 3rd arg isn't (int) * Can't re-insert (MUST remove first) so check for that... */ if((irnet_server.running) && (self->q.q_next == NULL)) { unsigned long flags; spin_lock_irqsave(&irnet_server.spinlock, flags); hashbin_insert(irnet_server.list, (irda_queue_t *) self, 0, self->rname); spin_unlock_irqrestore(&irnet_server.spinlock, flags); DEBUG(IRDA_SOCK_INFO, "Inserted ``%s'' in hashbin...\n", self->rname); } /* If we don't have anything (no address, no name) */ if((self->raddr == DEV_ADDR_ANY) && (self->rname[0] == '\0')) { /* Try to find a suitable address */ if((err = irnet_discover_daddr_and_lsap_sel(self)) != 0) DRETURN(err, IRDA_SOCK_INFO, "auto-connect failed!\n"); } else { /* If we have only the name (no address), try to get an address */ if(self->raddr == DEV_ADDR_ANY) { if((err = irnet_dname_to_daddr(self)) != 0) DRETURN(err, IRDA_SOCK_INFO, "name-connect failed!\n"); } else /* Use the requested destination address */ self->daddr = self->raddr; /* Query remote LM-IAS to find LSAP selector */ if((err = irnet_find_lsap_sel(self)) != 0) DRETURN(err, IRDA_SOCK_INFO, "connect failed!\n"); } DEBUG(IRDA_SOCK_INFO, "daddr = %08x, lsap = %d, starting IrTTP connection\n", self->daddr, self->dtsap_sel); /* Open a local TSAP (an IrTTP instance) */ err = irnet_open_tsap(self); DABORT(err != 0, err, IRDA_SOCK_ERROR, "connect aborted!\n"); /* Connect to remote device */ err = irttp_connect_request(self->tsap, self->dtsap_sel, self->saddr, self->daddr, NULL, self->max_sdu_size_rx, NULL); DABORT(err != 0, err, IRDA_SOCK_ERROR, "connect aborted!\n"); DEXIT(IRDA_SOCK_TRACE, "\n"); return(0); }