int btstack_main(int argc, const char * argv[]){ int arg = 1; cmdline_addr_found = 0; while (arg < argc) { if(!strcmp(argv[arg], "-a") || !strcmp(argv[arg], "--address")){ arg++; cmdline_addr_found = sscan_bd_addr((uint8_t *)argv[arg], cmdline_addr); arg++; continue; } usage(argv[0]); return 0; } l2cap_init(); l2cap_register_packet_handler(&handle_hci_event); gatt_client_init(); gc_id = gatt_client_register_packet_handler(&handle_gatt_client_event); sm_init(); sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int btstack_main(void){ // init L2CAP l2cap_init(); l2cap_register_packet_handler(packet_handler); // init RFCOMM rfcomm_init(); rfcomm_register_packet_handler(packet_handler); rfcomm_register_service_internal(NULL, rfcomm_channel_nr, 100); // reserved channel, mtu=100 // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, 1, "SPP Counter"); printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); sdp_register_service_internal(NULL, service_record_item); // set one-shot timer heartbeat.process = &timer_handler; run_loop_register_timer(&heartbeat, HEARTBEAT_PERIOD_MS); printf("Run...\n\r"); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int main(int argc, const char * argv[]) { int arg = 1; cmdline_addr_found = 0; while (arg < argc) { if(!strcmp(argv[arg], "-a") || !strcmp(argv[arg], "--address")){ arg++; cmdline_addr_found = sscan_bd_addr((uint8_t *)argv[arg], cmdline_addr); arg++; continue; } usage(argv[0]); return 0; } setup(); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int main (int argc, const char * argv[]){ // handle remote addr if (argc > 1){ if (sscan_bd_addr((uint8_t *)argv[1], addr)){ serverMode = 0; prepare_packet(); } } run_loop_init(RUN_LOOP_POSIX); int err = bt_open(); if (err) { printf("Failed to open connection to BTdaemon\n"); return err; } bt_register_packet_handler(packet_handler); bt_send_cmd(&l2cap_register_service, PSM_TEST, PACKET_SIZE); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON ); // banner printf("L2CAP Throughput Test (compatible with Apple's Bluetooth Explorer)\n"); if (serverMode) { printf(" * Running in Server mode. For client mode, specify remote addr 11:22:33:44:55:66\n"); } printf(" * MTU: 1000 bytes\n"); run_loop_execute(); bt_close(); return 0; }
int main(int argc, const char * argv[]){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // pick serial port hci_uart_config_cc256x.device_name = "/dev/tty.usbserial-AD025KU2"; // init HCI hci_transport_t * transport = hci_transport_h4_instance(); bt_control_t * control = bt_control_stlc2500d_instance(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; hci_init(transport, (void*) &hci_uart_config_cc256x, control, remote_db); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app btstack_main(argc, argv); // go run_loop_execute(); return 0; }
int main(int argc, const char * argv[]){ /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); hci_uart_config_t * config = NULL; bt_control_t * control = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs; hci_init(transport, config, control, remote_db); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app btstack_main(argc, argv); // go run_loop_execute(); return 0; }
int main(void) { printf("BTstack LE Peripheral starting up...\n"); setup(); setup_cli(); gap_random_address_set_update_period(300000); gap_random_address_set_mode(GAP_RANDOM_ADDRESS_RESOLVABLE); strcpy(gap_device_name, "BTstack"); sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT); sm_io_capabilities = "IO_CAPABILITY_NO_INPUT_NO_OUTPUT"; sm_set_authentication_requirements(0); sm_register_oob_data_callback(get_oob_data_callback); sm_set_encryption_key_size_range(sm_min_key_size, 16); sm_test_set_irk(test_irk); // set one-shot timer heartbeat.process = &heartbeat_handler; run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); run_loop_add_timer(&heartbeat); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
// main int main(void) { /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); // init HCI hci_transport_t * transport = hci_transport_usb_instance(); bt_control_t * control = NULL; hci_uart_config_t * config = NULL; remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, config, control, remote_db); // set up l2cap_le l2cap_init(); l2cap_register_fixed_channel(att_packet_handler, L2CAP_CID_ATTRIBUTE_PROTOCOL); l2cap_register_packet_handler(packet_handler); // set up ATT att_set_db(profile_data); att_set_write_callback(att_write_callback); att_dump_attributes(); att_connection.mtu = 27; printf("Run...\n\r"); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int main (int argc, const char * argv[]){ // parse addr of Bob uint8_t ok = 0; if (argc >= 2) { ok = sscan_bd_addr((uint8_t *) argv[1], bob_addr); } if (!ok) { printf("Usage: mitm 12:34:56:78:9A:BC\n"); exit(0); } // start stack run_loop_init(RUN_LOOP_POSIX); int err = bt_open(); if (err) { printf("Failed to open connection to BTdaemon\n"); return err; } printf("BTstack-in-the-Middle started, will pretend to be BOB ("); print_bd_addr(bob_addr); printf(")\n"); bt_register_packet_handler(packet_handler); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON ); run_loop_execute(); bt_close(); }
void bluetooth_task(intptr_t unused) { #if defined(DEBUG) syslog(LOG_DEBUG, "[bluetooth] Start main task."); #endif run_loop_init(RUN_LOOP_EMBEDDED); // Initialize HCI bt_control_t *control = bt_control_cc256x_instance(); hci_transport_t *transport = hci_transport_h4_dma_instance(); hci_uart_config_t *config = hci_uart_config_cc256x_instance(); const remote_device_db_t *db = &remote_device_db_memory; hci_init(transport, config, control, db); // Initialize SPP (Serial Port Profile) bluetooth_spp_initialize(); // Power on bt_control_cc256x_enable_ehcill(false); hci_power_control(HCI_POWER_ON); run_loop_execute(); #if 0 // Code for debugging while(1) { // bluetooth_uart_isr(); embedded_execute_once(); // if(rx_size > 0 && (UART2.IIR_FCR & 0x4)) // TODO: dirty hack // AINTC.SISR = UART2_INT; tslp_tsk(1); // TODO: Use interrupt instead of sleeping. -- ertl-liyixiao } #endif }
int main(void) { clock_setup(); gpio_setup(); hal_tick_init(); debug_usart_setup(); bluetooth_setup(); // start with BTstack init - especially configure HCI Transport 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(); remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory; hci_init(transport, (void*) &hci_uart_config_cc256x, control, remote_db); // enable eHCILL bt_control_cc256x_enable_ehcill(1); // hand over to btstack embedded code btstack_main(); // go run_loop_execute(); return 0; }
int main(void){ sdp_query_rfcomm_register_callback(handle_query_rfcomm_event, NULL); btstack_setup(); // go! run_loop_execute(); return 0; }
int main (int argc, const char * argv[]){ run_loop_init(RUN_LOOP_POSIX); int err = bt_open(); if (err) { printf("Failed to open connection to BTdaemon\n"); return err; } bt_register_packet_handler(packet_handler); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON ); run_loop_execute(); bt_close(); }
int btstack_main(int argc, const char * argv[]) { hci_register_packet_handler(packet_handler); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
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; }
// main == setup int main(void) { setup(); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int main(void){ // stop watchdog timer WDTCTL = WDTPW + WDTHOLD; //Initialize clock and peripherals halBoardInit(); halBoardStartXT1(); halBoardSetSystemClock(SYSCLK_16MHZ); // Debug UART halUsbInit(); // show off doLCD(); // init LEDs LED_PORT_OUT |= LED_1 | LED_2; LED_PORT_DIR |= LED_1 | LED_2; /// GET STARTED /// 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); // ready - enable irq used in h4 task __enable_interrupt(); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); return 0; }
int btstack_main(int argc, const char * argv[]){ l2cap_init(); ble_client_init(); ble_client_register_gatt_client_event_packet_handler(handle_gatt_client_event); ble_client_register_hci_packet_handler(handle_hci_event); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int btstack_main(int argc, const char * argv[]){ hci_set_class_of_device(0x200404); hci_discoverable_control(1); l2cap_init(); l2cap_register_packet_handler(&packet_handler2); l2cap_register_service_internal(NULL, packet_handler, PSM_SDP, 100, LEVEL_0); // turn on! hci_power_control(HCI_POWER_ON); btstack_stdin_setup(stdin_process); run_loop_execute(); return 0; }
int btstack_main(int argc, const char * argv[]){ printf("Client HCI init done\r\n"); // init L2CAP l2cap_init(); l2cap_register_packet_handler(packet_handler); sdp_query_rfcomm_register_callback(handle_query_rfcomm_event, NULL); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); return 0; }
int main (int argc, const char * argv[]){ // start stack run_loop_init(RUN_LOOP_POSIX); int err = bt_open(); if (err) { printf("Failed to open connection to BTdaemon\n"); return err; } // init table int i; for (i=0;i<MAX_DEVICES;i++) devices[i].state = 0; bt_register_packet_handler(packet_handler); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON ); run_loop_execute(); bt_close(); return 0; }
int main (int argc, const char * argv[]){ create_test_data(); run_loop_init(RUN_LOOP_POSIX); int err = bt_open(); if (err) { //fpritf(stderr,"Failed to open connection to BTdaemon, err %d\n",err); return 1; } bt_register_packet_handler(packet_handler); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON ); run_loop_execute(); bt_close(); return 0; }
// main == setup int main(void) { setup(); // set one-shot timer timer_source_t heartbeat; heartbeat.process = &heartbeat_handler; run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); run_loop_add_timer(&heartbeat); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int btstack_main(int argc, const char * argv[]){ hci_discoverable_control(1); l2cap_init(); l2cap_register_packet_handler(packet_handler); rfcomm_init(); rfcomm_register_packet_handler(packet_handler); rfcomm_register_service_internal(NULL, RFCOMM_SERVER_CHANNEL, 0xffff); // reserved channel, mtu limited by l2cap // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); #ifdef EMBEDDED service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, RFCOMM_SERVER_CHANNEL, "SPP Counter"); printf("SDP service buffer size: %u\n", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); sdp_register_service_internal(NULL, service_record_item); #else sdp_create_spp_service( spp_service_buffer, RFCOMM_SERVER_CHANNEL, "SPP Counter"); printf("SDP service record size: %u\n", de_get_len(spp_service_buffer)); sdp_register_service_internal(NULL, spp_service_buffer); #endif hci_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO); // set one-shot timer timer_source_t heartbeat; heartbeat.process = &heartbeat_handler; run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); run_loop_add_timer(&heartbeat); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int main (int argc, const char * argv[]){ printf("le_scan started\n"); printf("- connecting to BTstack Daemon\n"); // start stack run_loop_init(RUN_LOOP_POSIX); int err = bt_open(); if (err) { printf("-> Failed to open connection to BTstack Daemon\n"); return err; } printf("- connected\n"); printf("- send power on\n"); bt_register_packet_handler(packet_handler); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON ); run_loop_execute(); bt_close(); return 0; }
void btstack_libusb_device_base::init() { /// GET STARTED with BTstack /// btstack_memory_init(); run_loop_init(RUN_LOOP_POSIX); hci_dump_open( nullptr, HCI_DUMP_STDOUT ); // init HCI hci_init( hci_transport_usb_instance(), nullptr, nullptr, nullptr ); // handle CTRL-c signal(SIGINT, sigint_handler); // setup app hci_register_packet_handler( &btstack_libusb_device_base::btstack_packet_handler ); hci_connectable_control(0); // no services yet // turn on! hci_power_control(HCI_POWER_ON); // go run_loop_execute(); }
int main (int argc, char * const * argv){ static int tcp_flag = 0; while (1) { static struct option long_options[] = { { "tcp", no_argument, &tcp_flag, 1 }, { "help", no_argument, 0, 0 }, { 0,0,0,0 } // This is a filler for -1 }; int c; int option_index = -1; c = getopt_long(argc, argv, "h", long_options, &option_index); if (c == -1) break; // no more option // treat long parameter first if (option_index == -1) { switch (c) { case '?': case 'h': usage(argv[0]); return 0; break; } } else { switch (option_index) { case 1: usage(argv[0]); return 0; break; } } } // make stdout unbuffered setbuf(stdout, NULL); log_error("BTdaemon started\n"); // handle CTRL-c signal(SIGINT, daemon_sigint_handler); // handle SIGTERM - suggested for launchd signal(SIGTERM, daemon_sigint_handler); // handle SIGPIPE struct sigaction act; act.sa_handler = SIG_IGN; sigemptyset (&act.sa_mask); act.sa_flags = 0; sigaction (SIGPIPE, &act, NULL); bt_control_t * control = NULL; #ifdef HAVE_TRANSPORT_H4 config.device_name = UART_DEVICE; config.baudrate_init = UART_SPEED; config.baudrate_main = 0; config.flowcontrol = 1; #if defined(USE_BLUETOOL) && defined(USE_POWERMANAGEMENT) if (bt_control_iphone_power_management_supported()){ // use default (max) UART baudrate over netraph interface config.baudrate_init = 0; transport = hci_transport_h4_iphone_instance(); } else { transport = hci_transport_h4_instance(); } #else transport = hci_transport_h4_instance(); #endif #endif #ifdef HAVE_TRANSPORT_USB transport = hci_transport_usb_instance(); #endif #ifdef USE_BLUETOOL control = &bt_control_iphone; #endif #if defined(USE_BLUETOOL) && defined(USE_POWERMANAGEMENT) if (bt_control_iphone_power_management_supported()){ hci_transport_h4_iphone_set_enforce_wake_device("/dev/btwake"); } #endif #ifdef USE_SPRINGBOARD bluetooth_status_handler = platform_iphone_status_handler; platform_iphone_register_window_manager_restart(update_ui_status); platform_iphone_register_preferences_changed(preferences_changed_callback); #endif #ifdef REMOTE_DEVICE_DB remote_device_db = &REMOTE_DEVICE_DB; #endif run_loop_init(RUN_LOOP_POSIX); // init power management notifications if (control && control->register_for_power_notifications){ control->register_for_power_notifications(power_notification_callback); } // logging loggingEnabled = 0; int newLoggingEnabled = 1; #ifdef USE_BLUETOOL // iPhone has toggle in Preferences.app newLoggingEnabled = platform_iphone_logging_enabled(); #endif daemon_set_logging_enabled(newLoggingEnabled); // init HCI hci_init(transport, &config, control, remote_device_db); #ifdef USE_BLUETOOL // iPhone doesn't use SSP yet as there's no UI for it yet and auto accept is not an option hci_ssp_set_enable(0); #endif // init L2CAP l2cap_init(); l2cap_register_packet_handler(daemon_packet_handler); timeout.process = daemon_no_connections_timeout; #ifdef HAVE_RFCOMM log_info("config.h: HAVE_RFCOMM\n"); rfcomm_init(); rfcomm_register_packet_handler(daemon_packet_handler); #endif #ifdef HAVE_SDP sdp_init(); sdp_register_packet_handler(daemon_packet_handler); #endif #ifdef USE_LAUNCHD socket_connection_create_launchd(); #else // create server if (tcp_flag) { socket_connection_create_tcp(BTSTACK_PORT); } else { socket_connection_create_unix(BTSTACK_UNIX); } #endif socket_connection_register_packet_callback(daemon_client_handler); #ifdef USE_BLUETOOL // notify daemons notify_post("ch.ringwald.btstack.started"); // spawn thread to have BTstack run loop on new thread, while main thread is used to keep CFRunLoop pthread_t run_loop; pthread_create(&run_loop, NULL, &run_loop_thread, NULL); // needed to receive notifications CFRunLoopRun(); #endif // go! run_loop_execute(); return 0; }
static void * run_loop_thread(void *context){ run_loop_execute(); return NULL; }
// main int main(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; /// 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); // init RFCOMM rfcomm_init(); rfcomm_register_packet_handler(packet_handler); rfcomm_register_service_with_initial_credits_internal(NULL, rfcomm_channel_nr, 100, 1); // reserved channel, mtu=100, 1 credit // init SDP, create record for SPP and register with SDP sdp_init(); memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); service_record_item_t * service_record_item = (service_record_item_t *) spp_service_buffer; sdp_create_spp_service( (uint8_t*) &service_record_item->service_record, 1, "SPP Counter"); printf("SDP service buffer size: %u\n\r", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); sdp_register_service_internal(NULL, service_record_item); // set one-shot timer timer_source_t heartbeat; heartbeat.process = &heartbeat_handler; run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); run_loop_add_timer(&heartbeat); puts("SPP FlowControl Demo: simulates processing on received data...\n\r"); // ready - enable irq used in h4 task __enable_interrupt(); // turn on! hci_power_control(HCI_POWER_ON); // go! run_loop_execute(); // happy compiler! return 0; }
int main(void){ btstack_setup(); setup_cli(); run_loop_execute(); return 0; }