hci.c (124062bc8d22b8c088b66a6a98854012b4525569) hci.c (a3b02b7188908b1a71b8df1fd01a63b7a3345906)
1/*
2 * Copyright (C) 2009 by Matthias Ringwald
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 32 unchanged lines hidden (view full) ---

41#include <stdarg.h>
42#include <string.h>
43#include <stdio.h>
44
45#ifndef EMBEDDED
46#include <unistd.h> // gethostbyname
47#endif
48
1/*
2 * Copyright (C) 2009 by Matthias Ringwald
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 32 unchanged lines hidden (view full) ---

41#include <stdarg.h>
42#include <string.h>
43#include <stdio.h>
44
45#ifndef EMBEDDED
46#include <unistd.h> // gethostbyname
47#endif
48
49#include "btstack_memory.h"
49#include "debug.h"
50#include "hci_dump.h"
51
52#include <btstack/hci_cmds.h>
53#include <btstack/version.h>
54
50#include "debug.h"
51#include "hci_dump.h"
52
53#include <btstack/hci_cmds.h>
54#include <btstack/version.h>
55
55// temp
56// tmpe
56#include "l2cap.h"
57
58#define HCI_CONNECTION_TIMEOUT_MS 10000
59
60// the STACK is here
61static hci_stack_t hci_stack;
62
63/**

--- 35 unchanged lines hidden (view full) ---

99}
100
101/**
102 * create connection for given address
103 *
104 * @return connection OR NULL, if not found
105 */
106static hci_connection_t * create_connection_for_addr(bd_addr_t addr){
57#include "l2cap.h"
58
59#define HCI_CONNECTION_TIMEOUT_MS 10000
60
61// the STACK is here
62static hci_stack_t hci_stack;
63
64/**

--- 35 unchanged lines hidden (view full) ---

100}
101
102/**
103 * create connection for given address
104 *
105 * @return connection OR NULL, if not found
106 */
107static hci_connection_t * create_connection_for_addr(bd_addr_t addr){
107 hci_connection_t * conn = malloc( sizeof(hci_connection_t) );
108 hci_connection_t * conn = btstack_memory_hci_connection_get();
108 if (!conn) return NULL;
109 BD_ADDR_COPY(conn->address, addr);
110 conn->con_handle = 0xffff;
111 conn->authentication_flags = AUTH_FLAGS_NONE;
112#ifdef HAVE_TIME
113 linked_item_set_user(&conn->timeout.item, conn);
114 conn->timeout.process = hci_connection_timeout_handler;
115 hci_connection_timestamp(conn);

--- 222 unchanged lines hidden (view full) ---

338
339 // cancel all l2cap connections
340 hci_emit_disconnection_complete(conn->con_handle, 0x16); // terminated by local host
341
342#ifdef HAVE_TIME
343 run_loop_remove_timer(&conn->timeout);
344#endif
345 linked_list_remove(&hci_stack.connections, (linked_item_t *) conn);
109 if (!conn) return NULL;
110 BD_ADDR_COPY(conn->address, addr);
111 conn->con_handle = 0xffff;
112 conn->authentication_flags = AUTH_FLAGS_NONE;
113#ifdef HAVE_TIME
114 linked_item_set_user(&conn->timeout.item, conn);
115 conn->timeout.process = hci_connection_timeout_handler;
116 hci_connection_timestamp(conn);

--- 222 unchanged lines hidden (view full) ---

339
340 // cancel all l2cap connections
341 hci_emit_disconnection_complete(conn->con_handle, 0x16); // terminated by local host
342
343#ifdef HAVE_TIME
344 run_loop_remove_timer(&conn->timeout);
345#endif
346 linked_list_remove(&hci_stack.connections, (linked_item_t *) conn);
346 free( conn );
347 btstack_memory_hci_connection_free( conn );
347
348 // now it's gone
349 hci_emit_nr_connections_changed();
350}
351
352// avoid huge local variables
353static device_name_t device_name;
354static void event_handler(uint8_t *packet, int size){

--- 83 unchanged lines hidden (view full) ---

438 log_info("New connection: handle %u, ", conn->con_handle);
439 print_bd_addr( conn->address );
440 log_info("\n");
441
442 hci_emit_nr_connections_changed();
443 } else {
444 // connection failed, remove entry
445 linked_list_remove(&hci_stack.connections, (linked_item_t *) conn);
348
349 // now it's gone
350 hci_emit_nr_connections_changed();
351}
352
353// avoid huge local variables
354static device_name_t device_name;
355static void event_handler(uint8_t *packet, int size){

--- 83 unchanged lines hidden (view full) ---

439 log_info("New connection: handle %u, ", conn->con_handle);
440 print_bd_addr( conn->address );
441 log_info("\n");
442
443 hci_emit_nr_connections_changed();
444 } else {
445 // connection failed, remove entry
446 linked_list_remove(&hci_stack.connections, (linked_item_t *) conn);
446 free( conn );
447 btstack_memory_hci_connection_free( conn );
447
448 // if authentication error, also delete link key
449 if (packet[2] == 0x05) {
450 hci_drop_link_key_for_bd_addr(&addr);
451 }
452 }
453 }
454 break;

--- 739 unchanged lines hidden ---
448
449 // if authentication error, also delete link key
450 if (packet[2] == 0x05) {
451 hci_drop_link_key_for_bd_addr(&addr);
452 }
453 }
454 }
455 break;

--- 739 unchanged lines hidden ---