OSDN Git Service

android/hal-gatt: Use fixed size buffer when passing AD to Java
authorSzymon Janc <szymon.janc@tieto.com>
Wed, 2 Apr 2014 14:12:56 +0000 (16:12 +0200)
committerSzymon Janc <szymon.janc@tieto.com>
Wed, 2 Apr 2014 14:31:09 +0000 (16:31 +0200)
HAL callback is missing length parameter and JNI code always copies
62 bytes from data.

android/hal-gatt.c

index d7b3d9a..5e7443c 100644 (file)
@@ -75,15 +75,20 @@ static void handle_register_client(void *buf, uint16_t len)
 static void handle_scan_result(void *buf, uint16_t len)
 {
        struct hal_ev_gatt_client_scan_result *ev = buf;
+       uint8_t ad[62];
 
        if (len != sizeof(*ev) + ev->len ) {
                error("gatt: invalid scan result event, aborting");
                exit(EXIT_FAILURE);
        }
 
+       /* Java assumes that passed data has 62 bytes */
+       memset(ad, 0, sizeof(ad));
+       memcpy(ad, ev->adv_data, ev->len > sizeof(ad) ? sizeof(ad) : ev->len);
+
        if (cbs->client->scan_result_cb)
                cbs->client->scan_result_cb((bt_bdaddr_t *) ev->bda, ev->rssi,
-                                                               ev->adv_data);
+                                                                       ad);
 }
 
 static void handle_connect(void *buf, uint16_t len)