removed duplicate gap_inquiry.c sdp_general_query.c sdp_rfcomm_query.c

This commit is contained in:
matthias.ringwald@gmail.com 2014-11-15 17:20:34 +00:00
parent 166c83b075
commit e5985bbbf8
4 changed files with 4 additions and 551 deletions

View File

@ -110,7 +110,7 @@ hid_demo.out: ${CORE_OBJ} ${COMMON_OBJ} ${LCD_OBJ} ${SPP_OBJ} ${CC2560B} hid_dem
spp_accel.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} spp_accel.o sdp.o hal_adc.o
${CC} $^ ${LDFLAGS} -o $@
spp_and_le_counter.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${BLE_OBJ} spp_and_le_counter.h spp_and_le_counter.o sdp.o hal_adc.o
spp_and_le_counter.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${BLE_OBJ} main.o spp_and_le_counter.h spp_and_le_counter.o sdp.o hal_adc.o
${CC} $^ ${LDFLAGS} -o $@
spp_counter.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} main.o spp_counter.o sdp.o hal_adc.o
@ -119,13 +119,13 @@ spp_counter.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} main.o spp_coun
spp_flowcontrol.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} main.o spp_flowcontrol.o sdp.o hal_adc.o
${CC} $^ ${LDFLAGS} -o $@
gap_inquiry.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} gap_inquiry.o hal_adc.o
gap_inquiry.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${CC2560B} main.o gap_inquiry.o hal_adc.o
${CC} $^ ${LDFLAGS} -o $@
sdp_rfcomm_query.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${SDP_CLIENT} ${CC2560B} sdp_rfcomm_query.o hal_adc.o
sdp_rfcomm_query.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${SDP_CLIENT} ${CC2560B} main.o sdp_rfcomm_query.o hal_adc.o
${CC} $^ ${LDFLAGS} -o $@
sdp_general_query.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${SDP_CLIENT} ${CC2560B} sdp_general_query.o hal_adc.o
sdp_general_query.out: ${CORE_OBJ} ${COMMON_OBJ} ${SPP_OBJ} ${SDP_CLIENT} ${CC2560B} main.o sdp_general_query.o hal_adc.o
${CC} $^ ${LDFLAGS} -o $@
clean:

View File

@ -1,248 +0,0 @@
// *****************************************************************************
//
// minimal setup for HCI code
//
// *****************************************************************************
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <msp430x54x.h>
#include "bt_control_cc256x.h"
#include "hal_board.h"
#include "hal_compat.h"
#include "hal_usb.h"
#include <btstack/hci_cmds.h>
#include <btstack/run_loop.h>
#include "hci.h"
#include "btstack_memory.h"
#include "remote_device_db.h"
#include "btstack-config.h"
#define MAX_DEVICES 10
enum DEVICE_STATE { REMOTE_NAME_REQUEST, REMOTE_NAME_INQUIRED, REMOTE_NAME_FETCHED };
struct device {
bd_addr_t address;
uint16_t clockOffset;
uint32_t classOfDevice;
uint8_t pageScanRepetitionMode;
uint8_t rssi;
enum DEVICE_STATE state;
};
#define INQUIRY_INTERVAL 5
struct device devices[MAX_DEVICES];
int deviceCount = 0;
enum STATE {INIT, W4_INQUIRY_MODE_COMPLETE, ACTIVE} ;
enum STATE state = INIT;
int getDeviceIndexForAddress( bd_addr_t addr){
int j;
for (j=0; j< deviceCount; j++){
if (BD_ADDR_CMP(addr, devices[j].address) == 0){
return j;
}
}
return -1;
}
void start_scan(void){
printf("Starting inquiry scan..\n");
hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, INQUIRY_INTERVAL, 0);
}
int has_more_remote_name_requests(void){
int i;
for (i=0;i<deviceCount;i++) {
if (devices[i].state == REMOTE_NAME_REQUEST) return 1;
}
return 0;
}
void do_next_remote_name_request(void){
int i;
for (i=0;i<deviceCount;i++) {
// remote name request
if (devices[i].state == REMOTE_NAME_REQUEST){
devices[i].state = REMOTE_NAME_INQUIRED;
printf("Get remote name of %s...\n", bd_addr_to_str(devices[i].address));
hci_send_cmd(&hci_remote_name_request, devices[i].address,
devices[i].pageScanRepetitionMode, 0, devices[i].clockOffset | 0x8000);
return;
}
}
}
static void continue_remote_names(){
if (has_more_remote_name_requests()){
do_next_remote_name_request();
return;
}
start_scan();
}
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){
bd_addr_t addr;
int i;
int index;
int numResponses;
// printf("packet_handler: pt: 0x%02x, packet[0]: 0x%02x\n", packet_type, packet[0]);
if (packet_type != HCI_EVENT_PACKET) return;
uint8_t event = packet[0];
switch(state){
case INIT:
if (packet[2] == HCI_STATE_WORKING) {
hci_send_cmd(&hci_write_inquiry_mode, 0x01); // with RSSI
state = W4_INQUIRY_MODE_COMPLETE;
}
break;
case W4_INQUIRY_MODE_COMPLETE:
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_inquiry_mode) ) {
start_scan();
state = ACTIVE;
}
break;
case ACTIVE:
switch(event){
case HCI_EVENT_INQUIRY_RESULT:
case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI:{
numResponses = packet[2];
int offset = 3;
for (i=0; i<numResponses && deviceCount < MAX_DEVICES;i++){
bt_flip_addr(addr, &packet[offset]);
offset += 6;
index = getDeviceIndexForAddress(addr);
if (index >= 0) continue; // already in our list
memcpy(devices[deviceCount].address, addr, 6);
devices[deviceCount].pageScanRepetitionMode = packet[offset];
offset += 1;
if (event == HCI_EVENT_INQUIRY_RESULT){
offset += 2; // Reserved + Reserved
devices[deviceCount].classOfDevice = READ_BT_24(packet, offset);
offset += 3;
devices[deviceCount].clockOffset = READ_BT_16(packet, offset) & 0x7fff;
offset += 2;
devices[deviceCount].rssi = 0;
} else {
offset += 1; // Reserved
devices[deviceCount].classOfDevice = READ_BT_24(packet, offset);
offset += 3;
devices[deviceCount].clockOffset = READ_BT_16(packet, offset) & 0x7fff;
offset += 2;
devices[deviceCount].rssi = packet[offset];
offset += 1;
}
devices[deviceCount].state = REMOTE_NAME_REQUEST;
printf("Device found: %s with COD: 0x%06x, pageScan %d, clock offset 0x%04x, rssi 0x%02x\n", bd_addr_to_str(addr),
devices[deviceCount].classOfDevice, devices[deviceCount].pageScanRepetitionMode,
devices[deviceCount].clockOffset, devices[deviceCount].rssi);
deviceCount++;
}
break;
}
case HCI_EVENT_INQUIRY_COMPLETE:
for (i=0;i<deviceCount;i++) {
// retry remote name request
if (devices[i].state == REMOTE_NAME_INQUIRED)
devices[i].state = REMOTE_NAME_REQUEST;
}
continue_remote_names();
break;
case BTSTACK_EVENT_REMOTE_NAME_CACHED:
bt_flip_addr(addr, &packet[3]);
printf("Cached remote name for %s: '%s'\n", bd_addr_to_str(addr), &packet[9]);
break;
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
bt_flip_addr(addr, &packet[3]);
index = getDeviceIndexForAddress(addr);
if (index >= 0) {
if (packet[2] == 0) {
printf("Name: '%s'\n", &packet[9]);
devices[index].state = REMOTE_NAME_FETCHED;
} else {
printf("Failed to get name: page timeout\n");
}
}
continue_remote_names();
break;
default:
break;
}
break;
default:
break;
}
}
static void hw_setup(void){
// stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
//Initialize clock and peripherals
halBoardInit();
halBoardStartXT1();
halBoardSetSystemClock(SYSCLK_16MHZ);
// init debug UART
halUsbInit();
// init LEDs
LED_PORT_OUT |= LED_1 | LED_2;
LED_PORT_DIR |= LED_1 | LED_2;
// ready - enable irq used in h4 task
__enable_interrupt();
}
static void btstack_setup(void){
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
// init HCI
hci_transport_t * transport = hci_transport_h4_dma_instance();
bt_control_t * control = bt_control_cc256x_instance();
hci_uart_config_t * config = hci_uart_config_cc256x_instance();
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
hci_init(transport, config, control, remote_db);
hci_register_packet_handler(packet_handler);
}
// main == setup
int btstack_main(void)
{
hw_setup();
btstack_setup();
// turn on!
hci_power_control(HCI_POWER_ON);
// go!
run_loop_execute();
// happy compiler!
return 0;
}

View File

@ -1,151 +0,0 @@
// *****************************************************************************
//
// minimal setup for SDP client over USB or UART
//
// *****************************************************************************
#include "btstack-config.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <msp430x54x.h>
#include "sdp_parser.h"
#include "sdp_client.h"
#include "sdp_query_util.h"
#include "bt_control_cc256x.h"
#include "hal_adc.h"
#include "hal_board.h"
#include "hal_compat.h"
#include "hal_lcd.h"
#include "hal_usb.h"
#include <btstack/hci_cmds.h>
#include <btstack/run_loop.h>
#include "hci.h"
#include "btstack_memory.h"
#include "hci_dump.h"
#include "l2cap.h"
static bd_addr_t remote = {0x04,0x0C,0xCE,0xE4,0x85,0xD3};
static const uint8_t des_attributeIDList[] = {0x35, 0x05, 0x0A, 0x00, 0x01, 0xff, 0xff}; // Arribute: 0x0001 - 0xffff
static const uint8_t des_serviceSearchPattern[] = {0x35, 0x03, 0x19, 0x00, 0x00};
uint16_t attribute_id = -1;
uint16_t record_id = -1;
int attribute_value_buffer_size = 1000;
uint8_t attribute_value[1000];
static void handle_general_sdp_parser_event(sdp_query_event_t * event);
static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
uint8_t event = packet[0];
switch (event) {
case BTSTACK_EVENT_STATE:
// bt stack activated, get started
if (packet[2] == HCI_STATE_WORKING){
sdp_general_query_for_uuid(remote, 0x1002);
}
break;
default:
break;
}
}
static void assertBuffer(int size){
if (size > attribute_value_buffer_size){
printf("Buffer size exceeded: available %d, required %d", attribute_value_buffer_size, size);
}
}
static void handle_general_sdp_parser_event(sdp_query_event_t * event){
sdp_query_attribute_value_event_t * ve;
sdp_query_complete_event_t * ce;
switch (event->type){
case SDP_QUERY_ATTRIBUTE_VALUE:
ve = (sdp_query_attribute_value_event_t*) event;
// handle new record
if (ve->record_id != record_id){
record_id = ve->record_id;
printf("\n---\nRecord nr. %u\n", record_id);
}
assertBuffer(ve->attribute_length);
attribute_value[ve->data_offset] = ve->data;
if ((uint16_t)(ve->data_offset+1) == ve->attribute_length){
printf("Attribute 0x%04x: ", ve->attribute_id);
de_dump_data_element(attribute_value);
}
break;
case SDP_QUERY_COMPLETE:
ce = (sdp_query_complete_event_t*) event;
printf("General query done with status %d.\n\n", ce->status);
break;
}
}
static void hw_setup(){
// stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
//Initialize clock and peripherals
halBoardInit();
halBoardStartXT1();
halBoardSetSystemClock(SYSCLK_16MHZ);
// init debug UART
halUsbInit();
// init LEDs
LED_PORT_OUT |= LED_1 | LED_2;
LED_PORT_DIR |= LED_1 | LED_2;
// ready - enable irq used in h4 task
__enable_interrupt();
}
static void btstack_setup(){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
// init HCI
hci_transport_t * transport = hci_transport_h4_dma_instance();
bt_control_t * control = bt_control_cc256x_instance();
hci_uart_config_t * config = hci_uart_config_cc256x_instance();
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
hci_init(transport, config, control, remote_db);
// use eHCILL
bt_control_cc256x_enable_ehcill(1);
// init L2CAP
l2cap_init();
l2cap_register_packet_handler(packet_handler);
}
int main(void){
sdp_parser_init();
sdp_parser_register_callback(handle_general_sdp_parser_event);
hw_setup();
btstack_setup();
// turn on!
hci_power_control(HCI_POWER_ON);
// go!
run_loop_execute();
return 0;
}

View File

@ -1,148 +0,0 @@
// *****************************************************************************
//
// minimal setup for SDP client over USB or UART
//
// *****************************************************************************
#include "btstack-config.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <msp430x54x.h>
#include "sdp_query_rfcomm.h"
#include "bt_control_cc256x.h"
#include "hal_adc.h"
#include "hal_board.h"
#include "hal_compat.h"
#include "hal_lcd.h"
#include "hal_usb.h"
#include <btstack/hci_cmds.h>
#include <btstack/run_loop.h>
#include "hci.h"
#include "btstack_memory.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "bt_control_cc256x.h"
static bd_addr_t remote = {0x04,0x0C,0xCE,0xE4,0x85,0xD3};
static uint8_t service_index = 0;
static uint8_t channel_nr[10];
static char* service_name[10];
static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
uint8_t event = packet[0];
switch (event) {
case BTSTACK_EVENT_STATE:
// bt stack activated, get started
if (packet[2] == HCI_STATE_WORKING){
sdp_query_rfcomm_channel_and_name_for_uuid(remote, 0x1002);
}
break;
default:
break;
}
}
void store_found_service(uint8_t * name, uint8_t port){
printf("APP: Service name: '%s', RFCOMM port %u\n", name, port);
channel_nr[service_index] = port;
service_name[service_index] = (char*) malloc(SDP_SERVICE_NAME_LEN+1);
strncpy(service_name[service_index], (char*) name, SDP_SERVICE_NAME_LEN);
service_name[service_index][SDP_SERVICE_NAME_LEN] = 0;
service_index++;
}
void report_found_services(){
printf("\n *** Client query response done. ");
if (service_index == 0){
printf("No service found.\n\n");
} else {
printf("Found following %d services:\n", service_index);
}
int i;
for (i=0; i<service_index; i++){
printf(" Service name %s, RFCOMM port %u\n", service_name[i], channel_nr[i]);
}
printf(" ***\n\n");
}
void handle_query_rfcomm_event(sdp_query_event_t * event, void * context){
sdp_query_rfcomm_service_event_t * ve;
switch (event->type){
case SDP_QUERY_RFCOMM_SERVICE:
ve = (sdp_query_rfcomm_service_event_t*) event;
store_found_service(ve->service_name, ve->channel_nr);
break;
case SDP_QUERY_COMPLETE:
report_found_services();
break;
}
}
static void hw_setup(){
// stop watchdog timer
WDTCTL = WDTPW + WDTHOLD;
//Initialize clock and peripherals
halBoardInit();
halBoardStartXT1();
halBoardSetSystemClock(SYSCLK_16MHZ);
// init debug UART
halUsbInit();
// init LEDs
LED_PORT_OUT |= LED_1 | LED_2;
LED_PORT_DIR |= LED_1 | LED_2;
// ready - enable irq used in h4 task
__enable_interrupt();
}
static void btstack_setup(){
/// GET STARTED with BTstack ///
btstack_memory_init();
run_loop_init(RUN_LOOP_EMBEDDED);
// init HCI
hci_transport_t * transport = hci_transport_h4_dma_instance();
bt_control_t * control = bt_control_cc256x_instance();
hci_uart_config_t * config = hci_uart_config_cc256x_instance();
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
hci_init(transport, config, control, remote_db);
// use eHCILL
bt_control_cc256x_enable_ehcill(1);
// init L2CAP
l2cap_init();
l2cap_register_packet_handler(packet_handler);
}
int main(void){
sdp_query_rfcomm_register_callback(handle_query_rfcomm_event, NULL);
hw_setup();
btstack_setup();
printf("Run...\n\r");
// turn on!
hci_power_control(HCI_POWER_ON);
// go!
run_loop_execute();
return 0;
}