Ejemplo n.º 1
0
void handle_gatt_client_event(le_event_t * event){
    le_service_t service;
    le_characteristic_t characteristic;
    switch(state){
        case TC_W4_SERVICE_RESULT:
            switch(event->type){
                case GATT_SERVICE_QUERY_RESULT:
                    service = ((le_service_event_t *) event)->service;
                    dump_service(&service);
                    services[service_count++] = service;
                    break;
                case GATT_QUERY_COMPLETE:
                    state = TC_W4_CHARACTERISTIC_RESULT;
                    service_index = 0;
                    printf("\ntest client - CHARACTERISTIC for SERVICE ");
                    printUUID128(service.uuid128); printf("\n");
                    
                    gatt_client_discover_characteristics_for_service(gc_handle, &services[service_index]);
                    break;
                default:
                    break;
            }
            break;
            
        case TC_W4_CHARACTERISTIC_RESULT:
            switch(event->type){
                case GATT_CHARACTERISTIC_QUERY_RESULT:
                    characteristic = ((le_characteristic_event_t *) event)->characteristic;
                    dump_characteristic(&characteristic);
                    break;
                case GATT_QUERY_COMPLETE:
                    if (service_index < service_count) {
                        state = TC_W4_CHARACTERISTIC_RESULT;
                        service = services[service_index++];
                        printf("\ntest client - CHARACTERISTIC for SERVICE ");
                        printUUID128(service.uuid128);
                        printf(", [0x%04x-0x%04x]\n", service.start_group_handle, service.end_group_handle);
                        
                        gatt_client_discover_characteristics_for_service(gc_handle, &service);
                        break;
                    }
                    state = TC_W4_DISCONNECT;
                    service_index = 0;
                    gap_disconnect(gc_handle);
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
    
}
Ejemplo n.º 2
0
static void printUUID(uint8_t * uuid128, uint16_t uuid16){
    if (uuid16){
        printf("%04x",uuid16);
    } else {
        printUUID128(uuid128);
    }
}
Ejemplo n.º 3
0
static void printUUID(uint8_t * uuid128, uint16_t uuid16){
    printf(", uuid ");
    if (uuid16){
        printf(" 0x%02x",uuid16);
    } else {
        printUUID128(uuid128);
    }
    printf("\n");
}
Ejemplo n.º 4
0
Archivo: att.c Proyecto: 13hoop/limo
void att_dump_attributes(void){
    att_iterator_t it;
    att_iterator_init(&it);
    while (att_iterator_has_next(&it)){
        att_iterator_fetch_next(&it);
        if (it.handle == 0) {
            printf("Handle: END\n");
            return;
        }
        printf("Handle: 0x%04x, flags: 0x%04x, uuid: ", it.handle, it.flags);
        if (it.flags & ATT_PROPERTY_UUID128){
            printUUID128(it.uuid);
        } else {
            printf("%04x", READ_BT_16(it.uuid, 0));
        }
        printf(", value_len: %u, value: ", it.value_len);
        hexdump2(it.value, it.value_len);
    }
}
Ejemplo n.º 5
0
Archivo: att.c Proyecto: matlo/btstack
void att_dump_attributes(void){
    att_iterator_t it;
    att_iterator_init(&it);
    uint8_t uuid128[16];
    while (att_iterator_has_next(&it)){
        att_iterator_fetch_next(&it);
        if (it.handle == 0) {
            log_info("Handle: END");
            return;
        }
        log_info("Handle: 0x%04x, flags: 0x%04x, uuid: ", it.handle, it.flags);
        if (it.flags & ATT_PROPERTY_UUID128){
            swap128(it.uuid, uuid128);
            printUUID128(uuid128);
        } else {
            log_info("%04x", READ_BT_16(it.uuid, 0));
        }
        log_info(", value_len: %u, value: ", it.value_len);
        hexdump(it.value, it.value_len);
    }
}
Ejemplo n.º 6
0
 void handle_gatt_client_event(le_event_t * event){
     switch(tc_state){
         case TC_W4_SERVICE_RESULT:
             switch(event->type){
                 case GATT_SERVICE_QUERY_RESULT:
                     service = ((le_service_event_t *) event)->service;
                     dump_service(&service);
                     break;
                 case GATT_QUERY_COMPLETE:
                     tc_state = TC_W4_CHARACTERISTIC_RESULT;
                     printf("\n test client - ENABLE CHARACTERISTIC for SERVICE QUERY 1: \n");
                     dump_service(&service);
                     gatt_client_discover_characteristics_for_service_by_uuid128(&test_gatt_client_context, &service, acc_chr_enable_uuid);
                     break;
                 default:
                     break;
             }
             break;

         case TC_W4_CHARACTERISTIC_RESULT:
             switch(event->type){
                 case GATT_CHARACTERISTIC_QUERY_RESULT:
                     enable_characteristic = ((le_characteristic_event_t *) event)->characteristic;
                     dump_characteristic(&enable_characteristic);
                     break;
                 case GATT_QUERY_COMPLETE:
                     tc_state = TC_W4_ACC_ENABLE;
                     printf("\n test client - ACC ENABLE\n");
                     gatt_client_write_value_of_characteristic(&test_gatt_client_context, enable_characteristic.value_handle, 1, acc_enable);
                     break;
                 default:
                     break;
             }
             break;

         case TC_W4_ACC_ENABLE:
             tc_state = TC_W4_ACC_CLIENT_CONFIG_CHARACTERISTIC_RESULT;
             printf("\n test client - CLIENT CONFIG CHARACTERISTIC for SERVICE QUERY with UUID");
             printUUID128(service.uuid128);
             printf("\n");
             gatt_client_discover_characteristics_for_service_by_uuid128(&test_gatt_client_context, &service, acc_chr_client_config_uuid);
             break;
         case TC_W4_ACC_CLIENT_CONFIG_CHARACTERISTIC_RESULT:
             switch(event->type){
                 case GATT_CHARACTERISTIC_QUERY_RESULT:
                     config_characteristic = ((le_characteristic_event_t *) event)->characteristic;
                     dump_characteristic(&config_characteristic);
                     break;
                 case GATT_QUERY_COMPLETE:
                     tc_state = TC_W4_ACC_DATA;
                     printf("\n test client - ACC Client Configuration\n");
                     gatt_client_write_client_characteristic_configuration(&test_gatt_client_context, &config_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
                     break;
                 default:
                     break;
             }
             break;
         case TC_W4_ACC_DATA:
             printf("ACC Client Data: ");
             if ( event->type != GATT_NOTIFICATION && event->type != GATT_INDICATION ) break;
             dump_characteristic_value((le_characteristic_value_event_t *) event);
             break;
         default:
             printf("Client, unhandled state %d\n", tc_state);
             break;
     }
 }
Ejemplo n.º 7
0
/* LISTING_START(GAPLEAdvDataParsing): Parsing advertising data */
static void dump_advertisement_data(uint8_t * adv_data, uint8_t adv_size){
    ad_context_t context;
    bd_addr_t address;
    uint8_t uuid_128[16];
    for (ad_iterator_init(&context, adv_size, adv_data) ; ad_iterator_has_more(&context) ; ad_iterator_next(&context)){
        uint8_t data_type = ad_iterator_get_data_type(&context);
        uint8_t size      = ad_iterator_get_data_len(&context);
        uint8_t * data    = ad_iterator_get_data(&context);
        
        if (data_type > 0 && data_type < 0x1B){
            printf("    %s: ", ad_types[data_type]);
        } 
        int i;
        // Assigned Numbers GAP
    
        switch (data_type){
            case 0x01: // Flags
                // show only first octet, ignore rest
                for (i=0; i<8;i++){
                    if (data[0] & (1<<i)){
                        printf("%s; ", flags[i]);
                    }

                }
                break;
            case 0x02: // Incomplete List of 16-bit Service Class UUIDs
            case 0x03: // Complete List of 16-bit Service Class UUIDs
            case 0x14: // List of 16-bit Service Solicitation UUIDs
                for (i=0; i<size;i+=2){
                    printf("%02X ", READ_BT_16(data, i));
                }
                break;
            case 0x04: // Incomplete List of 32-bit Service Class UUIDs
            case 0x05: // Complete List of 32-bit Service Class UUIDs
                for (i=0; i<size;i+=4){
                    printf("%04X ", READ_BT_32(data, i));
                }
                break;
            case 0x06: // Incomplete List of 128-bit Service Class UUIDs
            case 0x07: // Complete List of 128-bit Service Class UUIDs
            case 0x15: // List of 128-bit Service Solicitation UUIDs
                swap128(data, uuid_128);
                printUUID128(uuid_128);
                break;
            case 0x08: // Shortened Local Name
            case 0x09: // Complete Local Name
                for (i=0; i<size;i++){
                    printf("%c", (char)(data[i]));
                }
                break;
            case 0x0A: // Tx Power Level 
                printf("%d dBm", *(int8_t*)data);
                break;
            case 0x12: // Slave Connection Interval Range 
                printf("Connection Interval Min = %u ms, Max = %u ms", READ_BT_16(data, 0) * 5/4, READ_BT_16(data, 2) * 5/4);
                break;
            case 0x16: // Service Data 
                printf_hexdump(data, size);
                break;
            case 0x17: // Public Target Address
            case 0x18: // Random Target Address
                bt_flip_addr(address, data);
                print_bd_addr(address);
                break;
            case 0x19: // Appearance 
                // https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
                printf("%02X", READ_BT_16(data, 0) );
                break;
            case 0x1A: // Advertising Interval 
                printf("%u ms", READ_BT_16(data, 0) * 5/8 );
                break;
            case 0x3D: // 3D Information Data 
                printf_hexdump(data, size);
                break;
            case 0xFF: // Manufacturer Specific Data 
                break;
            case 0x0D: // Class of Device (3B)
            case 0x0E: // Simple Pairing Hash C (16B)
            case 0x0F: // Simple Pairing Randomizer R (16B) 
            case 0x10: // Device ID 
            case 0x11: // Security Manager TK Value (16B)
            default:
                printf("Unknown Advertising Data Type"); 
                break;
        }        
        printf("\n");
    }
    printf("\n");
}