void main_cbsc_tx_run(void) { // Open the ANT channel and initialize the profile module. channel_open(); uint32_t err_code = cbsc_tx_initialize(); APP_ERROR_CHECK(err_code); uint8_t ant_channel; uint8_t event_message_buffer[ANT_EVENT_MSG_BUFFER_MIN_SIZE]; uint8_t event = NO_EVENT; // Extract and process all pending events, while maximizing application sleep. for (;;) { err_code = sd_app_event_wait(); APP_ERROR_CHECK(err_code); // Extract and process all pending ANT stack events. while (sd_ant_event_get(&ant_channel, &event, event_message_buffer) == NRF_SUCCESS) { err_code = cbsc_tx_channel_event_handle(event); APP_ERROR_CHECK(err_code); } } }
void channel_init_for_debug(void) { u8 i = 0, j = 0; _channel_config(); //初始化血沉值 for (i=0; i<MAX_CHANNELS; i++) { channel_open(i); switch (i) { case 0: tubes[i].inplace = 1; break; case 1: tubes[i].inplace = 0; break; case 2: tubes[i].inplace = 0; break; case 3: tubes[i].inplace = 0; break; #ifndef SMALL_MACHINE case 4: tubes[i].inplace = 0; break; case 5: tubes[i].inplace = 0; break; case 6: tubes[i].inplace = 0; break; case 7: tubes[i].inplace = 0; break; case 8: tubes[i].inplace = 0; break; case 9: tubes[i].inplace = 0; break; #endif } channel_close(); if (tubes[i].inplace) { tubes[i].status = CHN_STATUS_WAITING; tubes[i].insert_time = rtc_get_sec(); } else tubes[i].status = CHN_STATUS_NONE; tubes[i].remains = MAX_MEASURE_TIMES; for (j=0; j<MAX_MEASURE_TIMES; j++) tubes[i].values[j] = 0; } }
/*---------------------------------------------------------------------------*/ void abc_open(struct abc_conn *c, uint16_t channelno, const struct abc_callbacks *callbacks) { channel_open(&c->channel, channelno); c->u = callbacks; channel_set_attributes(channelno, attributes); }
/** * @brief Open a session channel (suited for a shell, not TCP forwarding). * * @param channel An allocated channel. * * @return SSH_OK on success\n * SSH_ERROR on error. * * @see channel_open_forward() * @see channel_request_env() * @see channel_request_shell() * @see channel_request_exec() */ int channel_open_session(CHANNEL *channel) { #ifdef HAVE_SSH1 if (channel->session->version == 1) { return channel_open_session1(channel); } #endif return channel_open(channel,"session",64000,32000,NULL); }
static void channel_check_all_for_debug(void) { u8 i; for (i=0; i<MAX_CHANNELS; i++) { if (tubes[i].status != CHN_STATUS_NONE) continue; channel_open(i); switch (i) { case 0: tubes[i].inplace = 1; break; case 1: tubes[i].inplace = 0; break; case 2: tubes[i].inplace = 0; break; case 3: tubes[i].inplace = 0; break; #ifndef SMALL_MACHINE case 4: tubes[i].inplace = 0; break; case 5: tubes[i].inplace = 0; break; case 6: tubes[i].inplace = 0; break; case 7: tubes[i].inplace = 0; break; case 8: tubes[i].inplace = 0; break; case 9: tubes[i].inplace = 0; break; #endif } channel_close(); if (tubes[i].inplace) { tubes[i].status = CHN_STATUS_WAITING; tubes[i].insert_time = rtc_get_sec(); } else tubes[i].status = CHN_STATUS_NONE; } }
int channel_open_session(CHANNEL *channel){ #ifdef HAVE_SSH1 if(channel->session.version.version==2) #endif return channel_open(channel,"session",64000,32000,NULL); #ifdef HAVE_SSH1 else return channel_open_session1(channel); #endif }
static void initialize_devices() { watchdog_enable(SYSTEM_WATCHDOG_INTERVAL_s); (void /* what to do if it fails? */)channel_open(ch_fpga_ctrl); // Is it safer to do it? commhub_connectUarts(COMMHUB_UART_ADDR_TMS_0_UART_1, COMMHUB_UART_ADDR_LITHIUM); // commhub_connectUarts(COMMHUB_UART_ADDR_TMS_0_UART_0, COMMHUB_UART_ADDR_UMB); // commhub_disconnectUartRx(COMMHUB_UART_ADDR_CONDOR); // commhub_disconnectUartRx(COMMHUB_UART_ADDR_SVIP_0); // commhub_disconnectUartRx(COMMHUB_UART_ADDR_SVIP_1); // commhub_disconnectUartRx(COMMHUB_UART_ADDR_OVERO_UART_1); }
int nvitem_sync(void) { static uint32 ifInit = 0; if(0 == ifInit){ initEvent(); initBuf(); channel_open(); _initPacket(); _syncInit(); ifInit = 1; } syncAnalyzer(); }
/*===========================================================================* * rpc_open * *===========================================================================*/ int rpc_open(void) { /* Open a HGFS RPC backdoor channel to the VMware host, and make sure that it * is working. Return OK upon success, or a negative error code otherwise; in * particular, return EAGAIN if shared folders are disabled. */ int r; if ((r = channel_open(&rpc_chan, CH_OUT)) != OK) return r; r = rpc_test(); if (r != OK) channel_close(&rpc_chan); return r; }
/** * @brief Open a TCP/IP forwarding channel. * * @param channel An allocated channel. * * @param remotehost The remote host to connected (host name or IP). * * @param remoteport The remote port. * * @param sourcehost The source host (your local computer). It's facultative * and for logging purpose. * * @param localport The source port (your local computer). It's facultative * and for logging purpose. * * @return SSH_OK on success\n * SSH_ERROR on error */ int channel_open_forward(CHANNEL *channel, const char *remotehost, int remoteport, const char *sourcehost, int localport) { SSH_SESSION *session = channel->session; BUFFER *payload = NULL; STRING *str = NULL; int rc = SSH_ERROR; enter_function(); payload = buffer_new(); if (payload == NULL) { goto error; } str = string_from_char(remotehost); if (str == NULL) { goto error; } if (buffer_add_ssh_string(payload, str) < 0 || buffer_add_u32(payload,htonl(remoteport)) < 0) { goto error; } string_free(str); str = string_from_char(sourcehost); if (str == NULL) { goto error; } if (buffer_add_ssh_string(payload, str) < 0 || buffer_add_u32(payload,htonl(localport)) < 0) { goto error; } rc = channel_open(channel, "direct-tcpip", 64000, 32000, payload); error: buffer_free(payload); string_free(str); leave_function(); return rc; }
// --------------------------------------------------------------------------- /// Establishes connection (all receives now will be met with proper sends). // --------------------------------------------------------------------------- void syncMesh_syncronize (connection_t *slot) { ENSURE (!slot->remote, "multiple syncronization is not allowed"); /* SAY_DEBUG ("List of claims for syncronization of the %s connection.", slot->channel.name); for (int cpu = 0 ; cpu < cpu_total ; ++cpu) { SAY_DEBUG (" cpu %d:", cpu); regList_dump (slot->local + cpu, " - "); } */ slot->remote = syncReg_sync (slot->local); // Syncronizes reg_t lists. for (int cpu = 0 ; cpu < cpu_total ; ++cpu) // Wraps ghost regions to align properly. for (int r = 0 ; r < slot->remote[cpu].N ; ++r) reg_unwrap (slot->remote[cpu].list + r); int *sizes = (int*) calloc (cpu_total, sizeof (int)); // Allocates empty sizes array. ENSURE (sizes, "cannot allocate memory for 'sizes'"); for (int cpu = 0 ; cpu < cpu_total ; ++cpu) // Calculates exchange buffer sizes. { reg_t *reg = slot->local[cpu].list, *end = slot->local[cpu].list + slot->local[cpu].N; for ( ; reg < end ; ++reg) sizes[cpu] += reg_volume (reg)*slot->bytesPerNode; } sizes[cpu_here] = 0; // Ignores sending to myself. channel_open (&slot->channel, mc_channel_income, sizes); // Opens channel. free (sizes); socket_t *s = slot->channel.sockets[mc_channel_income]; // Associates socket buffer with local reg-list. for (const socket_t * const end = s + slot->channel.socketsN[mc_channel_income] ; s < end ; ++s) s->boss = slot->local + s->cpu; s = slot->channel.sockets[mc_channel_outcome]; // Associates socket buffer with remote reg-list. for (const socket_t * const end = s + slot->channel.socketsN[mc_channel_outcome] ; s < end ; ++s) s->boss = slot->remote + s->cpu; regList_clean (&slot->map); // Removes map (no longer needed). }
int mwChannel_accept(struct mwChannel *chan) { struct mwSession *session; struct mwMsgChannelAccept *msg; struct mwCipherInstance *ci; int ret; g_return_val_if_fail(chan != NULL, -1); g_return_val_if_fail(mwChannel_isIncoming(chan), -1); g_return_val_if_fail(chan->state == mwChannel_WAIT, -1); session = chan->session; g_return_val_if_fail(session != NULL, -1); msg = (struct mwMsgChannelAccept *) mwMessage_new(mwMessage_CHANNEL_ACCEPT); msg->head.channel = chan->id; msg->service = chan->service; msg->proto_type = chan->proto_type; msg->proto_ver = chan->proto_ver; mwOpaque_clone(&msg->addtl, &chan->addtl_accept); ci = chan->cipher; if(! ci) { /* automatically select a cipher if one hasn't been already */ switch(chan->offered_policy) { case mwEncrypt_NONE: mwChannel_selectCipherInstance(chan, NULL); break; case mwEncrypt_RC2_40: ci = get_supported(chan, mwCipher_RC2_40); mwChannel_selectCipherInstance(chan, ci); break; case mwEncrypt_RC2_128: ci = get_supported(chan, mwCipher_RC2_128); mwChannel_selectCipherInstance(chan, ci); break; case mwEncrypt_WHATEVER: case mwEncrypt_ALL: default: { GList *l, *ll; l = mwChannel_getSupportedCipherInstances(chan); if(l) { /* nobody selected a cipher, so we'll just pick the last in the list of available ones */ for(ll = l; ll->next; ll = ll->next); ci = ll->data; g_list_free(l); mwChannel_selectCipherInstance(chan, ci); } else { /* this may cause breakage, but there's really nothing else we can do. They want something we can't provide. If they don't like it, then they'll error the channel out */ mwChannel_selectCipherInstance(chan, NULL); } } } } msg->encrypt.mode = chan->policy; /* set in selectCipherInstance */ msg->encrypt.extra = chan->offered_policy; if(chan->cipher) { msg->encrypt.item = mwCipherInstance_accept(chan->cipher); } ret = mwSession_send(session, MW_MESSAGE(msg)); mwMessage_free(MW_MESSAGE(msg)); if(ret) { state(chan, mwChannel_ERROR, ret); } else { channel_open(chan); } return ret; }
/* * handle connection request */ static void server_read(int s, short ev, void *arg) { struct sockaddr_l2cap ra, la; channel_t *chan; socklen_t len; int fd, n; uint16_t mru, mtu; len = sizeof(ra); fd = accept(s, (struct sockaddr *)&ra, &len); if (fd == -1) return; n = 1; if (ioctl(fd, FIONBIO, &n) == -1) { log_err("Could not set NonBlocking IO: %m"); close(fd); return; } len = sizeof(mru); if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_IMTU, &mru, &len) == -1) { log_err("Could not get L2CAP IMTU: %m"); close(fd); return; } if(mru < BNEP_MTU_MIN) { log_err("L2CAP IMTU too small (%d)", mru); close(fd); return; } len = sizeof(n); if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) { log_err("Could not read SO_RCVBUF"); close(fd); return; } if (n < (mru * 10)) { n = mru * 10; if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1) log_info("Could not increase SO_RCVBUF (from %d)", n); } len = sizeof(mtu); if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) { log_err("Could not get L2CAP OMTU: %m"); close(fd); return; } if (mtu < BNEP_MTU_MIN) { log_err("L2CAP OMTU too small (%d)", mtu); close(fd); return; } len = sizeof(n); if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, &len) == -1) { log_err("Could not get socket send buffer size: %m"); close(fd); return; } if (n < (mtu * 2)) { n = mtu * 2; if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) == -1) { log_err("Could not set socket send buffer size (%d): %m", n); close(fd); return; } } n = mtu; if (setsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &n, sizeof(n)) == -1) { log_err("Could not set socket low water mark (%d): %m", n); close(fd); return; } len = sizeof(la); if (getsockname(fd, (struct sockaddr *)&la, &len) == -1) { log_err("Could not get socket address: %m"); close(fd); return; } log_info("Accepted connection from %s", bt_ntoa(&ra.l2cap_bdaddr, NULL)); chan = channel_alloc(); if (chan == NULL) { close(fd); return; } chan->send = bnep_send; chan->recv = bnep_recv; chan->mru = mru; chan->mtu = mtu; b2eaddr(chan->raddr, &ra.l2cap_bdaddr); b2eaddr(chan->laddr, &la.l2cap_bdaddr); chan->state = CHANNEL_WAIT_CONNECT_REQ; channel_timeout(chan, 10); if (!channel_open(chan, fd)) { chan->state = CHANNEL_CLOSED; channel_free(chan); close(fd); return; } }
int32_t channelOpen( uint32_t channelId ) { return channel_open( channelId ); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_abc_process, ev, data) { static struct etimer et; static struct channel *c; PROCESS_BEGIN(); char buffer[32]; //button_sensor.activate(); SENSORS_ACTIVATE(button_sensor); printf("ready to rock\n"); static int i, j, k; //cc2420_init(); //cc2420_set_pan_addr(panId, 0 /*XXX*/, ds2411_id); //cc2420_set_channel(26); //cc2420_set_txpower(31); cc2420_on(); driver = nullmac_init(&cc2420_driver); driver->on(); channel_open(c, 128);channel_set_attributes(128, attributes); packetbuf_clear(); driver->set_receive_function(recv); packetbuf_clear(); //set_receive_function(driver); while(1) { //PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); for (j = 0; j < 10000; j++) k = j/23; sprintf(buffer, "ping %d, %d\0",i, k); printf("Attempting to send %s\n", buffer); // send the message straight to the radio //cc2420_send ( buffer, (int)strlen(buffer) ); packetbuf_clear(); packetbuf_copyfrom(&buffer, (int)strlen(buffer)); driver->send(); printf("Message sent\n"); leds_toggle(LEDS_RED); i = i + 1; } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_abc_process, ev, data) { static struct channel *c; static struct etimer et; PROCESS_BEGIN(); char buffer[32]; //button_sensor.activate(); SENSORS_ACTIVATE(button_sensor); printf("ready to rock\n"); //ds2411_init(); static int i; //cc2420_init(); //cc2420_set_pan_addr(panId, 0 /*XXX*/, ds2411_id); //cc2420_set_channel(26); //abc_open(&abc, 128, &abc_call); // set_rime_addr(); // cc2420_init(); //cc2420_set_pan_addr(panId, 0 , ds2411_id); // cc2420_set_channel(RF_CHANNEL); //cc2420_set_txpower(31); //nullmac_init(&cc2420_driver); //rime_init(&nullmac_driver); //cc2420_set_txpower(31); //cc2420_on(); channel_init(); packetbuf_clear(); driver = nullmac_init(&cc2420_driver); //rime_init(driver); //driver = sicslowmac_init(&cc2420_driver); cc2420_set_channel(26); channel_open(c, 34); /*packetbuf_clear();*/ driver->set_receive_function(recv); //packetbuf_clear(); channel_set_attributes(34, attributes); //set_receive_function(driver); driver->on(); leds_toggle(LEDS_RED); packetbuf_clear(); etimer_set(&et, CLOCK_SECOND * 2 + random_rand() % (CLOCK_SECOND * 2)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); leds_toggle(LEDS_RED); PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); while(1) { if (i % 20 == 19) { PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); } else { printf("wait!"); etimer_set(&et, CLOCK_SECOND * 0.5 + random_rand() % (CLOCK_SECOND) * 0.25); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); } sprintf(buffer, "ping %d\0",i); printf("Attempting to send %s\n", buffer); // send the message straight to the radio //cc2420_send ( buffer, (int)strlen(buffer) ); packetbuf_clear(); packetbuf_copyfrom(&buffer, (int)strlen(buffer)); //driver->on(); //cc2420_driver.send(&buffer, (int)strlen(buffer)); //cc2420_send ( &buffer, (int)strlen(buffer) ); driver->send(); //rime_output(); //abc_send(&abc); //chameleon_output(c); //driver->off(1); printf("Message sent\n"); leds_toggle(LEDS_YELLOW); i = i + 1; } PROCESS_END(); }
static void channel_check_all(void) { u8 i; for (i=0; i<MAX_CHANNELS; i++) { if (tubes[i].status != CHN_STATUS_NONE) continue; channel_open(i); switch (i) { case 0: tubes[i].inplace = !BLOOD_VALUE0; break; case 1: tubes[i].inplace = !BLOOD_VALUE1; break; case 2: tubes[i].inplace = !BLOOD_VALUE2; break; case 3: tubes[i].inplace = !BLOOD_VALUE3; break; #ifndef SMALL_MACHINE case 4: tubes[i].inplace = !BLOOD_VALUE4; break; case 5: tubes[i].inplace = !BLOOD_VALUE5; break; case 6: tubes[i].inplace = !BLOOD_VALUE6; break; case 7: tubes[i].inplace = !BLOOD_VALUE7; break; case 8: tubes[i].inplace = !BLOOD_VALUE8; break; case 9: tubes[i].inplace = !BLOOD_VALUE9; break; #endif } channel_close(); /* 没有插入管子 */ if (!tubes[i].inplace) { tubes[i].status = CHN_STATUS_NONE; return; } /* 血沉管在位 */ switch (tubes[i].remains) { case MAX_MEASURE_TIMES: tubes[i].status = CHN_STATUS_WAITING; tubes[i].insert_time = rtc_get_sec(); break; case 0: tubes[i].status = CHN_STATUS_FINISH; break; default: tubes[i].status = CHN_STATUS_WAITING; break; } } }
uint8_t file_submit_call(uint8_t channel_no, uint8_t type, uint8_t *cmd_buffer, errormsg_t *errormsg, rtconfig_t *rtconf, void (*callback)(int8_t errnum, uint8_t *rxdata), uint8_t iscmd) { assert_not_null(errormsg, "file_submit_call: errormsg is null"); assert_not_null(rtconf, "file_submit_call: rtconf is null"); // check for default drive (here is the place to set the last used one) if (nameinfo.drive == NAMEINFO_LAST_DRIVE) { nameinfo.drive = rtconf->last_used_drive; } else if (nameinfo.drive == NAMEINFO_UNUSED_DRIVE) { // TODO: match CBM behavior nameinfo.drive = rtconf->last_used_drive; } else if (nameinfo.drive < MAX_DRIVES) { // only save real drive numbers as last used default rtconf->last_used_drive = nameinfo.drive; } // if second name does not have a drive, use drive from first, // but only if it is defined if (nameinfo.file[0].drive == NAMEINFO_UNUSED_DRIVE && nameinfo.drive != NAMEINFO_UNDEF_DRIVE) { nameinfo.file[0].drive = nameinfo.drive; } // here is the place to plug in other file system providers, // like SD-Card, or even an outgoing IEC or IEEE, to convert between // the two bus systems. This is done depending on the drive number // and managed with the ASSIGN call. //provider_t *provider = &serial_provider; endpoint_t *endpoint = NULL; if (type == FS_OPEN_DIRECT) { debug_printf("Getting direct endpoint provider for channel %d\n", channel_no); endpoint = direct_provider(); } else { endpoint = provider_lookup(nameinfo.drive, (char*) nameinfo.drivename); } // convert from bus' PETSCII to provider // currently only up to the first zero byte is converted, options like file type // are still ASCII only // in the future the bus may have an own conversion option... cconv_converter(CHARSET_PETSCII, endpoint->provider->charset(endpoint->provdata)) ((char*)nameinfo.name, strlen((char*)nameinfo.name), (char*)nameinfo.name, strlen((char*)nameinfo.name)); for (uint8_t i=0 ; i < nameinfo.num_files ; ++i) { if (nameinfo.file[i].name != NULL) { cconv_converter(CHARSET_PETSCII, endpoint->provider->charset(endpoint->provdata)) ((char*)nameinfo.file[i].name, strlen((char*)nameinfo.file[i].name), (char*)nameinfo.file[i].name, strlen((char*)nameinfo.file[i].name)); } } if (type == FS_MOVE && nameinfo.file[0].drive != NAMEINFO_UNUSED_DRIVE // then use ep from first drive anyway && nameinfo.file[0].drive != nameinfo.drive) { // no need to check if the same // two-name command(s) with possibly different drive numbers endpoint_t *endpoint2 = provider_lookup(nameinfo.file[0].drive, (char*) nameinfo.file[0].name); if (endpoint2 != endpoint) { debug_printf("ILLEGAL DRIVE COMBINATION: %d vs. %d\n", nameinfo.drive+0x30, nameinfo.file[0].drive+0x30); set_error_tsd(errormsg, CBM_ERROR_DRIVE_NOT_READY, 0, 0, nameinfo.drive); return -1; } } // check the validity of the drive (note that in general provider_lookup // returns a default provider - serial-over-USB to the PC, which then // may do further checks if (endpoint == NULL) { debug_puts("ILLEGAL DRIVE: "); debug_putc(0x30+nameinfo.drive); debug_putcrlf(); set_error_tsd(errormsg, CBM_ERROR_DRIVE_NOT_READY, 0, 0, nameinfo.drive); return -1; } provider_t *provider = endpoint->provider; // find open slot //int8_t slot = -1; open_t *activeslot = NULL; for (uint8_t i = 0; i < MAX_ACTIVE_OPEN; i++) { if (active[i].channel_no < 0) { //slot = i; activeslot = (open_t*) &active[i]; break; } } //if (slot < 0) { if (activeslot == NULL) { debug_puts("NO OPEN SLOT FOR OPEN!"); debug_putcrlf(); set_error_tsd(errormsg, CBM_ERROR_NO_CHANNEL, 0, 0, nameinfo.drive); return -1; } activeslot->endpoint = endpoint; uint8_t len = assemble_filename_packet(cmd_buffer, &nameinfo); #ifdef DEBUG_FILE debug_printf("LEN AFTER ASSEMBLE=%d\n", len); #endif packet_init(&activeslot->txbuf, len, cmd_buffer); // store pointer to runtime config in packet // used by providers running on the device activeslot->txbuf.rtc = rtconf; packet_set_filled(&activeslot->txbuf, channel_no, type, len); if (!iscmd) { // only for file opens // note: we need the provider for the dir converter, // so we can only do it in here. // open channel uint8_t writetype = WTYPE_READONLY; if (type == FS_OPEN_WR || type == FS_OPEN_AP || type == FS_OPEN_OW) { writetype = WTYPE_WRITEONLY; } else if (type == FS_OPEN_RW) { writetype = WTYPE_READWRITE; } if (nameinfo.options & NAMEOPT_NONBLOCKING) { writetype |= WTYPE_NONBLOCKING; } int8_t (*converter)(void *, packet_t*, uint8_t) = (type == FS_OPEN_DR) ? (provider->directory_converter) : NULL; // TODO: if provider->channel_* are not NULL, we should probably not allocate a channel // but that would break the FILE OPEN detection here. channel_t *channel = channel_find(channel_no); if (channel != NULL) { // clean up channel_close(channel_no); // Note: it seems possible to open the same channel multiple times // on a direct file if (type != FS_OPEN_DIRECT) { debug_puts("FILE OPEN ERROR"); debug_putcrlf(); set_error_tsd(errormsg, CBM_ERROR_NO_CHANNEL, 0, 0, nameinfo.drive); return -1; } } int8_t e = channel_open(channel_no, writetype, endpoint, converter, nameinfo.drive); if (e < 0) { debug_puts("E="); debug_puthex(e); debug_putcrlf(); set_error_tsd(errormsg, CBM_ERROR_NO_CHANNEL, 0, 0, nameinfo.drive); return -1; } } activeslot->callback = callback; // no more error here, just the submit. // so callers can be sure if this function returns <0, they do not need // to close the channel, as it has not been opened // If this function returns 0, a callback must be received and handled, // and the channel is already opened. activeslot->channel_no = channel_no; // prepare response buffer packet_init(&activeslot->rxbuf, OPEN_RX_DATA_LEN, activeslot->rxdata); provider->submit_call(endpoint->provdata, channel_no, &activeslot->txbuf, &activeslot->rxbuf, _file_open_callback); return 0; }
int main(int argc, char *argv[]) { int fd; int res, x; int bs = BLOCK_SIZE; unsigned char c=0; unsigned char outbuf[BLOCK_SIZE]; int setup=0; int errors=0; int bytes=0; prog_name = argv[0]; if (argc < 2) { usage(); } fd = channel_open(argv[1], &bs); if (fd < 0) exit(1); ioctl(fd, DAHDI_GETEVENT); for(;;) { res = bs; res = read(fd, outbuf, res); if (res < bs) { int e; struct dahdi_spaninfo zi; res = ioctl(fd,DAHDI_GETEVENT,&e); if (res == -1) { perror("DAHDI_GETEVENT"); exit(1); } if (e == DAHDI_EVENT_NOALARM) printf("ALARMS CLEARED\n"); if (e == DAHDI_EVENT_ALARM) { zi.spanno = 0; res = ioctl(fd,DAHDI_SPANSTAT,&zi); if (res == -1) { perror("DAHDI_SPANSTAT"); exit(1); } printf("Alarm mask %x hex\n",zi.alarms); } continue; } if (!setup) { c = outbuf[0]; setup++; } for (x=0;x<bs;x++) { if (outbuf[x] != c) { printf("(Error %d): Unexpected result, %d != %d, %d bytes since last error.\n", ++errors, outbuf[x], c, bytes); c = outbuf[x]; bytes=0; } c = bit_next(c); bytes++; } #if 0 printf("(%d) Wrote %d bytes\n", packets++, res); #endif } }
void mwChannel_recvAccept(struct mwChannel *chan, struct mwMsgChannelAccept *msg) { struct mwService *srvc; g_return_if_fail(chan != NULL); g_return_if_fail(msg != NULL); g_return_if_fail(chan->id == msg->head.channel); if(mwChannel_isIncoming(chan)) { g_warning("channel 0x%08x not an outgoing channel", chan->id); mwChannel_destroy(chan, ERR_REQUEST_INVALID, NULL); return; } if(chan->state != mwChannel_WAIT) { g_warning("channel 0x%08x state not WAIT: %s", chan->id, state_str(chan->state)); mwChannel_destroy(chan, ERR_REQUEST_INVALID, NULL); return; } mwLoginInfo_clone(&chan->user, &msg->acceptor); srvc = mwSession_getService(chan->session, chan->service); if(! srvc) { g_warning("no service: 0x%08x", chan->service); mwChannel_destroy(chan, ERR_SERVICE_NO_SUPPORT, NULL); return; } chan->policy = msg->encrypt.mode; g_message("channel accepted with encrypt policy 0x%04x", chan->policy); if(! msg->encrypt.mode || ! msg->encrypt.item) { /* no mode or no item means no encryption */ mwChannel_selectCipherInstance(chan, NULL); } else { guint16 cid = msg->encrypt.item->id; struct mwCipherInstance *ci = get_supported(chan, cid); if(! ci) { g_warning("not an offered cipher: 0x%04x", cid); mwChannel_destroy(chan, ERR_REQUEST_INVALID, NULL); return; } mwCipherInstance_accepted(ci, msg->encrypt.item); mwChannel_selectCipherInstance(chan, ci); } /* mark it as open for the service */ state(chan, mwChannel_OPEN, 0); /* let the service know */ mwService_recvAccept(srvc, chan, msg); /* flush it if the service didn't just immediately close it */ if(mwChannel_isState(chan, mwChannel_OPEN)) { channel_open(chan); } }
void tap_init(void) { channel_t *chan; struct ifreq ifr; int fd, s; char pidfile[PATH_MAX]; fd = open(interface_name, O_RDWR); if (fd == -1) { log_err("Could not open \"%s\": %m", interface_name); exit(EXIT_FAILURE); } memset(&ifr, 0, sizeof(ifr)); if (ioctl(fd, TAPGIFNAME, &ifr) == -1) { log_err("Could not get interface name: %m"); exit(EXIT_FAILURE); } s = socket(AF_INET, SOCK_DGRAM, 0); if (s == -1) { log_err("Could not open PF_LINK socket: %m"); exit(EXIT_FAILURE); } ifr.ifr_addr.sa_family = AF_LINK; ifr.ifr_addr.sa_len = ETHER_ADDR_LEN; b2eaddr(ifr.ifr_addr.sa_data, &local_bdaddr); if (ioctl(s, SIOCSIFLLADDR, &ifr) == -1) { log_err("Could not set %s physical address: %m", ifr.ifr_name); exit(EXIT_FAILURE); } if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) { log_err("Could not get interface flags: %m"); exit(EXIT_FAILURE); } if ((ifr.ifr_flags & IFF_UP) == 0) { ifr.ifr_flags |= IFF_UP; if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) { log_err("Could not set IFF_UP: %m"); exit(EXIT_FAILURE); } } close(s); log_info("Using interface %s with addr %s", ifr.ifr_name, ether_ntoa((struct ether_addr *)&ifr.ifr_addr.sa_data)); chan = channel_alloc(); if (chan == NULL) exit(EXIT_FAILURE); chan->send = tap_send; chan->recv = tap_recv; chan->mru = ETHER_HDR_LEN + ETHER_MAX_LEN; memcpy(chan->raddr, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); memcpy(chan->laddr, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); chan->state = CHANNEL_OPEN; if (!channel_open(chan, fd)) exit(EXIT_FAILURE); snprintf(pidfile, sizeof(pidfile), "%s/%s.pid", _PATH_VARRUN, ifr.ifr_name); chan->pfh = pidfile_open(pidfile, 0600, NULL); if (chan->pfh == NULL) log_err("can't create pidfile"); else if (pidfile_write(chan->pfh) < 0) { log_err("can't write pidfile"); pidfile_remove(chan->pfh); chan->pfh = NULL; } }
void client_init(void) { struct sockaddr_l2cap sa; channel_t *chan; socklen_t len; int fd, n; uint16_t mru, mtu; if (bdaddr_any(&remote_bdaddr)) return; if (service_name) client_query(); fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP); if (fd == -1) { log_err("Could not open L2CAP socket: %m"); exit(EXIT_FAILURE); } memset(&sa, 0, sizeof(sa)); sa.l2cap_family = AF_BLUETOOTH; sa.l2cap_len = sizeof(sa); sa.l2cap_bdaddr_type = BDADDR_BREDR; sa.l2cap_cid = 0; bdaddr_copy(&sa.l2cap_bdaddr, &local_bdaddr); if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { log_err("Could not bind client socket: %m"); exit(EXIT_FAILURE); } mru = BNEP_MTU_MIN; if (setsockopt(fd, SOL_L2CAP, SO_L2CAP_IMTU, &mru, sizeof(mru)) == -1) { log_err("Could not set L2CAP IMTU (%d): %m", mru); exit(EXIT_FAILURE); } log_info("Opening connection to service 0x%4.4x at %s", service_class, bt_ntoa(&remote_bdaddr, NULL)); sa.l2cap_psm = htole16(l2cap_psm); bdaddr_copy(&sa.l2cap_bdaddr, &remote_bdaddr); if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { log_err("Could not connect: %m"); exit(EXIT_FAILURE); } len = sizeof(mru); if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_IMTU, &mru, &len) == -1) { log_err("Could not get IMTU: %m"); exit(EXIT_FAILURE); } if (mru < BNEP_MTU_MIN) { log_err("L2CAP IMTU too small (%d)", mru); exit(EXIT_FAILURE); } len = sizeof(n); if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) { log_err("Could not read SO_RCVBUF"); exit(EXIT_FAILURE); } if (n < (mru * 10)) { n = mru * 10; if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1) log_info("Could not increase SO_RCVBUF (from %d)", n); } len = sizeof(mtu); if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) { log_err("Could not get L2CAP OMTU: %m"); exit(EXIT_FAILURE); } if (mtu < BNEP_MTU_MIN) { log_err("L2CAP OMTU too small (%d)", mtu); exit(EXIT_FAILURE); } len = sizeof(n); if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, &len) == -1) { log_err("Could not get socket send buffer size: %m"); close(fd); return; } if (n < (mtu * 2)) { n = mtu * 2; if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) == -1) { log_err("Could not set socket send buffer size (%d): %m", n); close(fd); return; } } n = mtu; if (setsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &n, sizeof(n)) == -1) { log_err("Could not set socket low water mark (%d): %m", n); close(fd); return; } chan = channel_alloc(); if (chan == NULL) exit(EXIT_FAILURE); chan->send = bnep_send; chan->recv = bnep_recv; chan->mru = mru; chan->mtu = mtu; b2eaddr(chan->raddr, &remote_bdaddr); b2eaddr(chan->laddr, &local_bdaddr); chan->state = CHANNEL_WAIT_CONNECT_RSP; channel_timeout(chan, 10); if (!channel_open(chan, fd)) exit(EXIT_FAILURE); bnep_send_control(chan, BNEP_SETUP_CONNECTION_REQUEST, 2, service_class, SDP_SERVICE_CLASS_PANU); }