static int h4_close(void *transport_config){
    // first remove run loop handler
	run_loop_remove_data_source(&hci_transport_h4_dma_ds);
    
    // close device 
    // ...
    return 0;
}
void socket_connection_free_connection(connection_t *conn){
    // remove from run_loop 
    run_loop_remove_data_source(&conn->ds);
    
    // and from connection list
    linked_list_remove(&connections, &conn->item);
    
    // destroy
    free(conn);
}
int socket_connection_hci_process(struct data_source *ds) {
    connection_t *conn = (connection_t *) ds;
    
    int bytes_read = read(ds->fd, &conn->buffer[conn->bytes_read], conn->bytes_to_read);
    if (bytes_read <= 0){
        // connection broken (no particular channel, no date yet)
        socket_connection_emit_connection_closed(conn);
        
        // free connection
        socket_connection_free_connection(linked_item_get_user(&conn->item));
        
        socket_connection_emit_nr_connections();
        return 0;
    }
    conn->bytes_read += bytes_read;
    conn->bytes_to_read -= bytes_read;
    // hexdump( conn->buffer, conn->bytes_read);
    if (conn->bytes_to_read > 0) {
        return 0;
    }
    
    int dispatch = 0;
    switch (conn->state){
        case SOCKET_W4_HEADER:
            conn->state = SOCKET_W4_DATA;
            conn->bytes_to_read = READ_BT_16( conn->buffer, 4);
            if (conn->bytes_to_read == 0){
                dispatch = 1;
            }
            break;
        case SOCKET_W4_DATA:
            dispatch = 1;
            break;
        default:
            break;
    }
    
    if (dispatch){
        // dispatch packet !!! connection, type, channel, data, size
        int dispatch_err = (*socket_connection_packet_callback)(conn, READ_BT_16( conn->buffer, 0), READ_BT_16( conn->buffer, 2),
                                                            &conn->buffer[sizeof(packet_header_t)], READ_BT_16( conn->buffer, 4));
        
        // reset state machine
        socket_connection_init_statemachine(conn);
        
        // "park" if dispatch failed
        if (dispatch_err) {
            log_info("socket_connection_hci_process dispatch failed -> park connection\n");
            run_loop_remove_data_source(ds);
            linked_list_add_tail(&parked, (linked_item_t *) ds);
        }
    }
	return 0;
}
static int h4_close(void *transport_config){
    // first remove run loop handler
	run_loop_remove_data_source(&hci_transport_h4_dma_ds);
    
    // stop IRQ
    hal_uart_dma_set_csr_irq_handler(NULL);
    
    // close device 
    // ...
    return 0;
}
Beispiel #5
0
static int h4_close(void *transport_config) {
    // first remove run loop handler
    run_loop_remove_data_source(hci_transport_h4->ds);

    // close device
    close(hci_transport_h4->ds->fd);

    // free struct
    free(hci_transport_h4->ds);
    hci_transport_h4->ds = NULL;
    return 0;
}
Beispiel #6
0
static int    h5_close(){
    // first remove run loop handler
	run_loop_remove_data_source(hci_transport_h5->ds);
    
    // close device 
    close(hci_transport_h5->ds->fd);
    free(hci_transport_h5->ds);
    
    // free struct
    hci_transport_h5->ds = NULL;
    return 0;
}
static int    h4_close(){
    // first remove run loop handler
	run_loop_remove_data_source(hci_transport_h4->ds);
    
    // close device 
    close(hci_transport_h4->ds->fd);
    
    // let module sleep
    h4_enforce_wake_off();
    
    // free struct
    free(hci_transport_h4->ds);
    hci_transport_h4->ds = NULL;
    return 0;
}
static int usb_close(void *transport_config){
    int c;
    // @TODO: remove all run loops!

    switch (libusb_state){
        case LIB_USB_CLOSED:
            break;

        case LIB_USB_TRANSFERS_ALLOCATED:
            libusb_state = LIB_USB_INTERFACE_CLAIMED;

            if(usb_timer_active) {
                run_loop_remove_timer(&usb_timer);
                usb_timer_active = 0;
            }

            // Cancel any asynchronous transfers
            for (c = 0 ; c < ASYNC_BUFFERS ; c++) {
                libusb_cancel_transfer(event_in_transfer[c]);
                libusb_cancel_transfer(acl_in_transfer[c]);
#ifdef HAVE_SCO
                libusb_cancel_transfer(sco_in_transfer[c]);
#endif
            }

            /* TODO - find a better way to ensure that all transfers have completed */
            struct timeval tv;
            memset(&tv, 0, sizeof(struct timeval));
            libusb_handle_events_timeout(NULL, &tv);

            if (doing_pollfds){
                int r;
                for (r = 0 ; r < num_pollfds ; r++) {
                    data_source_t *ds = &pollfd_data_sources[r];
                    run_loop_remove_data_source(ds);
                }
                free(pollfd_data_sources);
                pollfd_data_sources = NULL;
                num_pollfds = 0;
                doing_pollfds = 0;
            }

        case LIB_USB_INTERFACE_CLAIMED:
            for (c = 0 ; c < ASYNC_BUFFERS ; c++) {
                if (event_in_transfer[c]) libusb_free_transfer(event_in_transfer[c]);
                if (acl_in_transfer[c])   libusb_free_transfer(acl_in_transfer[c]);
#ifdef HAVE_SCO
                if (sco_in_transfer[c])   libusb_free_transfer(sco_in_transfer[c]);
#endif
            }

            // TODO free control and acl out transfers

            libusb_release_interface(handle, 0);

        case LIB_USB_DEVICE_OPENDED:
            libusb_close(handle);

        case LIB_USB_OPENED:
            libusb_exit(NULL);
    }

    libusb_state = LIB_USB_CLOSED;
    handle = NULL;

    return 0;
}