├── AndroidManifest.xml ├── README.md ├── build.xml ├── gen ├── R.java.d └── com │ └── microsuncn │ └── hcidump │ ├── BuildConfig.java │ └── R.java ├── jni ├── Android.mk ├── config.h ├── lib │ ├── .deps │ │ ├── bluetooth.Po │ │ └── hci.Po │ ├── bluetooth.c │ ├── bluetooth.h │ ├── hci.c │ ├── hci.h │ ├── hci_lib.h │ └── l2cap.h ├── parser │ ├── .deps │ │ ├── att.Po │ │ ├── avctp.Po │ │ ├── avdtp.Po │ │ ├── avrcp.Po │ │ ├── bnep.Po │ │ ├── bpa.Po │ │ ├── capi.Po │ │ ├── cmtp.Po │ │ ├── csr.Po │ │ ├── ericsson.Po │ │ ├── hci.Po │ │ ├── hcrp.Po │ │ ├── hidp.Po │ │ ├── l2cap.Po │ │ ├── lmp.Po │ │ ├── obex.Po │ │ ├── parser.Po │ │ ├── ppp.Po │ │ ├── rfcomm.Po │ │ ├── sdp.Po │ │ ├── smp.Po │ │ └── tcpip.Po │ ├── att.c │ ├── avctp.c │ ├── avdtp.c │ ├── avrcp.c │ ├── bnep.c │ ├── bpa.c │ ├── capi.c │ ├── cmtp.c │ ├── csr.c │ ├── ericsson.c │ ├── hci.c │ ├── hcrp.c │ ├── hidp.c │ ├── l2cap.c │ ├── lmp.c │ ├── obex.c │ ├── parser.c │ ├── parser.h │ ├── ppp.c │ ├── rfcomm.c │ ├── rfcomm.h │ ├── sdp.c │ ├── sdp.h │ ├── smp.c │ └── tcpip.c └── src │ ├── bpasniff.c │ ├── csrsniff.c │ └── hcidump.c ├── local.properties ├── proguard-project.txt ├── project.properties └── res └── values └── strings.xml /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | bluez hcidump 2.3 for android 2 | 3 | 1) Type ndk-build to build it. 4 | 5 | 2) Then to use "adb push" to push it to android device 6 | 7 | Enjoy! 8 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 49 | 50 | 51 | 52 | 56 | 57 | 69 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /gen/R.java.d: -------------------------------------------------------------------------------- 1 | /home/azheng/projects/android/projects/hcidump/gen/com/microsuncn/hcidump/R.java \ 2 | : /home/azheng/projects/android/projects/hcidump/res/values/strings.xml \ 3 | /home/azheng/projects/android/projects/hcidump/bin/AndroidManifest.xml \ 4 | -------------------------------------------------------------------------------- /gen/com/microsuncn/hcidump/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package com.microsuncn.hcidump; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /gen/com/microsuncn/hcidump/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package com.microsuncn.hcidump; 9 | 10 | public final class R { 11 | public static final class attr { 12 | } 13 | public static final class string { 14 | public static final int app_name=0x7f020000; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | LOCAL_PATH := $(call my-dir) 16 | 17 | include $(CLEAR_VARS) 18 | 19 | LOCAL_MODULE := hcidump 20 | 21 | LOCAL_CFLAGS += -DHAVE_CONFIG_H 22 | 23 | LOCAL_SRC_FILES:= \ 24 | src/hcidump.c \ 25 | lib/bluetooth.c \ 26 | lib/hci.c \ 27 | parser/att.c \ 28 | parser/avctp.c \ 29 | parser/avdtp.c \ 30 | parser/avrcp.c \ 31 | parser/bnep.c \ 32 | parser/bpa.c \ 33 | parser/capi.c \ 34 | parser/cmtp.c \ 35 | parser/csr.c \ 36 | parser/ericsson.c \ 37 | parser/hci.c \ 38 | parser/hcrp.c \ 39 | parser/hidp.c \ 40 | parser/l2cap.c \ 41 | parser/lmp.c \ 42 | parser/obex.c \ 43 | parser/parser.c \ 44 | parser/ppp.c \ 45 | parser/rfcomm.c \ 46 | parser/sdp.c \ 47 | parser/smp.c \ 48 | parser/tcpip.c 49 | 50 | LOCAL_CFLAGS += -fPIE 51 | LOCAL_LDFLAGS += -fPIE -pie 52 | 53 | include $(BUILD_EXECUTABLE) 54 | -------------------------------------------------------------------------------- /jni/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Name of package */ 5 | #define PACKAGE "bluez-hcidump" 6 | 7 | /* Define to the address where bug reports for this package should be sent. */ 8 | #define PACKAGE_BUGREPORT "" 9 | 10 | /* Define to the full name of this package. */ 11 | #define PACKAGE_NAME "bluez-hcidump" 12 | 13 | /* Define to the full name and version of this package. */ 14 | #define PACKAGE_STRING "bluez-hcidump 2.3" 15 | 16 | /* Define to the one symbol short name of this package. */ 17 | #define PACKAGE_TARNAME "bluez-hcidump" 18 | 19 | /* Define to the version of this package. */ 20 | #define PACKAGE_VERSION "2.3" 21 | 22 | /* Version number of package */ 23 | #define VERSION "2.3" 24 | -------------------------------------------------------------------------------- /jni/lib/.deps/bluetooth.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/lib/.deps/hci.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/lib/bluetooth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | * 24 | */ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | #include 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "bluetooth.h" 39 | #include "hci.h" 40 | 41 | void baswap(bdaddr_t *dst, const bdaddr_t *src) 42 | { 43 | register unsigned char *d = (unsigned char *) dst; 44 | register const unsigned char *s = (const unsigned char *) src; 45 | register int i; 46 | 47 | for (i = 0; i < 6; i++) 48 | d[i] = s[5-i]; 49 | } 50 | 51 | char *batostr(const bdaddr_t *ba) 52 | { 53 | char *str = bt_malloc(18); 54 | if (!str) 55 | return NULL; 56 | 57 | sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", 58 | ba->b[0], ba->b[1], ba->b[2], 59 | ba->b[3], ba->b[4], ba->b[5]); 60 | 61 | return str; 62 | } 63 | 64 | bdaddr_t *strtoba(const char *str) 65 | { 66 | bdaddr_t b; 67 | bdaddr_t *ba = bt_malloc(sizeof(*ba)); 68 | 69 | if (ba) { 70 | str2ba(str, &b); 71 | baswap(ba, &b); 72 | } 73 | 74 | return ba; 75 | } 76 | 77 | int ba2str(const bdaddr_t *ba, char *str) 78 | { 79 | return sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", 80 | ba->b[5], ba->b[4], ba->b[3], ba->b[2], ba->b[1], ba->b[0]); 81 | } 82 | 83 | int str2ba(const char *str, bdaddr_t *ba) 84 | { 85 | bdaddr_t b; 86 | int i; 87 | 88 | if (bachk(str) < 0) { 89 | memset(ba, 0, sizeof(*ba)); 90 | return -1; 91 | } 92 | 93 | for (i = 0; i < 6; i++, str += 3) 94 | b.b[i] = strtol(str, NULL, 16); 95 | 96 | baswap(ba, &b); 97 | 98 | return 0; 99 | } 100 | 101 | int ba2oui(const bdaddr_t *ba, char *str) 102 | { 103 | return sprintf(str, "%2.2X-%2.2X-%2.2X", ba->b[5], ba->b[4], ba->b[3]); 104 | } 105 | 106 | int bachk(const char *str) 107 | { 108 | if (!str) 109 | return -1; 110 | 111 | if (strlen(str) != 17) 112 | return -1; 113 | 114 | while (*str) { 115 | if (!isxdigit(*str++)) 116 | return -1; 117 | 118 | if (!isxdigit(*str++)) 119 | return -1; 120 | 121 | if (*str == 0) 122 | break; 123 | 124 | if (*str++ != ':') 125 | return -1; 126 | } 127 | 128 | return 0; 129 | } 130 | 131 | int baprintf(const char *format, ...) 132 | { 133 | va_list ap; 134 | int len; 135 | 136 | va_start(ap, format); 137 | len = vprintf(format, ap); 138 | va_end(ap); 139 | 140 | return len; 141 | } 142 | 143 | int bafprintf(FILE *stream, const char *format, ...) 144 | { 145 | va_list ap; 146 | int len; 147 | 148 | va_start(ap, format); 149 | len = vfprintf(stream, format, ap); 150 | va_end(ap); 151 | 152 | return len; 153 | } 154 | 155 | int basprintf(char *str, const char *format, ...) 156 | { 157 | va_list ap; 158 | int len; 159 | 160 | va_start(ap, format); 161 | len = vsnprintf(str, (~0U) >> 1, format, ap); 162 | va_end(ap); 163 | 164 | return len; 165 | } 166 | 167 | int basnprintf(char *str, size_t size, const char *format, ...) 168 | { 169 | va_list ap; 170 | int len; 171 | 172 | va_start(ap, format); 173 | len = vsnprintf(str, size, format, ap); 174 | va_end(ap); 175 | 176 | return len; 177 | } 178 | 179 | void *bt_malloc(size_t size) 180 | { 181 | return malloc(size); 182 | } 183 | 184 | void bt_free(void *ptr) 185 | { 186 | free(ptr); 187 | } 188 | 189 | /* Bluetooth error codes to Unix errno mapping */ 190 | int bt_error(uint16_t code) 191 | { 192 | switch (code) { 193 | case 0: 194 | return 0; 195 | case HCI_UNKNOWN_COMMAND: 196 | return EBADRQC; 197 | case HCI_NO_CONNECTION: 198 | return ENOTCONN; 199 | case HCI_HARDWARE_FAILURE: 200 | return EIO; 201 | case HCI_PAGE_TIMEOUT: 202 | return EHOSTDOWN; 203 | case HCI_AUTHENTICATION_FAILURE: 204 | return EACCES; 205 | case HCI_PIN_OR_KEY_MISSING: 206 | return EINVAL; 207 | case HCI_MEMORY_FULL: 208 | return ENOMEM; 209 | case HCI_CONNECTION_TIMEOUT: 210 | return ETIMEDOUT; 211 | case HCI_MAX_NUMBER_OF_CONNECTIONS: 212 | case HCI_MAX_NUMBER_OF_SCO_CONNECTIONS: 213 | return EMLINK; 214 | case HCI_ACL_CONNECTION_EXISTS: 215 | return EALREADY; 216 | case HCI_COMMAND_DISALLOWED: 217 | case HCI_TRANSACTION_COLLISION: 218 | case HCI_ROLE_SWITCH_PENDING: 219 | return EBUSY; 220 | case HCI_REJECTED_LIMITED_RESOURCES: 221 | case HCI_REJECTED_PERSONAL: 222 | case HCI_QOS_REJECTED: 223 | return ECONNREFUSED; 224 | case HCI_HOST_TIMEOUT: 225 | return ETIMEDOUT; 226 | case HCI_UNSUPPORTED_FEATURE: 227 | case HCI_QOS_NOT_SUPPORTED: 228 | case HCI_PAIRING_NOT_SUPPORTED: 229 | case HCI_CLASSIFICATION_NOT_SUPPORTED: 230 | case HCI_UNSUPPORTED_LMP_PARAMETER_VALUE: 231 | case HCI_PARAMETER_OUT_OF_RANGE: 232 | case HCI_QOS_UNACCEPTABLE_PARAMETER: 233 | return EOPNOTSUPP; 234 | case HCI_INVALID_PARAMETERS: 235 | case HCI_SLOT_VIOLATION: 236 | return EINVAL; 237 | case HCI_OE_USER_ENDED_CONNECTION: 238 | case HCI_OE_LOW_RESOURCES: 239 | case HCI_OE_POWER_OFF: 240 | return ECONNRESET; 241 | case HCI_CONNECTION_TERMINATED: 242 | return ECONNABORTED; 243 | case HCI_REPEATED_ATTEMPTS: 244 | return ELOOP; 245 | case HCI_REJECTED_SECURITY: 246 | case HCI_PAIRING_NOT_ALLOWED: 247 | case HCI_INSUFFICIENT_SECURITY: 248 | return EACCES; 249 | case HCI_UNSUPPORTED_REMOTE_FEATURE: 250 | return EPROTONOSUPPORT; 251 | case HCI_SCO_OFFSET_REJECTED: 252 | return ECONNREFUSED; 253 | case HCI_UNKNOWN_LMP_PDU: 254 | case HCI_INVALID_LMP_PARAMETERS: 255 | case HCI_LMP_ERROR_TRANSACTION_COLLISION: 256 | case HCI_LMP_PDU_NOT_ALLOWED: 257 | case HCI_ENCRYPTION_MODE_NOT_ACCEPTED: 258 | return EPROTO; 259 | default: 260 | return ENOSYS; 261 | } 262 | } 263 | 264 | char *bt_compidtostr(int compid) 265 | { 266 | switch (compid) { 267 | case 0: 268 | return "Ericsson Technology Licensing"; 269 | case 1: 270 | return "Nokia Mobile Phones"; 271 | case 2: 272 | return "Intel Corp."; 273 | case 3: 274 | return "IBM Corp."; 275 | case 4: 276 | return "Toshiba Corp."; 277 | case 5: 278 | return "3Com"; 279 | case 6: 280 | return "Microsoft"; 281 | case 7: 282 | return "Lucent"; 283 | case 8: 284 | return "Motorola"; 285 | case 9: 286 | return "Infineon Technologies AG"; 287 | case 10: 288 | return "Cambridge Silicon Radio"; 289 | case 11: 290 | return "Silicon Wave"; 291 | case 12: 292 | return "Digianswer A/S"; 293 | case 13: 294 | return "Texas Instruments Inc."; 295 | case 14: 296 | return "Parthus Technologies Inc."; 297 | case 15: 298 | return "Broadcom Corporation"; 299 | case 16: 300 | return "Mitel Semiconductor"; 301 | case 17: 302 | return "Widcomm, Inc."; 303 | case 18: 304 | return "Zeevo, Inc."; 305 | case 19: 306 | return "Atmel Corporation"; 307 | case 20: 308 | return "Mitsubishi Electric Corporation"; 309 | case 21: 310 | return "RTX Telecom A/S"; 311 | case 22: 312 | return "KC Technology Inc."; 313 | case 23: 314 | return "Newlogic"; 315 | case 24: 316 | return "Transilica, Inc."; 317 | case 25: 318 | return "Rohde & Schwartz GmbH & Co. KG"; 319 | case 26: 320 | return "TTPCom Limited"; 321 | case 27: 322 | return "Signia Technologies, Inc."; 323 | case 28: 324 | return "Conexant Systems Inc."; 325 | case 29: 326 | return "Qualcomm"; 327 | case 30: 328 | return "Inventel"; 329 | case 31: 330 | return "AVM Berlin"; 331 | case 32: 332 | return "BandSpeed, Inc."; 333 | case 33: 334 | return "Mansella Ltd"; 335 | case 34: 336 | return "NEC Corporation"; 337 | case 35: 338 | return "WavePlus Technology Co., Ltd."; 339 | case 36: 340 | return "Alcatel"; 341 | case 37: 342 | return "Philips Semiconductors"; 343 | case 38: 344 | return "C Technologies"; 345 | case 39: 346 | return "Open Interface"; 347 | case 40: 348 | return "R F Micro Devices"; 349 | case 41: 350 | return "Hitachi Ltd"; 351 | case 42: 352 | return "Symbol Technologies, Inc."; 353 | case 43: 354 | return "Tenovis"; 355 | case 44: 356 | return "Macronix International Co. Ltd."; 357 | case 45: 358 | return "GCT Semiconductor"; 359 | case 46: 360 | return "Norwood Systems"; 361 | case 47: 362 | return "MewTel Technology Inc."; 363 | case 48: 364 | return "ST Microelectronics"; 365 | case 49: 366 | return "Synopsys"; 367 | case 50: 368 | return "Red-M (Communications) Ltd"; 369 | case 51: 370 | return "Commil Ltd"; 371 | case 52: 372 | return "Computer Access Technology Corporation (CATC)"; 373 | case 53: 374 | return "Eclipse (HQ Espana) S.L."; 375 | case 54: 376 | return "Renesas Technology Corp."; 377 | case 55: 378 | return "Mobilian Corporation"; 379 | case 56: 380 | return "Terax"; 381 | case 57: 382 | return "Integrated System Solution Corp."; 383 | case 58: 384 | return "Matsushita Electric Industrial Co., Ltd."; 385 | case 59: 386 | return "Gennum Corporation"; 387 | case 60: 388 | return "Research In Motion"; 389 | case 61: 390 | return "IPextreme, Inc."; 391 | case 62: 392 | return "Systems and Chips, Inc"; 393 | case 63: 394 | return "Bluetooth SIG, Inc"; 395 | case 64: 396 | return "Seiko Epson Corporation"; 397 | case 65: 398 | return "Integrated Silicon Solution Taiwain, Inc."; 399 | case 66: 400 | return "CONWISE Technology Corporation Ltd"; 401 | case 67: 402 | return "PARROT SA"; 403 | case 68: 404 | return "Socket Communications"; 405 | case 69: 406 | return "Atheros Communications, Inc."; 407 | case 70: 408 | return "MediaTek, Inc."; 409 | case 71: 410 | return "Bluegiga"; 411 | case 72: 412 | return "Marvell Technology Group Ltd."; 413 | case 73: 414 | return "3DSP Corporation"; 415 | case 74: 416 | return "Accel Semiconductor Ltd."; 417 | case 75: 418 | return "Continental Automotive Systems"; 419 | case 76: 420 | return "Apple, Inc."; 421 | case 77: 422 | return "Staccato Communications, Inc."; 423 | case 78: 424 | return "Avago Technologies"; 425 | case 79: 426 | return "APT Ltd."; 427 | case 80: 428 | return "SiRF Technology, Inc."; 429 | case 81: 430 | return "Tzero Technologies, Inc."; 431 | case 82: 432 | return "J&M Corporation"; 433 | case 83: 434 | return "Free2move AB"; 435 | case 84: 436 | return "3DiJoy Corporation"; 437 | case 85: 438 | return "Plantronics, Inc."; 439 | case 86: 440 | return "Sony Ericsson Mobile Communications"; 441 | case 87: 442 | return "Harman International Industries, Inc."; 443 | case 88: 444 | return "Vizio, Inc."; 445 | case 89: 446 | return "Nordic Semiconductor ASA"; 447 | case 90: 448 | return "EM Microelectronic-Marin SA"; 449 | case 91: 450 | return "Ralink Technology Corporation"; 451 | case 92: 452 | return "Belkin International, Inc."; 453 | case 93: 454 | return "Realtek Semiconductor Corporation"; 455 | case 94: 456 | return "Stonestreet One, LLC"; 457 | case 95: 458 | return "Wicentric, Inc."; 459 | case 96: 460 | return "RivieraWaves S.A.S"; 461 | case 97: 462 | return "RDA Microelectronics"; 463 | case 98: 464 | return "Gibson Guitars"; 465 | case 99: 466 | return "MiCommand Inc."; 467 | case 100: 468 | return "Band XI International, LLC"; 469 | case 101: 470 | return "Hewlett-Packard Company"; 471 | case 102: 472 | return "9Solutions Oy"; 473 | case 103: 474 | return "GN Netcom A/S"; 475 | case 104: 476 | return "General Motors"; 477 | case 105: 478 | return "A&D Engineering, Inc."; 479 | case 106: 480 | return "MindTree Ltd."; 481 | case 107: 482 | return "Polar Electro OY"; 483 | case 108: 484 | return "Beautiful Enterprise Co., Ltd."; 485 | case 109: 486 | return "BriarTek, Inc."; 487 | case 110: 488 | return "Summit Data Communications, Inc."; 489 | case 111: 490 | return "Sound ID"; 491 | case 112: 492 | return "Monster, LLC"; 493 | case 113: 494 | return "connectBlue AB"; 495 | case 114: 496 | return "ShangHai Super Smart Electronics Co. Ltd."; 497 | case 115: 498 | return "Group Sense Ltd."; 499 | case 116: 500 | return "Zomm, LLC"; 501 | case 65535: 502 | return "internal use"; 503 | default: 504 | return "not assigned"; 505 | } 506 | } 507 | -------------------------------------------------------------------------------- /jni/lib/bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | * 24 | */ 25 | 26 | #ifndef __BLUETOOTH_H 27 | #define __BLUETOOTH_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #ifndef AF_BLUETOOTH 41 | #define AF_BLUETOOTH 31 42 | #define PF_BLUETOOTH AF_BLUETOOTH 43 | #endif 44 | 45 | #define BTPROTO_L2CAP 0 46 | #define BTPROTO_HCI 1 47 | #define BTPROTO_SCO 2 48 | #define BTPROTO_RFCOMM 3 49 | #define BTPROTO_BNEP 4 50 | #define BTPROTO_CMTP 5 51 | #define BTPROTO_HIDP 6 52 | #define BTPROTO_AVDTP 7 53 | 54 | #define SOL_HCI 0 55 | #define SOL_L2CAP 6 56 | #define SOL_SCO 17 57 | #define SOL_RFCOMM 18 58 | 59 | #ifndef SOL_BLUETOOTH 60 | #define SOL_BLUETOOTH 274 61 | #endif 62 | 63 | #define BT_SECURITY 4 64 | struct bt_security { 65 | uint8_t level; 66 | uint8_t key_size; 67 | }; 68 | #define BT_SECURITY_SDP 0 69 | #define BT_SECURITY_LOW 1 70 | #define BT_SECURITY_MEDIUM 2 71 | #define BT_SECURITY_HIGH 3 72 | 73 | #define BT_DEFER_SETUP 7 74 | 75 | #define BT_FLUSHABLE 8 76 | 77 | #define BT_FLUSHABLE_OFF 0 78 | #define BT_FLUSHABLE_ON 1 79 | 80 | #define BT_CHANNEL_POLICY 10 81 | 82 | /* BR/EDR only (default policy) 83 | * AMP controllers cannot be used. 84 | * Channel move requests from the remote device are denied. 85 | * If the L2CAP channel is currently using AMP, move the channel to BR/EDR. 86 | */ 87 | #define BT_CHANNEL_POLICY_BREDR_ONLY 0 88 | 89 | /* BR/EDR Preferred 90 | * Allow use of AMP controllers. 91 | * If the L2CAP channel is currently on AMP, move it to BR/EDR. 92 | * Channel move requests from the remote device are allowed. 93 | */ 94 | #define BT_CHANNEL_POLICY_BREDR_PREFERRED 1 95 | 96 | /* AMP Preferred 97 | * Allow use of AMP controllers 98 | * If the L2CAP channel is currently on BR/EDR and AMP controller 99 | * resources are available, initiate a channel move to AMP. 100 | * Channel move requests from the remote device are allowed. 101 | * If the L2CAP socket has not been connected yet, try to create 102 | * and configure the channel directly on an AMP controller rather 103 | * than BR/EDR. 104 | */ 105 | #define BT_CHANNEL_POLICY_AMP_PREFERRED 2 106 | 107 | /* Connection and socket states */ 108 | enum { 109 | BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ 110 | BT_OPEN, 111 | BT_BOUND, 112 | BT_LISTEN, 113 | BT_CONNECT, 114 | BT_CONNECT2, 115 | BT_CONFIG, 116 | BT_DISCONN, 117 | BT_CLOSED 118 | }; 119 | 120 | /* Byte order conversions */ 121 | #if __BYTE_ORDER == __LITTLE_ENDIAN 122 | #define htobs(d) (d) 123 | #define htobl(d) (d) 124 | #define htobll(d) (d) 125 | #define btohs(d) (d) 126 | #define btohl(d) (d) 127 | #define btohll(d) (d) 128 | #elif __BYTE_ORDER == __BIG_ENDIAN 129 | #define htobs(d) bswap_16(d) 130 | #define htobl(d) bswap_32(d) 131 | #define htobll(d) bswap_64(d) 132 | #define btohs(d) bswap_16(d) 133 | #define btohl(d) bswap_32(d) 134 | #define btohll(d) bswap_64(d) 135 | #else 136 | #error "Unknown byte order" 137 | #endif 138 | 139 | /* Bluetooth unaligned access */ 140 | #define bt_get_unaligned(ptr) \ 141 | ({ \ 142 | struct __attribute__((packed)) { \ 143 | typeof(*(ptr)) __v; \ 144 | } *__p = (void *) (ptr); \ 145 | __p->__v; \ 146 | }) 147 | 148 | #define bt_put_unaligned(val, ptr) \ 149 | do { \ 150 | struct __attribute__((packed)) { \ 151 | typeof(*(ptr)) __v; \ 152 | } *__p = (void *) (ptr); \ 153 | __p->__v = (val); \ 154 | } while(0) 155 | 156 | #if __BYTE_ORDER == __LITTLE_ENDIAN 157 | static inline uint64_t bt_get_le64(const void *ptr) 158 | { 159 | return bt_get_unaligned((const uint64_t *) ptr); 160 | } 161 | 162 | static inline uint64_t bt_get_be64(const void *ptr) 163 | { 164 | return bswap_64(bt_get_unaligned((const uint64_t *) ptr)); 165 | } 166 | 167 | static inline uint32_t bt_get_le32(const void *ptr) 168 | { 169 | return bt_get_unaligned((const uint32_t *) ptr); 170 | } 171 | 172 | static inline uint32_t bt_get_be32(const void *ptr) 173 | { 174 | return bswap_32(bt_get_unaligned((const uint32_t *) ptr)); 175 | } 176 | 177 | static inline uint16_t bt_get_le16(const void *ptr) 178 | { 179 | return bt_get_unaligned((const uint16_t *) ptr); 180 | } 181 | 182 | static inline uint16_t bt_get_be16(const void *ptr) 183 | { 184 | return bswap_16(bt_get_unaligned((const uint16_t *) ptr)); 185 | } 186 | #elif __BYTE_ORDER == __BIG_ENDIAN 187 | static inline uint64_t bt_get_le64(const void *ptr) 188 | { 189 | return bswap_64(bt_get_unaligned((const uint64_t *) ptr)); 190 | } 191 | 192 | static inline uint64_t bt_get_be64(const void *ptr) 193 | { 194 | return bt_get_unaligned((const uint64_t *) ptr); 195 | } 196 | 197 | static inline uint32_t bt_get_le32(const void *ptr) 198 | { 199 | return bswap_32(bt_get_unaligned((const uint32_t *) ptr)); 200 | } 201 | 202 | static inline uint32_t bt_get_be32(const void *ptr) 203 | { 204 | return bt_get_unaligned((const uint32_t *) ptr); 205 | } 206 | 207 | static inline uint16_t bt_get_le16(const void *ptr) 208 | { 209 | return bswap_16(bt_get_unaligned((const uint16_t *) ptr)); 210 | } 211 | 212 | static inline uint16_t bt_get_be16(const void *ptr) 213 | { 214 | return bt_get_unaligned((const uint16_t *) ptr); 215 | } 216 | #else 217 | #error "Unknown byte order" 218 | #endif 219 | 220 | /* BD Address */ 221 | typedef struct { 222 | uint8_t b[6]; 223 | } __attribute__((packed)) bdaddr_t; 224 | 225 | #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 226 | #define BDADDR_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) 227 | #define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) 228 | 229 | /* Copy, swap, convert BD Address */ 230 | static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2) 231 | { 232 | return memcmp(ba1, ba2, sizeof(bdaddr_t)); 233 | } 234 | static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src) 235 | { 236 | memcpy(dst, src, sizeof(bdaddr_t)); 237 | } 238 | 239 | void baswap(bdaddr_t *dst, const bdaddr_t *src); 240 | bdaddr_t *strtoba(const char *str); 241 | char *batostr(const bdaddr_t *ba); 242 | int ba2str(const bdaddr_t *ba, char *str); 243 | int str2ba(const char *str, bdaddr_t *ba); 244 | int ba2oui(const bdaddr_t *ba, char *oui); 245 | int bachk(const char *str); 246 | 247 | int baprintf(const char *format, ...); 248 | int bafprintf(FILE *stream, const char *format, ...); 249 | int basprintf(char *str, const char *format, ...); 250 | int basnprintf(char *str, size_t size, const char *format, ...); 251 | 252 | void *bt_malloc(size_t size); 253 | void bt_free(void *ptr); 254 | 255 | int bt_error(uint16_t code); 256 | char *bt_compidtostr(int id); 257 | 258 | typedef struct { 259 | uint8_t data[16]; 260 | } uint128_t; 261 | 262 | #if __BYTE_ORDER == __BIG_ENDIAN 263 | 264 | #define ntoh64(x) (x) 265 | 266 | static inline void ntoh128(const uint128_t *src, uint128_t *dst) 267 | { 268 | memcpy(dst, src, sizeof(uint128_t)); 269 | } 270 | 271 | static inline void btoh128(const uint128_t *src, uint128_t *dst) 272 | { 273 | int i; 274 | 275 | for (i = 0; i < 16; i++) 276 | dst->data[15 - i] = src->data[i]; 277 | } 278 | 279 | #else 280 | 281 | static inline uint64_t ntoh64(uint64_t n) 282 | { 283 | uint64_t h; 284 | uint64_t tmp = ntohl(n & 0x00000000ffffffff); 285 | 286 | h = ntohl(n >> 32); 287 | h |= tmp << 32; 288 | 289 | return h; 290 | } 291 | 292 | static inline void ntoh128(const uint128_t *src, uint128_t *dst) 293 | { 294 | int i; 295 | 296 | for (i = 0; i < 16; i++) 297 | dst->data[15 - i] = src->data[i]; 298 | } 299 | 300 | static inline void btoh128(const uint128_t *src, uint128_t *dst) 301 | { 302 | memcpy(dst, src, sizeof(uint128_t)); 303 | } 304 | 305 | #endif 306 | 307 | #define hton64(x) ntoh64(x) 308 | #define hton128(x, y) ntoh128(x, y) 309 | #define htob128(x, y) btoh128(x, y) 310 | 311 | #ifdef __cplusplus 312 | } 313 | #endif 314 | 315 | #endif /* __BLUETOOTH_H */ 316 | -------------------------------------------------------------------------------- /jni/lib/hci_lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | * 24 | */ 25 | 26 | #ifndef __HCI_LIB_H 27 | #define __HCI_LIB_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | struct hci_request { 34 | uint16_t ogf; 35 | uint16_t ocf; 36 | int event; 37 | void *cparam; 38 | int clen; 39 | void *rparam; 40 | int rlen; 41 | }; 42 | 43 | struct hci_version { 44 | uint16_t manufacturer; 45 | uint8_t hci_ver; 46 | uint16_t hci_rev; 47 | uint8_t lmp_ver; 48 | uint16_t lmp_subver; 49 | }; 50 | 51 | int hci_open_dev(int dev_id); 52 | int hci_close_dev(int dd); 53 | int hci_send_cmd(int dd, uint16_t ogf, uint16_t ocf, uint8_t plen, void *param); 54 | int hci_send_req(int dd, struct hci_request *req, int timeout); 55 | 56 | int hci_create_connection(int dd, const bdaddr_t *bdaddr, uint16_t ptype, uint16_t clkoffset, uint8_t rswitch, uint16_t *handle, int to); 57 | int hci_disconnect(int dd, uint16_t handle, uint8_t reason, int to); 58 | 59 | int hci_inquiry(int dev_id, int len, int num_rsp, const uint8_t *lap, inquiry_info **ii, long flags); 60 | int hci_devinfo(int dev_id, struct hci_dev_info *di); 61 | int hci_devba(int dev_id, bdaddr_t *bdaddr); 62 | int hci_devid(const char *str); 63 | 64 | int hci_read_local_name(int dd, int len, char *name, int to); 65 | int hci_write_local_name(int dd, const char *name, int to); 66 | int hci_read_remote_name(int dd, const bdaddr_t *bdaddr, int len, char *name, int to); 67 | int hci_read_remote_name_with_clock_offset(int dd, const bdaddr_t *bdaddr, uint8_t pscan_rep_mode, uint16_t clkoffset, int len, char *name, int to); 68 | int hci_read_remote_name_cancel(int dd, const bdaddr_t *bdaddr, int to); 69 | int hci_read_remote_version(int dd, uint16_t handle, struct hci_version *ver, int to); 70 | int hci_read_remote_features(int dd, uint16_t handle, uint8_t *features, int to); 71 | int hci_read_remote_ext_features(int dd, uint16_t handle, uint8_t page, uint8_t *max_page, uint8_t *features, int to); 72 | int hci_read_clock_offset(int dd, uint16_t handle, uint16_t *clkoffset, int to); 73 | int hci_read_local_version(int dd, struct hci_version *ver, int to); 74 | int hci_read_local_commands(int dd, uint8_t *commands, int to); 75 | int hci_read_local_features(int dd, uint8_t *features, int to); 76 | int hci_read_local_ext_features(int dd, uint8_t page, uint8_t *max_page, uint8_t *features, int to); 77 | int hci_read_bd_addr(int dd, bdaddr_t *bdaddr, int to); 78 | int hci_read_class_of_dev(int dd, uint8_t *cls, int to); 79 | int hci_write_class_of_dev(int dd, uint32_t cls, int to); 80 | int hci_read_voice_setting(int dd, uint16_t *vs, int to); 81 | int hci_write_voice_setting(int dd, uint16_t vs, int to); 82 | int hci_read_current_iac_lap(int dd, uint8_t *num_iac, uint8_t *lap, int to); 83 | int hci_write_current_iac_lap(int dd, uint8_t num_iac, uint8_t *lap, int to); 84 | int hci_read_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to); 85 | int hci_write_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t *key, int to); 86 | int hci_delete_stored_link_key(int dd, bdaddr_t *bdaddr, uint8_t all, int to); 87 | int hci_authenticate_link(int dd, uint16_t handle, int to); 88 | int hci_encrypt_link(int dd, uint16_t handle, uint8_t encrypt, int to); 89 | int hci_change_link_key(int dd, uint16_t handle, int to); 90 | int hci_switch_role(int dd, bdaddr_t *bdaddr, uint8_t role, int to); 91 | int hci_park_mode(int dd, uint16_t handle, uint16_t max_interval, uint16_t min_interval, int to); 92 | int hci_exit_park_mode(int dd, uint16_t handle, int to); 93 | int hci_read_inquiry_scan_type(int dd, uint8_t *type, int to); 94 | int hci_write_inquiry_scan_type(int dd, uint8_t type, int to); 95 | int hci_read_inquiry_mode(int dd, uint8_t *mode, int to); 96 | int hci_write_inquiry_mode(int dd, uint8_t mode, int to); 97 | int hci_read_afh_mode(int dd, uint8_t *mode, int to); 98 | int hci_write_afh_mode(int dd, uint8_t mode, int to); 99 | int hci_read_ext_inquiry_response(int dd, uint8_t *fec, uint8_t *data, int to); 100 | int hci_write_ext_inquiry_response(int dd, uint8_t fec, uint8_t *data, int to); 101 | int hci_read_simple_pairing_mode(int dd, uint8_t *mode, int to); 102 | int hci_write_simple_pairing_mode(int dd, uint8_t mode, int to); 103 | int hci_read_local_oob_data(int dd, uint8_t *hash, uint8_t *randomizer, int to); 104 | int hci_read_inq_response_tx_power_level(int dd, int8_t *level, int to); 105 | int hci_read_inquiry_transmit_power_level(int dd, int8_t *level, int to); 106 | int hci_write_inquiry_transmit_power_level(int dd, int8_t level, int to); 107 | int hci_read_transmit_power_level(int dd, uint16_t handle, uint8_t type, int8_t *level, int to); 108 | int hci_read_link_policy(int dd, uint16_t handle, uint16_t *policy, int to); 109 | int hci_write_link_policy(int dd, uint16_t handle, uint16_t policy, int to); 110 | int hci_read_link_supervision_timeout(int dd, uint16_t handle, uint16_t *timeout, int to); 111 | int hci_write_link_supervision_timeout(int dd, uint16_t handle, uint16_t timeout, int to); 112 | int hci_set_afh_classification(int dd, uint8_t *map, int to); 113 | int hci_read_link_quality(int dd, uint16_t handle, uint8_t *link_quality, int to); 114 | int hci_read_rssi(int dd, uint16_t handle, int8_t *rssi, int to); 115 | int hci_read_afh_map(int dd, uint16_t handle, uint8_t *mode, uint8_t *map, int to); 116 | int hci_read_clock(int dd, uint16_t handle, uint8_t which, uint32_t *clock, uint16_t *accuracy, int to); 117 | 118 | int hci_le_set_scan_enable(int dev_id, uint8_t enable, uint8_t filter_dup, int to); 119 | int hci_le_set_scan_parameters(int dev_id, uint8_t type, uint16_t interval, 120 | uint16_t window, uint8_t own_type, 121 | uint8_t filter, int to); 122 | int hci_le_set_advertise_enable(int dev_id, uint8_t enable, int to); 123 | int hci_le_create_conn(int dd, uint16_t interval, uint16_t window, 124 | uint8_t initiator_filter, uint8_t peer_bdaddr_type, 125 | bdaddr_t peer_bdaddr, uint8_t own_bdaddr_type, 126 | uint16_t min_interval, uint16_t max_interval, 127 | uint16_t latency, uint16_t supervision_timeout, 128 | uint16_t min_ce_length, uint16_t max_ce_length, 129 | uint16_t *handle, int to); 130 | 131 | int hci_le_conn_update(int dd, uint16_t handle, uint16_t min_interval, 132 | uint16_t max_interval, uint16_t latency, 133 | uint16_t supervision_timeout, int to); 134 | int hci_le_add_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to); 135 | int hci_le_rm_white_list(int dd, const bdaddr_t *bdaddr, uint8_t type, int to); 136 | int hci_le_read_white_list_size(int dd, uint8_t *size, int to); 137 | int hci_le_clear_white_list(int dd, int to); 138 | int hci_for_each_dev(int flag, int(*func)(int dd, int dev_id, long arg), long arg); 139 | int hci_get_route(bdaddr_t *bdaddr); 140 | 141 | char *hci_bustostr(int bus); 142 | char *hci_typetostr(int type); 143 | char *hci_dtypetostr(int type); 144 | char *hci_dflagstostr(uint32_t flags); 145 | char *hci_ptypetostr(unsigned int ptype); 146 | int hci_strtoptype(char *str, unsigned int *val); 147 | char *hci_scoptypetostr(unsigned int ptype); 148 | int hci_strtoscoptype(char *str, unsigned int *val); 149 | char *hci_lptostr(unsigned int ptype); 150 | int hci_strtolp(char *str, unsigned int *val); 151 | char *hci_lmtostr(unsigned int ptype); 152 | int hci_strtolm(char *str, unsigned int *val); 153 | 154 | char *hci_cmdtostr(unsigned int cmd); 155 | char *hci_commandstostr(uint8_t *commands, char *pref, int width); 156 | 157 | char *hci_vertostr(unsigned int ver); 158 | int hci_strtover(char *str, unsigned int *ver); 159 | char *lmp_vertostr(unsigned int ver); 160 | int lmp_strtover(char *str, unsigned int *ver); 161 | 162 | char *lmp_featurestostr(uint8_t *features, char *pref, int width); 163 | 164 | static inline void hci_set_bit(int nr, void *addr) 165 | { 166 | *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31)); 167 | } 168 | 169 | static inline void hci_clear_bit(int nr, void *addr) 170 | { 171 | *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31)); 172 | } 173 | 174 | static inline int hci_test_bit(int nr, void *addr) 175 | { 176 | return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31)); 177 | } 178 | 179 | /* HCI filter tools */ 180 | static inline void hci_filter_clear(struct hci_filter *f) 181 | { 182 | memset(f, 0, sizeof(*f)); 183 | } 184 | static inline void hci_filter_set_ptype(int t, struct hci_filter *f) 185 | { 186 | hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 187 | } 188 | static inline void hci_filter_clear_ptype(int t, struct hci_filter *f) 189 | { 190 | hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 191 | } 192 | static inline int hci_filter_test_ptype(int t, struct hci_filter *f) 193 | { 194 | return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask); 195 | } 196 | static inline void hci_filter_all_ptypes(struct hci_filter *f) 197 | { 198 | memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask)); 199 | } 200 | static inline void hci_filter_set_event(int e, struct hci_filter *f) 201 | { 202 | hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 203 | } 204 | static inline void hci_filter_clear_event(int e, struct hci_filter *f) 205 | { 206 | hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 207 | } 208 | static inline int hci_filter_test_event(int e, struct hci_filter *f) 209 | { 210 | return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask); 211 | } 212 | static inline void hci_filter_all_events(struct hci_filter *f) 213 | { 214 | memset((void *) f->event_mask, 0xff, sizeof(f->event_mask)); 215 | } 216 | static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f) 217 | { 218 | f->opcode = opcode; 219 | } 220 | static inline void hci_filter_clear_opcode(struct hci_filter *f) 221 | { 222 | f->opcode = 0; 223 | } 224 | static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f) 225 | { 226 | return (f->opcode == opcode); 227 | } 228 | 229 | #ifdef __cplusplus 230 | } 231 | #endif 232 | 233 | #endif /* __HCI_LIB_H */ 234 | -------------------------------------------------------------------------------- /jni/lib/l2cap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2001 Qualcomm Incorporated 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky 7 | * Copyright (C) 2002-2010 Marcel Holtmann 8 | * Copyright (c) 2012 Code Aurora Forum. All rights reserved. 9 | * 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | * 25 | */ 26 | 27 | #ifndef __L2CAP_H 28 | #define __L2CAP_H 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #include 35 | 36 | /* L2CAP defaults */ 37 | #define L2CAP_DEFAULT_MTU 672 38 | #define L2CAP_DEFAULT_FLUSH_TO 0xFFFF 39 | 40 | /* L2CAP socket address */ 41 | struct sockaddr_l2 { 42 | sa_family_t l2_family; 43 | unsigned short l2_psm; 44 | bdaddr_t l2_bdaddr; 45 | unsigned short l2_cid; 46 | }; 47 | 48 | /* L2CAP socket options */ 49 | #define L2CAP_OPTIONS 0x01 50 | struct l2cap_options { 51 | uint16_t omtu; 52 | uint16_t imtu; 53 | uint16_t flush_to; 54 | uint8_t mode; 55 | uint8_t fcs; 56 | uint8_t max_tx; 57 | uint16_t txwin_size; 58 | }; 59 | 60 | #define L2CAP_CONNINFO 0x02 61 | struct l2cap_conninfo { 62 | uint16_t hci_handle; 63 | uint8_t dev_class[3]; 64 | }; 65 | 66 | #define L2CAP_LM 0x03 67 | #define L2CAP_LM_MASTER 0x0001 68 | #define L2CAP_LM_AUTH 0x0002 69 | #define L2CAP_LM_ENCRYPT 0x0004 70 | #define L2CAP_LM_TRUSTED 0x0008 71 | #define L2CAP_LM_RELIABLE 0x0010 72 | #define L2CAP_LM_SECURE 0x0020 73 | 74 | /* L2CAP command codes */ 75 | #define L2CAP_COMMAND_REJ 0x01 76 | #define L2CAP_CONN_REQ 0x02 77 | #define L2CAP_CONN_RSP 0x03 78 | #define L2CAP_CONF_REQ 0x04 79 | #define L2CAP_CONF_RSP 0x05 80 | #define L2CAP_DISCONN_REQ 0x06 81 | #define L2CAP_DISCONN_RSP 0x07 82 | #define L2CAP_ECHO_REQ 0x08 83 | #define L2CAP_ECHO_RSP 0x09 84 | #define L2CAP_INFO_REQ 0x0a 85 | #define L2CAP_INFO_RSP 0x0b 86 | #define L2CAP_CREATE_REQ 0x0c 87 | #define L2CAP_CREATE_RSP 0x0d 88 | #define L2CAP_MOVE_REQ 0x0e 89 | #define L2CAP_MOVE_RSP 0x0f 90 | #define L2CAP_MOVE_CFM 0x10 91 | #define L2CAP_MOVE_CFM_RSP 0x11 92 | 93 | /* L2CAP extended feature mask */ 94 | #define L2CAP_FEAT_FLOWCTL 0x00000001 95 | #define L2CAP_FEAT_RETRANS 0x00000002 96 | #define L2CAP_FEAT_BIDIR_QOS 0x00000004 97 | #define L2CAP_FEAT_ERTM 0x00000008 98 | #define L2CAP_FEAT_STREAMING 0x00000010 99 | #define L2CAP_FEAT_FCS 0x00000020 100 | #define L2CAP_FEAT_EXT_FLOW 0x00000040 101 | #define L2CAP_FEAT_FIXED_CHAN 0x00000080 102 | #define L2CAP_FEAT_EXT_WINDOW 0x00000100 103 | #define L2CAP_FEAT_UCD 0x00000200 104 | 105 | /* L2CAP Control Field bit masks */ 106 | #define L2CAP_CTRL_SAR_MASK 0xC000 107 | #define L2CAP_CTRL_REQSEQ_MASK 0x3F00 108 | #define L2CAP_CTRL_TXSEQ_MASK 0x007E 109 | #define L2CAP_CTRL_SUPERVISE_MASK 0x000C 110 | 111 | #define L2CAP_CTRL_RETRANS 0x0080 112 | #define L2CAP_CTRL_FINAL 0x0080 113 | #define L2CAP_CTRL_POLL 0x0010 114 | #define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */ 115 | 116 | #define L2CAP_CTRL_TXSEQ_SHIFT 1 117 | #define L2CAP_CTRL_SUPER_SHIFT 2 118 | #define L2CAP_CTRL_REQSEQ_SHIFT 8 119 | #define L2CAP_CTRL_SAR_SHIFT 14 120 | 121 | #define L2CAP_EXT_CTRL_TXSEQ_MASK 0xFFFC0000 122 | #define L2CAP_EXT_CTRL_SAR_MASK 0x00030000 123 | #define L2CAP_EXT_CTRL_SUPERVISE_MASK 0x00030000 124 | #define L2CAP_EXT_CTRL_REQSEQ_MASK 0x0000FFFC 125 | 126 | #define L2CAP_EXT_CTRL_POLL 0x00040000 127 | #define L2CAP_EXT_CTRL_FINAL 0x00000002 128 | #define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */ 129 | 130 | #define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2 131 | #define L2CAP_EXT_CTRL_SAR_SHIFT 16 132 | #define L2CAP_EXT_CTRL_SUPER_SHIFT 16 133 | #define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18 134 | 135 | /* L2CAP Supervisory Function */ 136 | #define L2CAP_SUPER_RR 0x00 137 | #define L2CAP_SUPER_REJ 0x01 138 | #define L2CAP_SUPER_RNR 0x02 139 | #define L2CAP_SUPER_SREJ 0x03 140 | 141 | /* L2CAP Segmentation and Reassembly */ 142 | #define L2CAP_SAR_UNSEGMENTED 0x00 143 | #define L2CAP_SAR_START 0x01 144 | #define L2CAP_SAR_END 0x02 145 | #define L2CAP_SAR_CONTINUE 0x03 146 | 147 | #define L2CAP_SDULEN_SIZE 2 148 | 149 | /* L2CAP fixed channels */ 150 | #define L2CAP_FC_L2CAP 0x02 151 | #define L2CAP_FC_CONNLESS 0x04 152 | #define L2CAP_FC_A2MP 0x08 153 | 154 | /* L2CAP structures */ 155 | typedef struct { 156 | uint16_t len; 157 | uint16_t cid; 158 | } __attribute__ ((packed)) l2cap_hdr; 159 | #define L2CAP_HDR_SIZE 4 160 | 161 | typedef struct { 162 | uint8_t code; 163 | uint8_t ident; 164 | uint16_t len; 165 | } __attribute__ ((packed)) l2cap_cmd_hdr; 166 | #define L2CAP_CMD_HDR_SIZE 4 167 | 168 | typedef struct { 169 | uint16_t reason; 170 | } __attribute__ ((packed)) l2cap_cmd_rej; 171 | #define L2CAP_CMD_REJ_SIZE 2 172 | 173 | typedef struct { 174 | uint16_t psm; 175 | uint16_t scid; 176 | } __attribute__ ((packed)) l2cap_conn_req; 177 | #define L2CAP_CONN_REQ_SIZE 4 178 | 179 | typedef struct { 180 | uint16_t dcid; 181 | uint16_t scid; 182 | uint16_t result; 183 | uint16_t status; 184 | } __attribute__ ((packed)) l2cap_conn_rsp; 185 | #define L2CAP_CONN_RSP_SIZE 8 186 | 187 | /* connect result */ 188 | #define L2CAP_CR_SUCCESS 0x0000 189 | #define L2CAP_CR_PEND 0x0001 190 | #define L2CAP_CR_BAD_PSM 0x0002 191 | #define L2CAP_CR_SEC_BLOCK 0x0003 192 | #define L2CAP_CR_NO_MEM 0x0004 193 | 194 | /* connect status */ 195 | #define L2CAP_CS_NO_INFO 0x0000 196 | #define L2CAP_CS_AUTHEN_PEND 0x0001 197 | #define L2CAP_CS_AUTHOR_PEND 0x0002 198 | 199 | typedef struct { 200 | uint16_t dcid; 201 | uint16_t flags; 202 | uint8_t data[0]; 203 | } __attribute__ ((packed)) l2cap_conf_req; 204 | #define L2CAP_CONF_REQ_SIZE 4 205 | 206 | typedef struct { 207 | uint16_t scid; 208 | uint16_t flags; 209 | uint16_t result; 210 | uint8_t data[0]; 211 | } __attribute__ ((packed)) l2cap_conf_rsp; 212 | #define L2CAP_CONF_RSP_SIZE 6 213 | 214 | #define L2CAP_CONF_SUCCESS 0x0000 215 | #define L2CAP_CONF_UNACCEPT 0x0001 216 | #define L2CAP_CONF_REJECT 0x0002 217 | #define L2CAP_CONF_UNKNOWN 0x0003 218 | #define L2CAP_CONF_PENDING 0x0004 219 | #define L2CAP_CONF_EFS_REJECT 0x0005 220 | 221 | typedef struct { 222 | uint8_t type; 223 | uint8_t len; 224 | uint8_t val[0]; 225 | } __attribute__ ((packed)) l2cap_conf_opt; 226 | #define L2CAP_CONF_OPT_SIZE 2 227 | 228 | #define L2CAP_CONF_MTU 0x01 229 | #define L2CAP_CONF_FLUSH_TO 0x02 230 | #define L2CAP_CONF_QOS 0x03 231 | #define L2CAP_CONF_RFC 0x04 232 | #define L2CAP_CONF_FCS 0x05 233 | #define L2CAP_CONF_EFS 0x06 234 | #define L2CAP_CONF_EWS 0x07 235 | 236 | #define L2CAP_CONF_MAX_SIZE 22 237 | 238 | #define L2CAP_MODE_BASIC 0x00 239 | #define L2CAP_MODE_RETRANS 0x01 240 | #define L2CAP_MODE_FLOWCTL 0x02 241 | #define L2CAP_MODE_ERTM 0x03 242 | #define L2CAP_MODE_STREAMING 0x04 243 | 244 | #define L2CAP_SERVTYPE_NOTRAFFIC 0x00 245 | #define L2CAP_SERVTYPE_BESTEFFORT 0x01 246 | #define L2CAP_SERVTYPE_GUARANTEED 0x02 247 | 248 | typedef struct { 249 | uint16_t dcid; 250 | uint16_t scid; 251 | } __attribute__ ((packed)) l2cap_disconn_req; 252 | #define L2CAP_DISCONN_REQ_SIZE 4 253 | 254 | typedef struct { 255 | uint16_t dcid; 256 | uint16_t scid; 257 | } __attribute__ ((packed)) l2cap_disconn_rsp; 258 | #define L2CAP_DISCONN_RSP_SIZE 4 259 | 260 | typedef struct { 261 | uint16_t type; 262 | } __attribute__ ((packed)) l2cap_info_req; 263 | #define L2CAP_INFO_REQ_SIZE 2 264 | 265 | typedef struct { 266 | uint16_t type; 267 | uint16_t result; 268 | uint8_t data[0]; 269 | } __attribute__ ((packed)) l2cap_info_rsp; 270 | #define L2CAP_INFO_RSP_SIZE 4 271 | 272 | /* info type */ 273 | #define L2CAP_IT_CL_MTU 0x0001 274 | #define L2CAP_IT_FEAT_MASK 0x0002 275 | 276 | /* info result */ 277 | #define L2CAP_IR_SUCCESS 0x0000 278 | #define L2CAP_IR_NOTSUPP 0x0001 279 | 280 | typedef struct { 281 | uint16_t psm; 282 | uint16_t scid; 283 | uint8_t id; 284 | } __attribute__ ((packed)) l2cap_create_req; 285 | #define L2CAP_CREATE_REQ_SIZE 5 286 | 287 | typedef struct { 288 | uint16_t dcid; 289 | uint16_t scid; 290 | uint16_t result; 291 | uint16_t status; 292 | } __attribute__ ((packed)) l2cap_create_rsp; 293 | #define L2CAP_CREATE_RSP_SIZE 8 294 | 295 | typedef struct { 296 | uint16_t icid; 297 | uint8_t id; 298 | } __attribute__ ((packed)) l2cap_move_req; 299 | #define L2CAP_MOVE_REQ_SIZE 3 300 | 301 | typedef struct { 302 | uint16_t icid; 303 | uint16_t result; 304 | } __attribute__ ((packed)) l2cap_move_rsp; 305 | #define L2CAP_MOVE_RSP_SIZE 4 306 | 307 | typedef struct { 308 | uint16_t icid; 309 | uint16_t result; 310 | } __attribute__ ((packed)) l2cap_move_cfm; 311 | #define L2CAP_MOVE_CFM_SIZE 4 312 | 313 | typedef struct { 314 | uint16_t icid; 315 | } __attribute__ ((packed)) l2cap_move_cfm_rsp; 316 | #define L2CAP_MOVE_CFM_RSP_SIZE 2 317 | 318 | #ifdef __cplusplus 319 | } 320 | #endif 321 | 322 | #endif /* __L2CAP_H */ 323 | -------------------------------------------------------------------------------- /jni/parser/.deps/att.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/avctp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/avdtp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/avrcp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/bnep.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/bpa.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/capi.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/cmtp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/csr.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/ericsson.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/hci.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/hcrp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/hidp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/l2cap.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/lmp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/obex.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/parser.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/ppp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/rfcomm.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/sdp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/smp.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/.deps/tcpip.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /jni/parser/avctp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | #include "parser/sdp.h" 36 | 37 | static char *pt2str(uint8_t hdr) 38 | { 39 | switch (hdr & 0x0c) { 40 | case 0x00: 41 | return ""; 42 | case 0x04: 43 | return "Start"; 44 | case 0x08: 45 | return "Cont"; 46 | case 0x0c: 47 | return "End"; 48 | default: 49 | return "Unk"; 50 | } 51 | } 52 | 53 | void avctp_dump(int level, struct frame *frm) 54 | { 55 | uint8_t hdr; 56 | uint16_t pid; 57 | 58 | p_indent(level, frm); 59 | 60 | hdr = get_u8(frm); 61 | pid = get_u16(frm); 62 | 63 | printf("AVCTP: %s %s: pt 0x%02x transaction %d pid 0x%04x \n", 64 | hdr & 0x02 ? "Response" : "Command", 65 | pt2str(hdr), hdr & 0x0c, hdr >> 4, pid); 66 | 67 | if (pid == SDP_UUID_AV_REMOTE || pid == SDP_UUID_AV_REMOTE_TARGET) 68 | avrcp_dump(level + 1, frm); 69 | else 70 | raw_dump(level + 1, frm); 71 | } 72 | -------------------------------------------------------------------------------- /jni/parser/avdtp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | static char *si2str(uint8_t si) 37 | { 38 | switch (si & 0x7f) { 39 | case 0x01: 40 | return "Discover"; 41 | case 0x02: 42 | return "Capabilities"; 43 | case 0x03: 44 | return "Set config"; 45 | case 0x04: 46 | return "Get config"; 47 | case 0x05: 48 | return "Reconfigure"; 49 | case 0x06: 50 | return "Open"; 51 | case 0x07: 52 | return "Start"; 53 | case 0x08: 54 | return "Close"; 55 | case 0x09: 56 | return "Suspend"; 57 | case 0x0a: 58 | return "Abort"; 59 | case 0x0b: 60 | return "Security"; 61 | case 0x0c: 62 | return "All Capabilities"; 63 | case 0x0d: 64 | return "Delay Report"; 65 | default: 66 | return "Unknown"; 67 | } 68 | } 69 | 70 | static char *pt2str(uint8_t hdr) 71 | { 72 | switch (hdr & 0x0c) { 73 | case 0x00: 74 | return "Single"; 75 | case 0x04: 76 | return "Start"; 77 | case 0x08: 78 | return "Cont"; 79 | case 0x0c: 80 | return "End"; 81 | default: 82 | return "Unk"; 83 | } 84 | } 85 | 86 | static char *mt2str(uint8_t hdr) 87 | { 88 | switch (hdr & 0x03) { 89 | case 0x00: 90 | return "cmd"; 91 | case 0x02: 92 | return "rsp"; 93 | case 0x03: 94 | return "rej"; 95 | default: 96 | return "rfd"; 97 | } 98 | } 99 | 100 | static char *media2str(uint8_t type) 101 | { 102 | switch (type) { 103 | case 0: 104 | return "Audio"; 105 | case 1: 106 | return "Video"; 107 | case 2: 108 | return "Multimedia"; 109 | default: 110 | return "Reserved"; 111 | } 112 | } 113 | 114 | static char *codec2str(uint8_t type, uint8_t codec) 115 | { 116 | switch (type) { 117 | case 0: 118 | switch (codec) { 119 | case 0: 120 | return "SBC"; 121 | case 1: 122 | return "MPEG-1,2 Audio"; 123 | case 2: 124 | return "MPEG-2,4 AAC"; 125 | case 4: 126 | return "ATRAC family"; 127 | case 255: 128 | return "non-A2DP"; 129 | default: 130 | return "Reserved"; 131 | } 132 | break; 133 | case 1: 134 | switch (codec) { 135 | case 1: 136 | return "H.263 baseline"; 137 | case 2: 138 | return "MPEG-4 Visual Simple Profile"; 139 | case 3: 140 | return "H.263 profile 3"; 141 | case 4: 142 | return "H.263 profile 8"; 143 | case 255: 144 | return "Non-VDP"; 145 | default: 146 | return "Reserved"; 147 | } 148 | break; 149 | } 150 | return "Unknown"; 151 | } 152 | 153 | static char *cat2str(uint8_t cat) 154 | { 155 | switch (cat) { 156 | case 1: 157 | return "Media Transport"; 158 | case 2: 159 | return "Reporting"; 160 | case 3: 161 | return "Recovery"; 162 | case 4: 163 | return "Content Protection"; 164 | case 5: 165 | return "Header Compression"; 166 | case 6: 167 | return "Multiplexing"; 168 | case 7: 169 | return "Media Codec"; 170 | case 8: 171 | return "Delay Reporting"; 172 | default: 173 | return "Reserved"; 174 | } 175 | } 176 | 177 | static void errorcode(int level, struct frame *frm) 178 | { 179 | uint8_t code; 180 | 181 | p_indent(level, frm); 182 | code = get_u8(frm); 183 | printf("Error code %d\n", code); 184 | } 185 | 186 | static void acp_seid(int level, struct frame *frm) 187 | { 188 | uint8_t seid; 189 | 190 | p_indent(level, frm); 191 | seid = get_u8(frm); 192 | printf("ACP SEID %d\n", seid >> 2); 193 | } 194 | 195 | static void acp_int_seid(int level, struct frame *frm) 196 | { 197 | uint8_t acp_seid, int_seid; 198 | 199 | p_indent(level, frm); 200 | acp_seid = get_u8(frm); 201 | int_seid = get_u8(frm); 202 | printf("ACP SEID %d - INT SEID %d\n", acp_seid >> 2, int_seid >> 2); 203 | } 204 | 205 | static void capabilities(int level, struct frame *frm) 206 | { 207 | uint8_t cat, len; 208 | 209 | while (frm->len > 1) { 210 | p_indent(level, frm); 211 | cat = get_u8(frm); 212 | len = get_u8(frm); 213 | 214 | if (cat == 7) { 215 | uint8_t type, codec, tmp; 216 | 217 | type = get_u8(frm); 218 | codec = get_u8(frm); 219 | 220 | printf("%s - %s\n", cat2str(cat), codec2str(type, codec)); 221 | 222 | switch (codec) { 223 | case 0: 224 | tmp = get_u8(frm); 225 | p_indent(level + 1, frm); 226 | if (tmp & 0x80) 227 | printf("16kHz "); 228 | if (tmp & 0x40) 229 | printf("32kHz "); 230 | if (tmp & 0x20) 231 | printf("44.1kHz "); 232 | if (tmp & 0x10) 233 | printf("48kHz "); 234 | printf("\n"); 235 | p_indent(level + 1, frm); 236 | if (tmp & 0x08) 237 | printf("Mono "); 238 | if (tmp & 0x04) 239 | printf("DualChannel "); 240 | if (tmp & 0x02) 241 | printf("Stereo "); 242 | if (tmp & 0x01) 243 | printf("JointStereo "); 244 | printf("\n"); 245 | tmp = get_u8(frm); 246 | p_indent(level + 1, frm); 247 | if (tmp & 0x80) 248 | printf("4 "); 249 | if (tmp & 0x40) 250 | printf("8 "); 251 | if (tmp & 0x20) 252 | printf("12 "); 253 | if (tmp & 0x10) 254 | printf("16 "); 255 | printf("Blocks\n"); 256 | p_indent(level + 1, frm); 257 | if (tmp & 0x08) 258 | printf("4 "); 259 | if (tmp & 0x04) 260 | printf("8 "); 261 | printf("Subbands\n"); 262 | p_indent(level + 1, frm); 263 | if (tmp & 0x02) 264 | printf("SNR "); 265 | if (tmp & 0x01) 266 | printf("Loudness "); 267 | printf("\n"); 268 | tmp = get_u8(frm); 269 | p_indent(level + 1, frm); 270 | printf("Bitpool Range %d-%d\n", tmp, get_u8(frm)); 271 | break; 272 | default: 273 | hex_dump(level + 1, frm, len - 2); 274 | frm->ptr += (len - 2); 275 | frm->len -= (len - 2); 276 | break; 277 | } 278 | } else { 279 | printf("%s\n", cat2str(cat)); 280 | hex_dump(level + 1, frm, len); 281 | 282 | frm->ptr += len; 283 | frm->len -= len; 284 | } 285 | } 286 | } 287 | 288 | static inline void discover(int level, uint8_t hdr, struct frame *frm) 289 | { 290 | uint8_t seid, type; 291 | 292 | switch (hdr & 0x03) { 293 | case 0x02: 294 | while (frm->len > 1) { 295 | p_indent(level, frm); 296 | seid = get_u8(frm); 297 | type = get_u8(frm); 298 | printf("ACP SEID %d - %s %s%s\n", 299 | seid >> 2, media2str(type >> 4), 300 | type & 0x08 ? "Sink" : "Source", 301 | seid & 0x02 ? " (InUse)" : ""); 302 | } 303 | break; 304 | case 0x03: 305 | errorcode(level, frm); 306 | break; 307 | } 308 | } 309 | 310 | static inline void get_capabilities(int level, uint8_t hdr, struct frame *frm) 311 | { 312 | switch (hdr & 0x03) { 313 | case 0x00: 314 | acp_seid(level, frm); 315 | break; 316 | case 0x02: 317 | capabilities(level, frm); 318 | break; 319 | case 0x03: 320 | errorcode(level, frm); 321 | break; 322 | } 323 | } 324 | 325 | static inline void set_configuration(int level, uint8_t hdr, struct frame *frm) 326 | { 327 | uint8_t cat; 328 | 329 | switch (hdr & 0x03) { 330 | case 0x00: 331 | acp_int_seid(level, frm); 332 | capabilities(level, frm); 333 | break; 334 | case 0x03: 335 | p_indent(level, frm); 336 | cat = get_u8(frm); 337 | printf("%s\n", cat2str(cat)); 338 | errorcode(level, frm); 339 | break; 340 | } 341 | } 342 | 343 | static inline void get_configuration(int level, uint8_t hdr, struct frame *frm) 344 | { 345 | switch (hdr & 0x03) { 346 | case 0x00: 347 | acp_seid(level, frm); 348 | case 0x02: 349 | capabilities(level, frm); 350 | break; 351 | case 0x03: 352 | errorcode(level, frm); 353 | break; 354 | } 355 | } 356 | 357 | static inline void reconfigure(int level, uint8_t hdr, struct frame *frm) 358 | { 359 | uint8_t cat; 360 | 361 | switch (hdr & 0x03) { 362 | case 0x00: 363 | acp_seid(level, frm); 364 | capabilities(level, frm); 365 | break; 366 | case 0x03: 367 | p_indent(level, frm); 368 | cat = get_u8(frm); 369 | printf("%s\n", cat2str(cat)); 370 | errorcode(level, frm); 371 | break; 372 | } 373 | } 374 | 375 | static inline void open_close_stream(int level, uint8_t hdr, struct frame *frm) 376 | { 377 | switch (hdr & 0x03) { 378 | case 0x00: 379 | acp_seid(level, frm); 380 | break; 381 | case 0x03: 382 | errorcode(level, frm); 383 | break; 384 | } 385 | } 386 | 387 | static inline void start_suspend_stream(int level, uint8_t hdr, struct frame *frm) 388 | { 389 | switch (hdr & 0x03) { 390 | case 0x00: 391 | while (frm->len > 0) 392 | acp_seid(level, frm); 393 | break; 394 | case 0x03: 395 | acp_seid(level, frm); 396 | errorcode(level, frm); 397 | break; 398 | } 399 | } 400 | 401 | static inline void abort_streaming(int level, uint8_t hdr, struct frame *frm) 402 | { 403 | switch (hdr & 0x03) { 404 | case 0x00: 405 | acp_seid(level, frm); 406 | break; 407 | } 408 | } 409 | 410 | static inline void security(int level, uint8_t hdr, struct frame *frm) 411 | { 412 | switch (hdr & 0x03) { 413 | case 0x00: 414 | acp_seid(level, frm); 415 | case 0x02: 416 | hex_dump(level + 1, frm, frm->len); 417 | frm->ptr += frm->len; 418 | frm->len = 0; 419 | break; 420 | case 0x03: 421 | errorcode(level, frm); 422 | break; 423 | } 424 | } 425 | 426 | static inline void delay_report(int level, uint8_t hdr, struct frame *frm) 427 | { 428 | uint8_t seid; 429 | uint16_t delay; 430 | 431 | switch (hdr & 0x03) { 432 | case 0x00: 433 | p_indent(level, frm); 434 | seid = get_u8(frm); 435 | delay = get_u16(frm); 436 | printf("ACP SEID %d delay %u.%ums\n", seid >> 2, 437 | delay / 10, delay % 10); 438 | break; 439 | case 0x03: 440 | errorcode(level, frm); 441 | break; 442 | } 443 | } 444 | 445 | void avdtp_dump(int level, struct frame *frm) 446 | { 447 | uint8_t hdr, sid, nsp, type; 448 | uint16_t seqn; 449 | uint32_t time, ssrc; 450 | 451 | switch (frm->num) { 452 | case 1: 453 | p_indent(level, frm); 454 | hdr = get_u8(frm); 455 | 456 | nsp = (hdr & 0x0c) == 0x04 ? get_u8(frm) : 0; 457 | sid = hdr & 0x08 ? 0x00 : get_u8(frm); 458 | 459 | printf("AVDTP(s): %s %s: transaction %d nsp 0x%02x\n", 460 | hdr & 0x08 ? pt2str(hdr) : si2str(sid), 461 | mt2str(hdr), hdr >> 4, nsp); 462 | 463 | switch (sid & 0x7f) { 464 | case 0x01: 465 | discover(level + 1, hdr, frm); 466 | break; 467 | case 0x02: 468 | case 0x0c: 469 | get_capabilities(level + 1, hdr, frm); 470 | break; 471 | case 0x03: 472 | set_configuration(level + 1, hdr, frm); 473 | break; 474 | case 0x04: 475 | get_configuration(level + 1, hdr, frm); 476 | break; 477 | case 0x05: 478 | reconfigure(level + 1, hdr, frm); 479 | break; 480 | case 0x06: 481 | open_close_stream(level + 1, hdr, frm); 482 | break; 483 | case 0x07: 484 | start_suspend_stream(level + 1, hdr, frm); 485 | break; 486 | case 0x08: 487 | open_close_stream(level + 1, hdr, frm); 488 | break; 489 | case 0x09: 490 | start_suspend_stream(level + 1, hdr, frm); 491 | break; 492 | case 0x0a: 493 | abort_streaming(level + 1, hdr, frm); 494 | break; 495 | case 0x0b: 496 | security(level + 1, hdr, frm); 497 | break; 498 | case 0x0d: 499 | delay_report(level + 1, hdr, frm); 500 | break; 501 | } 502 | 503 | break; 504 | 505 | case 2: 506 | p_indent(level, frm); 507 | hdr = get_u8(frm); 508 | type = get_u8(frm); 509 | seqn = get_u16(frm); 510 | time = get_u32(frm); 511 | ssrc = get_u32(frm); 512 | 513 | printf("AVDTP(m): ver %d %s%scc %d %spt %d seqn %d time %d ssrc %d\n", 514 | hdr >> 6, hdr & 0x20 ? "pad " : "", hdr & 0x10 ? "ext " : "", 515 | hdr & 0xf, type & 0x80 ? "mark " : "", type & 0x7f, seqn, time, ssrc); 516 | break; 517 | } 518 | 519 | raw_dump(level, frm); 520 | } 521 | -------------------------------------------------------------------------------- /jni/parser/bnep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2003 Takashi Sasai 6 | * Copyright (C) 2003-2011 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include 27 | #endif 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | #include "parser/parser.h" 38 | 39 | /* BNEP Type */ 40 | #define BNEP_GENERAL_ETHERNET 0x00 41 | #define BNEP_CONTROL 0x01 42 | #define BNEP_COMPRESSED_ETHERNET 0x02 43 | #define BNEP_COMPRESSED_ETHERNET_SOURCE_ONLY 0x03 44 | #define BNEP_COMPRESSED_ETHERNET_DEST_ONLY 0x04 45 | 46 | /* BNEP Control Packet Type */ 47 | #define BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD 0x00 48 | #define BNEP_SETUP_CONNECTION_REQUEST_MSG 0x01 49 | #define BNEP_SETUP_CONNECTION_RESPONSE_MSG 0x02 50 | #define BNEP_FILTER_NET_TYPE_SET_MSG 0x03 51 | #define BNEP_FILTER_NET_TYPE_RESPONSE_MSG 0x04 52 | #define BNEP_FILTER_MULT_ADDR_SET_MSG 0x05 53 | #define BNEP_FILTER_MULT_ADDR_RESPONSE_MSG 0x06 54 | 55 | /* BNEP Extension Type */ 56 | #define BNEP_EXTENSION_CONTROL 0x00 57 | 58 | #ifndef ETHERTYPE_IPV6 59 | #define ETHERTYPE_IPV6 ETH_P_IPV6 60 | #endif 61 | 62 | static char *get_macaddr(struct frame *frm) 63 | { 64 | static char str[20]; 65 | unsigned char *buf = frm->ptr; 66 | 67 | sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x", 68 | buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); 69 | 70 | frm->ptr += 6; 71 | frm->len -= 6; 72 | 73 | return str; 74 | } 75 | 76 | static void bnep_control(int level, struct frame *frm, int header_length) 77 | { 78 | uint8_t uuid_size; 79 | int i, length; 80 | char *s; 81 | uint32_t uuid = 0; 82 | uint8_t type = get_u8(frm); 83 | 84 | p_indent(++level, frm); 85 | switch (type) { 86 | case BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD: 87 | printf("Not Understood(0x%02x) type 0x%02x\n", type, get_u8(frm)); 88 | break; 89 | 90 | case BNEP_SETUP_CONNECTION_REQUEST_MSG: 91 | uuid_size = get_u8(frm); 92 | printf("Setup Req(0x%02x) size 0x%02x ", type, uuid_size); 93 | switch (uuid_size) { 94 | case 2: 95 | uuid = get_u16(frm); 96 | printf("dst 0x%x", uuid); 97 | if ((s = get_uuid_name(uuid)) != 0) 98 | printf("(%s)", s); 99 | uuid = get_u16(frm); 100 | printf(" src 0x%x", uuid); 101 | if ((s = get_uuid_name(uuid)) != 0) 102 | printf("(%s)", s); 103 | printf("\n"); 104 | break; 105 | case 4: 106 | uuid = get_u32(frm); 107 | printf("dst 0x%x", uuid); 108 | if ((s = get_uuid_name(uuid)) != 0) 109 | printf("(%s)", s); 110 | uuid = get_u32(frm); 111 | printf(" src 0x%x", uuid); 112 | if ((s = get_uuid_name(uuid)) != 0) 113 | printf("(%s)", s); 114 | printf("\n"); 115 | break; 116 | case 16: 117 | uuid = get_u32(frm); 118 | printf("dst 0x%x", uuid); 119 | if ((s = get_uuid_name(uuid)) != 0) 120 | printf("(%s)", s); 121 | frm->ptr += 12; 122 | frm->len -= 12; 123 | uuid = get_u32(frm); 124 | printf(" src 0x%x", uuid); 125 | if ((s = get_uuid_name(uuid)) != 0) 126 | printf("(%s)", s); 127 | printf("\n"); 128 | frm->ptr += 12; 129 | frm->len -= 12; 130 | break; 131 | default: 132 | frm->ptr += (uuid_size * 2); 133 | frm->len -= (uuid_size * 2); 134 | break; 135 | } 136 | break; 137 | 138 | case BNEP_SETUP_CONNECTION_RESPONSE_MSG: 139 | printf("Setup Rsp(0x%02x) res 0x%04x\n", 140 | type, get_u16(frm)); 141 | break; 142 | 143 | case BNEP_FILTER_NET_TYPE_SET_MSG: 144 | length = get_u16(frm); 145 | printf("Filter NetType Set(0x%02x) len 0x%04x\n", 146 | type, length); 147 | for (i = 0; i < length / 4; i++) { 148 | p_indent(level + 1, frm); 149 | printf("0x%04x - ", get_u16(frm)); 150 | printf("0x%04x\n", get_u16(frm)); 151 | } 152 | break; 153 | 154 | case BNEP_FILTER_NET_TYPE_RESPONSE_MSG: 155 | printf("Filter NetType Rsp(0x%02x) res 0x%04x\n", 156 | type, get_u16(frm)); 157 | break; 158 | 159 | case BNEP_FILTER_MULT_ADDR_SET_MSG: 160 | length = get_u16(frm); 161 | printf("Filter MultAddr Set(0x%02x) len 0x%04x\n", 162 | type, length); 163 | for (i = 0; i < length / 12; i++) { 164 | p_indent(level + 1, frm); 165 | printf("%s - ", get_macaddr(frm)); 166 | printf("%s\n", get_macaddr(frm)); 167 | } 168 | break; 169 | 170 | case BNEP_FILTER_MULT_ADDR_RESPONSE_MSG: 171 | printf("Filter MultAddr Rsp(0x%02x) res 0x%04x\n", 172 | type, get_u16(frm)); 173 | break; 174 | 175 | default: 176 | printf("Unknown control type(0x%02x)\n", type); 177 | raw_ndump(level + 1, frm, header_length - 1); 178 | frm->ptr += header_length - 1; 179 | frm->len -= header_length - 1; 180 | return; 181 | } 182 | } 183 | 184 | static void bnep_eval_extension(int level, struct frame *frm) 185 | { 186 | uint8_t type = get_u8(frm); 187 | uint8_t length = get_u8(frm); 188 | int extension = type & 0x80; 189 | 190 | p_indent(level, frm); 191 | 192 | switch (type & 0x7f) { 193 | case BNEP_EXTENSION_CONTROL: 194 | printf("Ext Control(0x%02x|%s) len 0x%02x\n", 195 | type & 0x7f, extension ? "1" : "0", length); 196 | bnep_control(level, frm, length); 197 | break; 198 | 199 | default: 200 | printf("Ext Unknown(0x%02x|%s) len 0x%02x\n", 201 | type & 0x7f, extension ? "1" : "0", length); 202 | raw_ndump(level + 1, frm, length); 203 | frm->ptr += length; 204 | frm->len -= length; 205 | } 206 | 207 | if (extension) 208 | bnep_eval_extension(level, frm); 209 | } 210 | 211 | void bnep_dump(int level, struct frame *frm) 212 | { 213 | uint8_t type = get_u8(frm); 214 | uint16_t proto = 0x0000; 215 | int extension = type & 0x80; 216 | 217 | p_indent(level, frm); 218 | 219 | switch (type & 0x7f) { 220 | case BNEP_CONTROL: 221 | printf("BNEP: Control(0x%02x|%s)\n", 222 | type & 0x7f, extension ? "1" : "0"); 223 | bnep_control(level, frm, -1); 224 | break; 225 | 226 | case BNEP_COMPRESSED_ETHERNET: 227 | printf("BNEP: Compressed(0x%02x|%s)\n", 228 | type & 0x7f, extension ? "1" : "0"); 229 | p_indent(++level, frm); 230 | proto = get_u16(frm); 231 | printf("[proto 0x%04x]\n", proto); 232 | break; 233 | 234 | case BNEP_GENERAL_ETHERNET: 235 | printf("BNEP: General ethernet(0x%02x|%s)\n", 236 | type & 0x7f, extension ? "1" : "0"); 237 | p_indent(++level, frm); 238 | printf("dst %s ", get_macaddr(frm)); 239 | printf("src %s ", get_macaddr(frm)); 240 | proto = get_u16(frm); 241 | printf("[proto 0x%04x]\n", proto); 242 | break; 243 | 244 | case BNEP_COMPRESSED_ETHERNET_DEST_ONLY: 245 | printf("BNEP: Compressed DestOnly(0x%02x|%s)\n", 246 | type & 0x7f, extension ? "1" : "0"); 247 | p_indent(++level, frm); 248 | printf("dst %s ", get_macaddr(frm)); 249 | proto = get_u16(frm); 250 | printf("[proto 0x%04x]\n", proto); 251 | break; 252 | 253 | case BNEP_COMPRESSED_ETHERNET_SOURCE_ONLY: 254 | printf("BNEP: Compressed SrcOnly(0x%02x|%s)\n", 255 | type & 0x7f, extension ? "1" : "0"); 256 | p_indent(++level, frm); 257 | printf("src %s ", get_macaddr(frm)); 258 | proto = get_u16(frm); 259 | printf("[proto 0x%04x]\n", proto); 260 | break; 261 | 262 | default: 263 | printf("(Unknown packet type)\n"); 264 | return; 265 | } 266 | 267 | /* Extension info */ 268 | if (extension) 269 | bnep_eval_extension(++level, frm); 270 | 271 | /* Control packet => No payload info */ 272 | if ((type & 0x7f) == BNEP_CONTROL) 273 | return; 274 | 275 | /* 802.1p header */ 276 | if (proto == 0x8100) { 277 | p_indent(level, frm); 278 | printf("802.1p Header: 0x%04x ", get_u16(frm)); 279 | proto = get_u16(frm); 280 | printf("[proto 0x%04x]\n", proto); 281 | } 282 | 283 | if (!(parser.flags & DUMP_VERBOSE)) { 284 | raw_dump(level, frm); 285 | return; 286 | } 287 | 288 | switch (proto) { 289 | case ETHERTYPE_ARP: 290 | p_indent(++level, frm); 291 | printf("ARP: "); 292 | arp_dump(level, frm); 293 | break; 294 | 295 | case ETHERTYPE_REVARP: 296 | p_indent(++level, frm); 297 | printf("RARP: "); 298 | arp_dump(level, frm); 299 | break; 300 | 301 | case ETHERTYPE_IP: 302 | p_indent(++level, frm); 303 | printf("IP: "); 304 | ip_dump(level, frm); 305 | break; 306 | 307 | case ETHERTYPE_IPV6: 308 | p_indent(++level, frm); 309 | printf("IPV6: "); 310 | ip_dump(level, frm); 311 | break; 312 | 313 | default: 314 | raw_dump(level, frm); 315 | break; 316 | } 317 | } 318 | -------------------------------------------------------------------------------- /jni/parser/bpa.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | #define BPA_U8(frm) (get_u8(frm)) 37 | #define BPA_U16(frm) (btohs(htons(get_u16(frm)))) 38 | #define BPA_U32(frm) (btohl(htonl(get_u32(frm)))) 39 | 40 | void bpa_dump(int level, struct frame *frm) 41 | { 42 | uint8_t id, status, channel; 43 | uint16_t num, len; 44 | uint32_t time; 45 | 46 | id = get_u8(frm); 47 | num = get_u16(frm); 48 | len = BPA_U16(frm); 49 | 50 | status = get_u8(frm); 51 | time = get_u32(frm); 52 | channel = get_u8(frm); 53 | 54 | p_indent(level, frm); 55 | printf("BPA: id %d num %d len %u status 0x%02x time %d channel %d\n", 56 | id, num, len, status, time, channel); 57 | 58 | raw_dump(level, frm); 59 | } 60 | -------------------------------------------------------------------------------- /jni/parser/cmtp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2002-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | #define TABLE_SIZE 10 37 | 38 | static struct { 39 | uint16_t handle; 40 | uint16_t cid; 41 | struct frame msg[16]; 42 | } table[TABLE_SIZE]; 43 | 44 | static void add_segment(uint8_t bid, struct frame *frm, int len) 45 | { 46 | uint16_t handle = frm->handle, cid = frm->cid; 47 | struct frame *msg; 48 | void *data; 49 | int i, pos = -1; 50 | 51 | if (bid > 15) 52 | return; 53 | 54 | for (i = 0; i < TABLE_SIZE; i++) { 55 | if (table[i].handle == handle && table[i].cid == cid) { 56 | pos = i; 57 | break; 58 | } 59 | 60 | if (pos < 0 && !table[i].handle && !table[i].cid) 61 | pos = i; 62 | } 63 | 64 | if (pos < 0) 65 | return; 66 | 67 | table[pos].handle = handle; 68 | table[pos].cid = cid; 69 | msg = &table[pos].msg[bid]; 70 | 71 | data = malloc(msg->data_len + len); 72 | if (!data) 73 | return; 74 | 75 | if (msg->data_len > 0) 76 | memcpy(data, msg->data, msg->data_len); 77 | 78 | memcpy(data + msg->data_len, frm->ptr, len); 79 | free(msg->data); 80 | msg->data = data; 81 | msg->data_len += len; 82 | msg->ptr = msg->data; 83 | msg->len = msg->data_len; 84 | msg->in = frm->in; 85 | msg->ts = frm->ts; 86 | msg->handle = handle; 87 | msg->cid = cid; 88 | } 89 | 90 | static void free_segment(uint8_t bid, struct frame *frm) 91 | { 92 | uint16_t handle = frm->handle, cid = frm->cid; 93 | struct frame *msg; 94 | int i, len = 0, pos = -1; 95 | 96 | if (bid > 15) 97 | return; 98 | 99 | for (i = 0; i < TABLE_SIZE; i++) 100 | if (table[i].handle == handle && table[i].cid == cid) { 101 | pos = i; 102 | break; 103 | } 104 | 105 | if (pos < 0) 106 | return; 107 | 108 | msg = &table[pos].msg[bid]; 109 | 110 | if (msg->data) 111 | free(msg->data); 112 | 113 | msg->data = NULL; 114 | msg->data_len = 0; 115 | 116 | for (i = 0; i < 16; i++) 117 | len += table[pos].msg[i].data_len; 118 | 119 | if (!len) { 120 | table[pos].handle = 0; 121 | table[pos].cid = 0; 122 | } 123 | } 124 | 125 | static struct frame *get_segment(uint8_t bid, struct frame *frm) 126 | { 127 | uint16_t handle = frm->handle, cid = frm->cid; 128 | int i; 129 | 130 | if (bid > 15) 131 | return NULL; 132 | 133 | for (i = 0; i < TABLE_SIZE; i++) 134 | if (table[i].handle == handle && table[i].cid == cid) 135 | return &table[i].msg[bid]; 136 | 137 | return NULL; 138 | } 139 | 140 | static char *bst2str(uint8_t bst) 141 | { 142 | switch (bst) { 143 | case 0x00: 144 | return "complete CAPI Message"; 145 | case 0x01: 146 | return "segmented CAPI Message"; 147 | case 0x02: 148 | return "error"; 149 | case 0x03: 150 | return "reserved"; 151 | default: 152 | return "unknown"; 153 | } 154 | } 155 | 156 | void cmtp_dump(int level, struct frame *frm) 157 | { 158 | struct frame *msg; 159 | uint8_t hdr, bid; 160 | uint16_t len; 161 | 162 | while (frm->len > 0) { 163 | 164 | hdr = get_u8(frm); 165 | bid = (hdr & 0x3c) >> 2; 166 | 167 | switch ((hdr & 0xc0) >> 6) { 168 | case 0x01: 169 | len = get_u8(frm); 170 | break; 171 | case 0x02: 172 | len = htons(get_u16(frm)); 173 | break; 174 | default: 175 | len = 0; 176 | break; 177 | } 178 | 179 | p_indent(level, frm); 180 | 181 | printf("CMTP: %s: id %d len %d\n", bst2str(hdr & 0x03), bid, len); 182 | 183 | switch (hdr & 0x03) { 184 | case 0x00: 185 | add_segment(bid, frm, len); 186 | msg = get_segment(bid, frm); 187 | if (!msg) 188 | break; 189 | 190 | if (!p_filter(FILT_CAPI)) 191 | capi_dump(level + 1, msg); 192 | else 193 | raw_dump(level, msg); 194 | 195 | free_segment(bid, frm); 196 | break; 197 | case 0x01: 198 | add_segment(bid, frm, len); 199 | break; 200 | default: 201 | free_segment(bid, frm); 202 | break; 203 | } 204 | 205 | frm->ptr += len; 206 | frm->len -= len; 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /jni/parser/csr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | #define CSR_U8(frm) (get_u8(frm)) 37 | #define CSR_U16(frm) (btohs(htons(get_u16(frm)))) 38 | #define CSR_U32(frm) ((CSR_U16(frm) << 16) + CSR_U16(frm)) 39 | #define CSR_S16(frm) (btohs(htons(get_u16(frm)))) 40 | 41 | static char *type2str(uint16_t type) 42 | { 43 | switch (type) { 44 | case 0x0000: 45 | return "Get req"; 46 | case 0x0001: 47 | return "Get rsp"; 48 | case 0x0002: 49 | return "Set req"; 50 | default: 51 | return "Reserved"; 52 | } 53 | } 54 | 55 | static inline void valueless_dump(int level, char *str, struct frame *frm) 56 | { 57 | p_indent(level, frm); 58 | printf("%s\n", str); 59 | } 60 | 61 | static inline void complex_dump(int level, char *str, struct frame *frm) 62 | { 63 | p_indent(level, frm); 64 | printf("%s\n", str); 65 | 66 | raw_dump(level, frm); 67 | } 68 | 69 | static inline void bool_dump(int level, char *str, struct frame *frm) 70 | { 71 | uint16_t value; 72 | 73 | value = CSR_U16(frm); 74 | 75 | p_indent(level, frm); 76 | printf("%s: value %s (%d)\n", str, value ? "TRUE" : "FALSE", value); 77 | } 78 | 79 | static inline void int8_dump(int level, char *str, struct frame *frm) 80 | { 81 | int16_t value; 82 | 83 | value = CSR_S16(frm); 84 | 85 | p_indent(level, frm); 86 | printf("%s: value %d (0x%2.2x)\n", str, value, value); 87 | } 88 | 89 | static inline void int16_dump(int level, char *str, struct frame *frm) 90 | { 91 | int16_t value; 92 | 93 | value = CSR_S16(frm); 94 | 95 | p_indent(level, frm); 96 | printf("%s: value %d (0x%2.2x)\n", str, value, value); 97 | } 98 | 99 | static inline void uint16_dump(int level, char *str, struct frame *frm) 100 | { 101 | uint16_t value; 102 | 103 | value = CSR_U16(frm); 104 | 105 | p_indent(level, frm); 106 | printf("%s: value %d (0x%4.4x)\n", str, value, value); 107 | } 108 | 109 | static inline void uint32_dump(int level, char *str, struct frame *frm) 110 | { 111 | uint32_t value; 112 | 113 | value = CSR_U32(frm); 114 | 115 | p_indent(level, frm); 116 | printf("%s: value %d (0x%4.4x)\n", str, value, value); 117 | } 118 | 119 | static inline void bdaddr_dump(int level, char *str, struct frame *frm) 120 | { 121 | char addr[18]; 122 | 123 | p_ba2str(frm->ptr, addr); 124 | 125 | p_indent(level, frm); 126 | printf("%s: bdaddr %s\n", str, addr); 127 | } 128 | 129 | static inline void features_dump(int level, char *str, struct frame *frm) 130 | { 131 | unsigned char features[8]; 132 | int i; 133 | 134 | memcpy(features, frm->ptr, 8); 135 | 136 | p_indent(level, frm); 137 | printf("%s: features", str); 138 | for (i = 0; i < 8; i++) 139 | printf(" 0x%02x", features[i]); 140 | printf("\n"); 141 | } 142 | 143 | static inline void commands_dump(int level, char *str, struct frame *frm) 144 | { 145 | unsigned char commands[64]; 146 | unsigned int i; 147 | 148 | memcpy(commands, frm->ptr, frm->len); 149 | 150 | p_indent(level, frm); 151 | printf("%s: commands", str); 152 | for (i = 0; i < frm->len; i++) 153 | printf(" 0x%02x", commands[i]); 154 | printf("\n"); 155 | } 156 | 157 | static inline void handle_length_dump(int level, char *str, struct frame *frm) 158 | { 159 | uint16_t handle, length; 160 | 161 | handle = CSR_U16(frm); 162 | length = CSR_U16(frm); 163 | 164 | p_indent(level, frm); 165 | printf("%s: handle %d length %d\n", str, handle, length); 166 | } 167 | 168 | static inline void handle_clock_dump(int level, char *str, struct frame *frm) 169 | { 170 | uint16_t handle; 171 | uint32_t clock; 172 | 173 | handle = CSR_U16(frm); 174 | clock = CSR_U32(frm); 175 | 176 | p_indent(level, frm); 177 | printf("%s: handle %d clock 0x%4.4x\n", str, handle, clock); 178 | } 179 | 180 | static inline void radiotest_dump(int level, char *str, struct frame *frm) 181 | { 182 | uint16_t testid; 183 | 184 | testid = CSR_U16(frm); 185 | 186 | p_indent(level, frm); 187 | printf("%s: test id %d\n", str, testid); 188 | 189 | raw_dump(level, frm); 190 | } 191 | 192 | static inline void psmemtype_dump(int level, char *str, struct frame *frm) 193 | { 194 | uint16_t store, type; 195 | 196 | store = CSR_U16(frm); 197 | type = CSR_U16(frm); 198 | 199 | p_indent(level, frm); 200 | printf("%s: store 0x%4.4x type %d\n", str, store, type); 201 | } 202 | 203 | static inline void psnext_dump(int level, char *str, struct frame *frm) 204 | { 205 | uint16_t key, stores, next; 206 | 207 | key = CSR_U16(frm); 208 | stores = CSR_U16(frm); 209 | next = CSR_U16(frm); 210 | 211 | p_indent(level, frm); 212 | printf("%s: key 0x%4.4x stores 0x%4.4x next 0x%4.4x\n", str, key, stores, next); 213 | } 214 | 215 | static inline void pssize_dump(int level, char *str, struct frame *frm) 216 | { 217 | uint16_t key, length; 218 | 219 | key = CSR_U16(frm); 220 | length = CSR_U16(frm); 221 | 222 | p_indent(level, frm); 223 | printf("%s: key 0x%4.4x %s 0x%4.4x\n", str, key, 224 | frm->in ? "len" : "stores", length); 225 | } 226 | 227 | static inline void psstores_dump(int level, char *str, struct frame *frm) 228 | { 229 | uint16_t key, stores; 230 | 231 | key = CSR_U16(frm); 232 | stores = CSR_U16(frm); 233 | 234 | p_indent(level, frm); 235 | printf("%s: key 0x%4.4x stores 0x%4.4x\n", str, key, stores); 236 | } 237 | 238 | static inline void pskey_dump(int level, struct frame *frm) 239 | { 240 | uint16_t key, length, stores; 241 | 242 | key = CSR_U16(frm); 243 | length = CSR_U16(frm); 244 | stores = CSR_U16(frm); 245 | 246 | p_indent(level, frm); 247 | printf("PSKEY: key 0x%4.4x len %d stores 0x%4.4x\n", key, length, stores); 248 | 249 | switch (key) { 250 | case 0x0001: 251 | bdaddr_dump(level + 1, "BDADDR", frm); 252 | break; 253 | case 0x0002: 254 | uint16_dump(level + 1, "COUNTRYCODE", frm); 255 | break; 256 | case 0x0003: 257 | uint32_dump(level + 1, "CLASSOFDEVICE", frm); 258 | break; 259 | case 0x0004: 260 | uint16_dump(level + 1, "DEVICE_DRIFT", frm); 261 | break; 262 | case 0x0005: 263 | uint16_dump(level + 1, "DEVICE_JITTER", frm); 264 | break; 265 | case 0x000d: 266 | uint16_dump(level + 1, "MAX_ACLS", frm); 267 | break; 268 | case 0x000e: 269 | uint16_dump(level + 1, "MAX_SCOS", frm); 270 | break; 271 | case 0x000f: 272 | uint16_dump(level + 1, "MAX_REMOTE_MASTERS", frm); 273 | break; 274 | case 0x00da: 275 | uint16_dump(level + 1, "ENC_KEY_LMIN", frm); 276 | break; 277 | case 0x00db: 278 | uint16_dump(level + 1, "ENC_KEY_LMAX", frm); 279 | break; 280 | case 0x00ef: 281 | features_dump(level + 1, "LOCAL_SUPPORTED_FEATURES", frm); 282 | break; 283 | case 0x0106: 284 | commands_dump(level + 1, "LOCAL_SUPPORTED_COMMANDS", frm); 285 | break; 286 | case 0x010d: 287 | uint16_dump(level + 1, "HCI_LMP_LOCAL_VERSION", frm); 288 | break; 289 | case 0x010e: 290 | uint16_dump(level + 1, "LMP_REMOTE_VERSION", frm); 291 | break; 292 | case 0x01a5: 293 | bool_dump(level + 1, "HOSTIO_USE_HCI_EXTN", frm); 294 | break; 295 | case 0x01ab: 296 | bool_dump(level + 1, "HOSTIO_MAP_SCO_PCM", frm); 297 | break; 298 | case 0x01be: 299 | uint16_dump(level + 1, "UART_BAUDRATE", frm); 300 | break; 301 | case 0x01f6: 302 | uint16_dump(level + 1, "ANA_FTRIM", frm); 303 | break; 304 | case 0x01f9: 305 | uint16_dump(level + 1, "HOST_INTERFACE", frm); 306 | break; 307 | case 0x01fe: 308 | uint16_dump(level + 1, "ANA_FREQ", frm); 309 | break; 310 | case 0x02be: 311 | uint16_dump(level + 1, "USB_VENDOR_ID", frm); 312 | break; 313 | case 0x02bf: 314 | uint16_dump(level + 1, "USB_PRODUCT_ID", frm); 315 | break; 316 | case 0x02cb: 317 | uint16_dump(level + 1, "USB_DFU_PRODUCT_ID", frm); 318 | break; 319 | case 0x03cd: 320 | int16_dump(level + 1, "INITIAL_BOOTMODE", frm); 321 | break; 322 | default: 323 | raw_dump(level + 1, frm); 324 | break; 325 | } 326 | } 327 | 328 | static inline void bccmd_dump(int level, struct frame *frm) 329 | { 330 | uint16_t type, length, seqno, varid, status; 331 | 332 | type = CSR_U16(frm); 333 | length = CSR_U16(frm); 334 | seqno = CSR_U16(frm); 335 | varid = CSR_U16(frm); 336 | status = CSR_U16(frm); 337 | 338 | p_indent(level, frm); 339 | printf("BCCMD: %s: len %d seqno %d varid 0x%4.4x status %d\n", 340 | type2str(type), length, seqno, varid, status); 341 | 342 | if (!(parser.flags & DUMP_VERBOSE)) { 343 | raw_dump(level + 1, frm); 344 | return; 345 | } 346 | 347 | switch (varid) { 348 | case 0x000b: 349 | valueless_dump(level + 1, "PS_CLR_ALL", frm); 350 | break; 351 | case 0x000c: 352 | valueless_dump(level + 1, "PS_FACTORY_SET", frm); 353 | break; 354 | case 0x082d: 355 | uint16_dump(level + 1, "PS_CLR_ALL_STORES", frm); 356 | break; 357 | case 0x2801: 358 | uint16_dump(level + 1, "BC01_STATUS", frm); 359 | break; 360 | case 0x2819: 361 | uint16_dump(level + 1, "BUILDID", frm); 362 | break; 363 | case 0x281a: 364 | uint16_dump(level + 1, "CHIPVER", frm); 365 | break; 366 | case 0x281b: 367 | uint16_dump(level + 1, "CHIPREV", frm); 368 | break; 369 | case 0x2825: 370 | uint16_dump(level + 1, "INTERFACE_VERSION", frm); 371 | break; 372 | case 0x282a: 373 | uint16_dump(level + 1, "RAND", frm); 374 | break; 375 | case 0x282c: 376 | uint16_dump(level + 1, "MAX_CRYPT_KEY_LENGTH", frm); 377 | break; 378 | case 0x2833: 379 | uint16_dump(level + 1, "E2_APP_SIZE", frm); 380 | break; 381 | case 0x2836: 382 | uint16_dump(level + 1, "CHIPANAREV", frm); 383 | break; 384 | case 0x2838: 385 | uint16_dump(level + 1, "BUILDID_LOADER", frm); 386 | break; 387 | case 0x2c00: 388 | uint32_dump(level + 1, "BT_CLOCK", frm); 389 | break; 390 | case 0x3005: 391 | psnext_dump(level + 1, "PS_NEXT", frm); 392 | break; 393 | case 0x3006: 394 | pssize_dump(level + 1, "PS_SIZE", frm); 395 | break; 396 | case 0x3008: 397 | handle_length_dump(level + 1, "CRYPT_KEY_LENGTH", frm); 398 | break; 399 | case 0x3009: 400 | handle_clock_dump(level + 1, "PICONET_INSTANCE", frm); 401 | break; 402 | case 0x300a: 403 | complex_dump(level + 1, "GET_CLR_EVT", frm); 404 | break; 405 | case 0x300b: 406 | complex_dump(level + 1, "GET_NEXT_BUILDDEF", frm); 407 | break; 408 | case 0x300e: 409 | complex_dump(level + 1, "E2_DEVICE", frm); 410 | break; 411 | case 0x300f: 412 | complex_dump(level + 1, "E2_APP_DATA", frm); 413 | break; 414 | case 0x3012: 415 | psmemtype_dump(level + 1, "PS_MEMORY_TYPE", frm); 416 | break; 417 | case 0x301c: 418 | complex_dump(level + 1, "READ_BUILD_NAME", frm); 419 | break; 420 | case 0x4001: 421 | valueless_dump(level + 1, "COLD_RESET", frm); 422 | break; 423 | case 0x4002: 424 | valueless_dump(level + 1, "WARM_RESET", frm); 425 | break; 426 | case 0x4003: 427 | valueless_dump(level + 1, "COLD_HALT", frm); 428 | break; 429 | case 0x4004: 430 | valueless_dump(level + 1, "WARM_HALT", frm); 431 | break; 432 | case 0x4005: 433 | valueless_dump(level + 1, "INIT_BT_STACK", frm); 434 | break; 435 | case 0x4006: 436 | valueless_dump(level + 1, "ACTIVATE_BT_STACK", frm); 437 | break; 438 | case 0x4007: 439 | valueless_dump(level + 1, "ENABLE_TX", frm); 440 | break; 441 | case 0x4008: 442 | valueless_dump(level + 1, "DISABLE_TX", frm); 443 | break; 444 | case 0x4009: 445 | valueless_dump(level + 1, "RECAL", frm); 446 | break; 447 | case 0x400d: 448 | valueless_dump(level + 1, "PS_FACTORY_RESTORE", frm); 449 | break; 450 | case 0x400e: 451 | valueless_dump(level + 1, "PS_FACTORY_RESTORE_ALL", frm); 452 | break; 453 | case 0x400f: 454 | valueless_dump(level + 1, "PS_DEFRAG_RESET", frm); 455 | break; 456 | case 0x4011: 457 | valueless_dump(level + 1, "HOPPING_ON", frm); 458 | break; 459 | case 0x4012: 460 | valueless_dump(level + 1, "CANCEL_PAGE", frm); 461 | break; 462 | case 0x4818: 463 | uint16_dump(level + 1, "PS_CLR", frm); 464 | break; 465 | case 0x481c: 466 | uint16_dump(level + 1, "MAP_SCO_PCM", frm); 467 | break; 468 | case 0x482e: 469 | uint16_dump(level + 1, "SINGLE_CHAN", frm); 470 | break; 471 | case 0x5004: 472 | radiotest_dump(level + 1, "RADIOTEST", frm); 473 | break; 474 | case 0x500c: 475 | psstores_dump(level + 1, "PS_CLR_STORES", frm); 476 | break; 477 | case 0x6000: 478 | valueless_dump(level + 1, "NO_VARIABLE", frm); 479 | break; 480 | case 0x6802: 481 | uint16_dump(level + 1, "CONFIG_UART", frm); 482 | break; 483 | case 0x6805: 484 | uint16_dump(level + 1, "PANIC_ARG", frm); 485 | break; 486 | case 0x6806: 487 | uint16_dump(level + 1, "FAULT_ARG", frm); 488 | break; 489 | case 0x6827: 490 | int8_dump(level + 1, "MAX_TX_POWER", frm); 491 | break; 492 | case 0x682b: 493 | int8_dump(level + 1, "DEFAULT_TX_POWER", frm); 494 | break; 495 | case 0x7003: 496 | pskey_dump(level + 1, frm); 497 | break; 498 | default: 499 | raw_dump(level + 1, frm); 500 | break; 501 | } 502 | } 503 | 504 | static char *cid2str(uint8_t cid) 505 | { 506 | switch (cid & 0x3f) { 507 | case 0: 508 | return "BCSP Internal"; 509 | case 1: 510 | return "BCSP Link"; 511 | case 2: 512 | return "BCCMD"; 513 | case 3: 514 | return "HQ"; 515 | case 4: 516 | return "Device Mgt"; 517 | case 5: 518 | return "HCI Cmd/Evt"; 519 | case 6: 520 | return "HCI ACL"; 521 | case 7: 522 | return "HCI SCO"; 523 | case 8: 524 | return "L2CAP"; 525 | case 9: 526 | return "RFCOMM"; 527 | case 10: 528 | return "SDP"; 529 | case 11: 530 | return "Debug"; 531 | case 12: 532 | return "DFU"; 533 | case 13: 534 | return "VM"; 535 | case 14: 536 | return "Unused"; 537 | case 15: 538 | return "Reserved"; 539 | default: 540 | return "Unknown"; 541 | } 542 | } 543 | 544 | static char *frag2str(uint8_t frag) 545 | { 546 | switch (frag & 0xc0) { 547 | case 0x00: 548 | return " middle fragment"; 549 | case 0x40: 550 | return " first fragment"; 551 | case 0x80: 552 | return " last fragment"; 553 | default: 554 | return ""; 555 | } 556 | } 557 | 558 | void csr_dump(int level, struct frame *frm) 559 | { 560 | uint8_t desc, cid, type; 561 | uint16_t handle, master, addr; 562 | 563 | desc = CSR_U8(frm); 564 | 565 | cid = desc & 0x3f; 566 | 567 | switch (cid) { 568 | case 2: 569 | bccmd_dump(level, frm); 570 | break; 571 | 572 | case 20: 573 | type = CSR_U8(frm); 574 | 575 | if (!p_filter(FILT_LMP)) { 576 | switch (type) { 577 | case 0x0f: 578 | frm->handle = ((uint8_t *) frm->ptr)[17]; 579 | frm->master = 0; 580 | frm->len--; 581 | lmp_dump(level, frm); 582 | return; 583 | case 0x10: 584 | frm->handle = ((uint8_t *) frm->ptr)[17]; 585 | frm->master = 1; 586 | frm->len--; 587 | lmp_dump(level, frm); 588 | return; 589 | case 0x12: 590 | handle = CSR_U16(frm); 591 | master = CSR_U16(frm); 592 | addr = CSR_U16(frm); 593 | p_indent(level, frm); 594 | printf("FHS: handle %d addr %d (%s)\n", handle, 595 | addr, master ? "master" : "slave"); 596 | if (!master) { 597 | char addr[18]; 598 | p_ba2str((bdaddr_t *) frm->ptr, addr); 599 | p_indent(level + 1, frm); 600 | printf("bdaddr %s class " 601 | "0x%2.2x%2.2x%2.2x\n", addr, 602 | ((uint8_t *) frm->ptr)[8], 603 | ((uint8_t *) frm->ptr)[7], 604 | ((uint8_t *) frm->ptr)[6]); 605 | } 606 | return; 607 | case 0x7b: 608 | p_indent(level, frm); 609 | printf("LMP(r): duplicate (same SEQN)\n"); 610 | return; 611 | } 612 | } 613 | 614 | p_indent(level, frm); 615 | printf("CSR: Debug (type 0x%2.2x)\n", type); 616 | raw_dump(level, frm); 617 | break; 618 | 619 | default: 620 | p_indent(level, frm); 621 | printf("CSR: %s (channel %d)%s\n", cid2str(cid), cid, frag2str(desc)); 622 | raw_dump(level, frm); 623 | break; 624 | } 625 | } 626 | -------------------------------------------------------------------------------- /jni/parser/ericsson.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | 31 | #include "parser/parser.h" 32 | 33 | void ericsson_dump(int level, struct frame *frm) 34 | { 35 | uint8_t event = get_u8(frm); 36 | uint8_t *buf = (uint8_t *) frm->ptr; 37 | 38 | if (event != 0x10) { 39 | p_indent(level, frm); 40 | printf("Ericsson: event 0x%2.2x\n", event); 41 | raw_dump(level, frm); 42 | } 43 | 44 | frm->master = !(buf[0] & 0x01); 45 | frm->handle = buf[1] | (buf[2] << 8); 46 | 47 | buf[5] = (buf[5] << 1) | (buf[3] & 0x01); 48 | 49 | frm->ptr += 5; 50 | frm->len -= 5; 51 | 52 | lmp_dump(level, frm); 53 | } 54 | -------------------------------------------------------------------------------- /jni/parser/hcrp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | static char *pid2str(uint16_t pid) 37 | { 38 | switch (pid) { 39 | case 0x0001: 40 | return "CreditGrant"; 41 | case 0x0002: 42 | return "CreditRequest"; 43 | case 0x0003: 44 | return "CreditReturn"; 45 | case 0x0004: 46 | return "CreditQuery"; 47 | case 0x0005: 48 | return "GetLPTStatus"; 49 | case 0x0006: 50 | return "Get1284ID"; 51 | case 0x0007: 52 | return "SoftReset"; 53 | case 0x0008: 54 | return "HardRest"; 55 | case 0x0009: 56 | return "RegisterNotification"; 57 | case 0x000A: 58 | return "NotificationConnectionAlive"; 59 | default: 60 | return "Reserved"; 61 | } 62 | } 63 | 64 | static char *status2str(uint16_t status) 65 | { 66 | switch (status) { 67 | case 0x0000: 68 | return "Feature unsupported"; 69 | case 0x0001: 70 | return "Success"; 71 | case 0x0002: 72 | return "Credit synchronization error"; 73 | case 0xFFFF: 74 | return "Generic error"; 75 | default: 76 | return "Unknown"; 77 | } 78 | } 79 | 80 | void hcrp_dump(int level, struct frame *frm) 81 | { 82 | uint16_t pid, tid, plen, status; 83 | uint32_t credits; 84 | 85 | pid = get_u16(frm); 86 | tid = get_u16(frm); 87 | plen = get_u16(frm); 88 | 89 | p_indent(level, frm); 90 | 91 | printf("HCRP %s %s: tid 0x%x plen %d", 92 | pid2str(pid), frm->in ? "rsp" : "cmd", tid, plen); 93 | 94 | if (frm->in) { 95 | status = get_u16(frm); 96 | printf(" status %d (%s)\n", status, status2str(status)); 97 | } else 98 | printf("\n"); 99 | 100 | if (pid == 0x0001 && !frm->in) { 101 | credits = get_u32(frm); 102 | p_indent(level + 1, frm); 103 | printf("credits %d\n", credits); 104 | } 105 | 106 | if (pid == 0x0002 && frm->in) { 107 | credits = get_u32(frm); 108 | p_indent(level + 1, frm); 109 | printf("credits %d\n", credits); 110 | } 111 | 112 | raw_dump(level + 1, frm); 113 | } 114 | -------------------------------------------------------------------------------- /jni/parser/hidp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2003-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | static char *type2str(uint8_t head) 37 | { 38 | switch (head & 0xf0) { 39 | case 0x00: 40 | return "Handshake"; 41 | case 0x10: 42 | return "Control"; 43 | case 0x40: 44 | return "Get report"; 45 | case 0x50: 46 | return "Set report"; 47 | case 0x60: 48 | return "Get protocol"; 49 | case 0x70: 50 | return "Set protocol"; 51 | case 0x80: 52 | return "Get idle"; 53 | case 0x90: 54 | return "Set idle"; 55 | case 0xa0: 56 | return "Data"; 57 | case 0xb0: 58 | return "Data continuation"; 59 | default: 60 | return "Reserved"; 61 | } 62 | } 63 | 64 | static char *result2str(uint8_t head) 65 | { 66 | switch (head & 0x0f) { 67 | case 0x00: 68 | return "Successful"; 69 | case 0x01: 70 | return "Not ready"; 71 | case 0x02: 72 | return "Invalid report ID"; 73 | case 0x03: 74 | return "Unsupported request"; 75 | case 0x04: 76 | return "Invalid parameter"; 77 | case 0x0e: 78 | return "Unknown"; 79 | case 0x0f: 80 | return "Fatal"; 81 | default: 82 | return "Reserved"; 83 | } 84 | } 85 | 86 | static char *operation2str(uint8_t head) 87 | { 88 | switch (head & 0x0f) { 89 | case 0x00: 90 | return "No operation"; 91 | case 0x01: 92 | return "Hard reset"; 93 | case 0x02: 94 | return "Soft reset"; 95 | case 0x03: 96 | return "Suspend"; 97 | case 0x04: 98 | return "Exit suspend"; 99 | case 0x05: 100 | return "Virtual cable unplug"; 101 | default: 102 | return "Reserved"; 103 | } 104 | } 105 | 106 | static char *report2str(uint8_t head) 107 | { 108 | switch (head & 0x03) { 109 | case 0x00: 110 | return "Other report"; 111 | case 0x01: 112 | return "Input report"; 113 | case 0x02: 114 | return "Output report"; 115 | case 0x03: 116 | return "Feature report"; 117 | default: 118 | return "Reserved"; 119 | } 120 | } 121 | 122 | static char *protocol2str(uint8_t head) 123 | { 124 | switch (head & 0x01) { 125 | case 0x00: 126 | return "Boot protocol"; 127 | case 0x01: 128 | return "Report protocol"; 129 | default: 130 | return "Reserved"; 131 | } 132 | } 133 | 134 | void hidp_dump(int level, struct frame *frm) 135 | { 136 | uint8_t hdr; 137 | char *param; 138 | 139 | hdr = get_u8(frm); 140 | 141 | switch (hdr & 0xf0) { 142 | case 0x00: 143 | param = result2str(hdr); 144 | break; 145 | case 0x10: 146 | param = operation2str(hdr); 147 | break; 148 | case 0x60: 149 | case 0x70: 150 | param = protocol2str(hdr); 151 | break; 152 | case 0x40: 153 | case 0x50: 154 | case 0xa0: 155 | case 0xb0: 156 | param = report2str(hdr); 157 | break; 158 | default: 159 | param = ""; 160 | break; 161 | } 162 | 163 | p_indent(level, frm); 164 | 165 | printf("HIDP: %s: %s\n", type2str(hdr), param); 166 | 167 | raw_dump(level, frm); 168 | } 169 | -------------------------------------------------------------------------------- /jni/parser/obex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | static char *opcode2str(uint8_t opcode) 37 | { 38 | switch (opcode & 0x7f) { 39 | case 0x00: 40 | return "Connect"; 41 | case 0x01: 42 | return "Disconnect"; 43 | case 0x02: 44 | return "Put"; 45 | case 0x03: 46 | return "Get"; 47 | case 0x04: 48 | return "Reserved"; 49 | case 0x05: 50 | return "SetPath"; 51 | case 0x06: 52 | return "Action"; 53 | case 0x07: 54 | return "Session"; 55 | case 0x7f: 56 | return "Abort"; 57 | case 0x10: 58 | return "Continue"; 59 | case 0x20: 60 | return "Success"; 61 | case 0x21: 62 | return "Created"; 63 | case 0x22: 64 | return "Accepted"; 65 | case 0x23: 66 | return "Non-authoritative information"; 67 | case 0x24: 68 | return "No content"; 69 | case 0x25: 70 | return "Reset content"; 71 | case 0x26: 72 | return "Partial content"; 73 | case 0x30: 74 | return "Multiple choices"; 75 | case 0x31: 76 | return "Moved permanently"; 77 | case 0x32: 78 | return "Moved temporarily"; 79 | case 0x33: 80 | return "See other"; 81 | case 0x34: 82 | return "Not modified"; 83 | case 0x35: 84 | return "Use Proxy"; 85 | case 0x40: 86 | return "Bad request"; 87 | case 0x41: 88 | return "Unauthorized"; 89 | case 0x42: 90 | return "Payment required"; 91 | case 0x43: 92 | return "Forbidden"; 93 | case 0x44: 94 | return "Not found"; 95 | case 0x45: 96 | return "Method not allowed"; 97 | case 0x46: 98 | return "Not acceptable"; 99 | case 0x47: 100 | return "Proxy authentication required"; 101 | case 0x48: 102 | return "Request timeout"; 103 | case 0x49: 104 | return "Conflict"; 105 | case 0x4a: 106 | return "Gone"; 107 | case 0x4b: 108 | return "Length required"; 109 | case 0x4c: 110 | return "Precondition failed"; 111 | case 0x4d: 112 | return "Requested entity too large"; 113 | case 0x4e: 114 | return "Requested URL too large"; 115 | case 0x4f: 116 | return "Unsupported media type"; 117 | case 0x50: 118 | return "Internal server error"; 119 | case 0x51: 120 | return "Not implemented"; 121 | case 0x52: 122 | return "Bad gateway"; 123 | case 0x53: 124 | return "Service unavailable"; 125 | case 0x54: 126 | return "Gateway timeout"; 127 | case 0x55: 128 | return "HTTP version not supported"; 129 | case 0x60: 130 | return "Database full"; 131 | case 0x61: 132 | return "Database locked"; 133 | default: 134 | return "Unknown"; 135 | } 136 | } 137 | 138 | static char *hi2str(uint8_t hi) 139 | { 140 | switch (hi & 0x3f) { 141 | case 0x00: 142 | return "Count"; 143 | case 0x01: 144 | return "Name"; 145 | case 0x02: 146 | return "Type"; 147 | case 0x03: 148 | return "Length"; 149 | case 0x04: 150 | return "Time"; 151 | case 0x05: 152 | return "Description"; 153 | case 0x06: 154 | return "Target"; 155 | case 0x07: 156 | return "HTTP"; 157 | case 0x08: 158 | return "Body"; 159 | case 0x09: 160 | return "End of Body"; 161 | case 0x0a: 162 | return "Who"; 163 | case 0x0b: 164 | return "Connection ID"; 165 | case 0x0c: 166 | return "App. Parameters"; 167 | case 0x0d: 168 | return "Auth. Challenge"; 169 | case 0x0e: 170 | return "Auth. Response"; 171 | case 0x0f: 172 | return "Creator ID"; 173 | case 0x10: 174 | return "WAN UUID"; 175 | case 0x11: 176 | return "Object Class"; 177 | case 0x12: 178 | return "Session Parameters"; 179 | case 0x13: 180 | return "Session Sequence Number"; 181 | case 0x14: 182 | return "Action ID"; 183 | case 0x15: 184 | return "DestName"; 185 | case 0x16: 186 | return "Permission"; 187 | case 0x17: 188 | return "Single Response Mode"; 189 | case 0x18: 190 | return "Single Response Mode Parameters"; 191 | default: 192 | return "Unknown"; 193 | } 194 | } 195 | 196 | static void parse_headers(int level, struct frame *frm) 197 | { 198 | uint8_t hi, hv8; 199 | uint16_t len; 200 | uint32_t hv32; 201 | 202 | while (frm->len > 0) { 203 | hi = get_u8(frm); 204 | 205 | p_indent(level, frm); 206 | 207 | printf("%s (0x%02x)", hi2str(hi), hi); 208 | switch (hi & 0xc0) { 209 | case 0x00: /* Unicode */ 210 | if (frm->len < 2) { 211 | printf("\n"); 212 | return; 213 | } 214 | 215 | len = get_u16(frm) - 3; 216 | printf(" = Unicode length %d\n", len); 217 | 218 | if (frm->len < len) 219 | return; 220 | 221 | raw_ndump(level, frm, len); 222 | frm->ptr += len; 223 | frm->len -= len; 224 | break; 225 | 226 | case 0x40: /* Byte sequence */ 227 | if (frm->len < 2) { 228 | printf("\n"); 229 | return; 230 | } 231 | 232 | len = get_u16(frm) - 3; 233 | printf(" = Sequence length %d\n", len); 234 | 235 | if (frm->len < len) 236 | return; 237 | 238 | raw_ndump(level, frm, len); 239 | frm->ptr += len; 240 | frm->len -= len; 241 | break; 242 | 243 | case 0x80: /* One byte */ 244 | if (frm->len < 1) { 245 | printf("\n"); 246 | return; 247 | } 248 | 249 | hv8 = get_u8(frm); 250 | printf(" = %d\n", hv8); 251 | break; 252 | 253 | case 0xc0: /* Four bytes */ 254 | if (frm->len < 4) { 255 | printf("\n"); 256 | return; 257 | } 258 | 259 | hv32 = get_u32(frm); 260 | printf(" = %u\n", hv32); 261 | break; 262 | } 263 | } 264 | } 265 | 266 | void obex_dump(int level, struct frame *frm) 267 | { 268 | uint8_t last_opcode, opcode, status; 269 | uint8_t version, flags, constants; 270 | uint16_t length, pktlen; 271 | 272 | frm = add_frame(frm); 273 | 274 | while (frm->len > 2) { 275 | opcode = get_u8(frm); 276 | length = get_u16(frm); 277 | status = opcode & 0x7f; 278 | 279 | if ((int) frm->len < length - 3) { 280 | frm->ptr -= 3; 281 | frm->len += 3; 282 | return; 283 | } 284 | 285 | p_indent(level, frm); 286 | 287 | last_opcode = get_opcode(frm->handle, frm->dlci); 288 | 289 | if (!(opcode & 0x70)) { 290 | printf("OBEX: %s cmd(%c): len %d", 291 | opcode2str(opcode), 292 | opcode & 0x80 ? 'f' : 'c', length); 293 | set_opcode(frm->handle, frm->dlci, opcode); 294 | } else { 295 | printf("OBEX: %s rsp(%c): status %x%02d len %d", 296 | opcode2str(last_opcode), 297 | opcode & 0x80 ? 'f' : 'c', 298 | status >> 4, status & 0xf, length); 299 | opcode = last_opcode; 300 | } 301 | 302 | if (get_status(frm->handle, frm->dlci) == 0x10) 303 | printf(" (continue)"); 304 | 305 | set_status(frm->handle, frm->dlci, status); 306 | 307 | if (frm->len == 0) { 308 | printf("\n"); 309 | break; 310 | } 311 | 312 | switch (opcode & 0x7f) { 313 | case 0x00: /* Connect */ 314 | if (frm->len < 4) { 315 | printf("\n"); 316 | return; 317 | } 318 | 319 | version = get_u8(frm); 320 | flags = get_u8(frm); 321 | pktlen = get_u16(frm); 322 | printf(" version %d.%d flags %d mtu %d\n", 323 | version >> 4, version & 0xf, flags, pktlen); 324 | break; 325 | 326 | case 0x05: /* SetPath */ 327 | if (frm->len < 2) { 328 | printf("\n"); 329 | return; 330 | } 331 | 332 | flags = get_u8(frm); 333 | constants = get_u8(frm); 334 | printf(" flags %d constants %d\n", flags, constants); 335 | break; 336 | 337 | default: 338 | printf("\n"); 339 | break; 340 | } 341 | 342 | if ((status & 0x70) && (parser.flags & DUMP_VERBOSE)) { 343 | p_indent(level, frm); 344 | printf("Status %x%02d = %s\n", 345 | status >> 4, status & 0xf, 346 | opcode2str(status)); 347 | } 348 | 349 | parse_headers(level, frm); 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /jni/parser/parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2002 Maxim Krasnyansky 6 | * Copyright (C) 2003-2011 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include 27 | #endif 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "parser/parser.h" 37 | #include "parser/rfcomm.h" 38 | 39 | struct parser_t parser; 40 | 41 | void init_parser(unsigned long flags, unsigned long filter, 42 | unsigned short defpsm, unsigned short defcompid, 43 | int pppdump_fd, int audio_fd) 44 | { 45 | if ((flags & DUMP_RAW) && !(flags & DUMP_TYPE_MASK)) 46 | flags |= DUMP_HEX; 47 | 48 | parser.flags = flags; 49 | parser.filter = filter; 50 | parser.defpsm = defpsm; 51 | parser.defcompid = defcompid; 52 | parser.state = 0; 53 | parser.pppdump_fd = pppdump_fd; 54 | parser.audio_fd = audio_fd; 55 | } 56 | 57 | #define PROTO_TABLE_SIZE 20 58 | 59 | static struct { 60 | uint16_t handle; 61 | uint16_t psm; 62 | uint8_t channel; 63 | uint32_t proto; 64 | } proto_table[PROTO_TABLE_SIZE]; 65 | 66 | void set_proto(uint16_t handle, uint16_t psm, uint8_t channel, uint32_t proto) 67 | { 68 | int i, pos = -1; 69 | 70 | if (psm > 0 && psm < 0x1000 && !channel) 71 | return; 72 | 73 | if (!psm && channel) 74 | psm = RFCOMM_PSM; 75 | 76 | for (i = 0; i < PROTO_TABLE_SIZE; i++) { 77 | if (proto_table[i].handle == handle && proto_table[i].psm == psm && proto_table[i].channel == channel) { 78 | pos = i; 79 | break; 80 | } 81 | 82 | if (pos < 0 && !proto_table[i].handle && !proto_table[i].psm && !proto_table[i].channel) 83 | pos = i; 84 | } 85 | 86 | if (pos < 0) 87 | return; 88 | 89 | proto_table[pos].handle = handle; 90 | proto_table[pos].psm = psm; 91 | proto_table[pos].channel = channel; 92 | proto_table[pos].proto = proto; 93 | } 94 | 95 | uint32_t get_proto(uint16_t handle, uint16_t psm, uint8_t channel) 96 | { 97 | int i, pos = -1; 98 | 99 | if (!psm && channel) 100 | psm = RFCOMM_PSM; 101 | 102 | for (i = 0; i < PROTO_TABLE_SIZE; i++) { 103 | if (proto_table[i].handle == handle && proto_table[i].psm == psm && proto_table[i].channel == channel) 104 | return proto_table[i].proto; 105 | 106 | if (!proto_table[i].handle) { 107 | if (proto_table[i].psm == psm && proto_table[i].channel == channel) 108 | pos = i; 109 | } 110 | } 111 | 112 | return (pos < 0) ? 0 : proto_table[pos].proto; 113 | } 114 | 115 | #define FRAME_TABLE_SIZE 20 116 | 117 | static struct { 118 | uint16_t handle; 119 | uint8_t dlci; 120 | uint8_t opcode; 121 | uint8_t status; 122 | struct frame frm; 123 | } frame_table[FRAME_TABLE_SIZE]; 124 | 125 | void del_frame(uint16_t handle, uint8_t dlci) 126 | { 127 | int i; 128 | 129 | for (i = 0; i < FRAME_TABLE_SIZE; i++) 130 | if (frame_table[i].handle == handle && 131 | frame_table[i].dlci == dlci) { 132 | frame_table[i].handle = 0; 133 | frame_table[i].dlci = 0; 134 | frame_table[i].opcode = 0; 135 | frame_table[i].status = 0; 136 | if (frame_table[i].frm.data) 137 | free(frame_table[i].frm.data); 138 | memset(&frame_table[i].frm, 0, sizeof(struct frame)); 139 | break; 140 | } 141 | } 142 | 143 | struct frame *add_frame(struct frame *frm) 144 | { 145 | struct frame *fr; 146 | void *data; 147 | int i, pos = -1; 148 | 149 | for (i = 0; i < FRAME_TABLE_SIZE; i++) { 150 | if (frame_table[i].handle == frm->handle && 151 | frame_table[i].dlci == frm->dlci) { 152 | pos = i; 153 | break; 154 | } 155 | 156 | if (pos < 0 && !frame_table[i].handle && !frame_table[i].dlci) 157 | pos = i; 158 | } 159 | 160 | if (pos < 0) 161 | return frm; 162 | 163 | frame_table[pos].handle = frm->handle; 164 | frame_table[pos].dlci = frm->dlci; 165 | fr = &frame_table[pos].frm; 166 | 167 | data = malloc(fr->len + frm->len); 168 | if (!data) { 169 | perror("Can't allocate frame stream buffer"); 170 | del_frame(frm->handle, frm->dlci); 171 | return frm; 172 | } 173 | 174 | if (fr->len > 0) 175 | memcpy(data, fr->ptr, fr->len); 176 | 177 | if (frm->len > 0) 178 | memcpy(data + fr->len, frm->ptr, frm->len); 179 | 180 | if (fr->data) 181 | free(fr->data); 182 | 183 | fr->data = data; 184 | fr->data_len = fr->len + frm->len; 185 | fr->len = fr->data_len; 186 | fr->ptr = fr->data; 187 | fr->dev_id = frm->dev_id; 188 | fr->in = frm->in; 189 | fr->ts = frm->ts; 190 | fr->handle = frm->handle; 191 | fr->cid = frm->cid; 192 | fr->num = frm->num; 193 | fr->dlci = frm->dlci; 194 | fr->channel = frm->channel; 195 | fr->pppdump_fd = frm->pppdump_fd; 196 | fr->audio_fd = frm->audio_fd; 197 | 198 | return fr; 199 | } 200 | 201 | uint8_t get_opcode(uint16_t handle, uint8_t dlci) 202 | { 203 | int i; 204 | 205 | for (i = 0; i < FRAME_TABLE_SIZE; i++) 206 | if (frame_table[i].handle == handle && 207 | frame_table[i].dlci == dlci) 208 | return frame_table[i].opcode; 209 | 210 | return 0x00; 211 | } 212 | 213 | void set_opcode(uint16_t handle, uint8_t dlci, uint8_t opcode) 214 | { 215 | int i; 216 | 217 | for (i = 0; i < FRAME_TABLE_SIZE; i++) 218 | if (frame_table[i].handle == handle && 219 | frame_table[i].dlci == dlci) { 220 | frame_table[i].opcode = opcode; 221 | break; 222 | } 223 | } 224 | 225 | uint8_t get_status(uint16_t handle, uint8_t dlci) 226 | { 227 | int i; 228 | 229 | for (i = 0; i < FRAME_TABLE_SIZE; i++) 230 | if (frame_table[i].handle == handle && 231 | frame_table[i].dlci == dlci) 232 | return frame_table[i].status; 233 | 234 | return 0x00; 235 | } 236 | 237 | void set_status(uint16_t handle, uint8_t dlci, uint8_t status) 238 | { 239 | int i; 240 | 241 | for (i = 0; i < FRAME_TABLE_SIZE; i++) 242 | if (frame_table[i].handle == handle && 243 | frame_table[i].dlci == dlci) { 244 | frame_table[i].status = status; 245 | break; 246 | } 247 | } 248 | 249 | void ascii_dump(int level, struct frame *frm, int num) 250 | { 251 | unsigned char *buf = frm->ptr; 252 | register int i, n; 253 | 254 | if ((num < 0) || (num > (int) frm->len)) 255 | num = frm->len; 256 | 257 | for (i = 0, n = 1; i < num; i++, n++) { 258 | if (n == 1) 259 | p_indent(level, frm); 260 | printf("%1c ", isprint(buf[i]) ? buf[i] : '.'); 261 | if (n == DUMP_WIDTH) { 262 | printf("\n"); 263 | n = 0; 264 | } 265 | } 266 | if (i && n != 1) 267 | printf("\n"); 268 | } 269 | 270 | void hex_dump(int level, struct frame *frm, int num) 271 | { 272 | unsigned char *buf = frm->ptr; 273 | register int i, n; 274 | 275 | if ((num < 0) || (num > (int) frm->len)) 276 | num = frm->len; 277 | 278 | for (i = 0, n = 1; i < num; i++, n++) { 279 | if (n == 1) 280 | p_indent(level, frm); 281 | printf("%2.2X ", buf[i]); 282 | if (n == DUMP_WIDTH) { 283 | printf("\n"); 284 | n = 0; 285 | } 286 | } 287 | if (i && n != 1) 288 | printf("\n"); 289 | } 290 | 291 | void ext_dump(int level, struct frame *frm, int num) 292 | { 293 | unsigned char *buf = frm->ptr; 294 | register int i, n = 0, size; 295 | 296 | if ((num < 0) || (num > (int) frm->len)) 297 | num = frm->len; 298 | 299 | while (num > 0) { 300 | p_indent(level, frm); 301 | printf("%04x: ", n); 302 | 303 | size = num > 16 ? 16 : num; 304 | 305 | for (i = 0; i < size; i++) 306 | printf("%02x%s", buf[i], (i + 1) % 8 ? " " : " "); 307 | for (i = size; i < 16; i++) 308 | printf(" %s", (i + 1) % 8 ? " " : " "); 309 | 310 | for (i = 0; i < size; i++) 311 | printf("%1c", isprint(buf[i]) ? buf[i] : '.'); 312 | printf("\n"); 313 | 314 | buf += size; 315 | num -= size; 316 | n += size; 317 | } 318 | } 319 | 320 | void raw_ndump(int level, struct frame *frm, int num) 321 | { 322 | if (!frm->len) 323 | return; 324 | 325 | switch (parser.flags & DUMP_TYPE_MASK) { 326 | case DUMP_ASCII: 327 | ascii_dump(level, frm, num); 328 | break; 329 | 330 | case DUMP_HEX: 331 | hex_dump(level, frm, num); 332 | break; 333 | 334 | case DUMP_EXT: 335 | ext_dump(level, frm, num); 336 | break; 337 | } 338 | } 339 | 340 | void raw_dump(int level, struct frame *frm) 341 | { 342 | raw_ndump(level, frm, -1); 343 | } 344 | -------------------------------------------------------------------------------- /jni/parser/parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2000-2002 Maxim Krasnyansky 6 | * Copyright (C) 2003-2011 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __PARSER_H 26 | #define __PARSER_H 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "lib/bluetooth.h" 33 | 34 | struct frame { 35 | void *data; 36 | uint32_t data_len; 37 | void *ptr; 38 | uint32_t len; 39 | uint16_t dev_id; 40 | uint8_t in; 41 | uint8_t master; 42 | uint16_t handle; 43 | uint16_t cid; 44 | uint16_t num; 45 | uint8_t dlci; 46 | uint8_t channel; 47 | unsigned long flags; 48 | struct timeval ts; 49 | int pppdump_fd; 50 | int audio_fd; 51 | }; 52 | 53 | /* Parser flags */ 54 | #define DUMP_WIDTH 20 55 | 56 | #define DUMP_ASCII 0x0001 57 | #define DUMP_HEX 0x0002 58 | #define DUMP_EXT 0x0004 59 | #define DUMP_RAW 0x0008 60 | #define DUMP_BPA 0x0010 61 | #define DUMP_TSTAMP 0x0100 62 | #define DUMP_VERBOSE 0x0200 63 | #define DUMP_BTSNOOP 0x1000 64 | #define DUMP_PKTLOG 0x2000 65 | #define DUMP_NOVENDOR 0x4000 66 | #define DUMP_TYPE_MASK (DUMP_ASCII | DUMP_HEX | DUMP_EXT) 67 | 68 | /* Parser filter */ 69 | #define FILT_LMP 0x0001 70 | #define FILT_HCI 0x0002 71 | #define FILT_SCO 0x0004 72 | #define FILT_L2CAP 0x0008 73 | #define FILT_RFCOMM 0x0010 74 | #define FILT_SDP 0x0020 75 | #define FILT_BNEP 0x0040 76 | #define FILT_CMTP 0x0080 77 | #define FILT_HIDP 0x0100 78 | #define FILT_HCRP 0x0200 79 | #define FILT_AVDTP 0x0400 80 | #define FILT_AVCTP 0x0800 81 | #define FILT_ATT 0x1000 82 | #define FILT_SMP 0x2000 83 | 84 | #define FILT_OBEX 0x00010000 85 | #define FILT_CAPI 0x00020000 86 | #define FILT_PPP 0x00040000 87 | #define FILT_ERICSSON 0x10000000 88 | #define FILT_CSR 0x1000000a 89 | #define FILT_DGA 0x1000000c 90 | 91 | #define STRUCT_OFFSET(type, member) ((uint8_t *)&(((type *)NULL)->member) - \ 92 | (uint8_t *)((type *)NULL)) 93 | 94 | #define STRUCT_END(type, member) (STRUCT_OFFSET(type, member) + \ 95 | sizeof(((type *)NULL)->member)) 96 | 97 | #define DEFAULT_COMPID 65535 98 | 99 | struct parser_t { 100 | unsigned long flags; 101 | unsigned long filter; 102 | unsigned short defpsm; 103 | unsigned short defcompid; 104 | int state; 105 | int pppdump_fd; 106 | int audio_fd; 107 | }; 108 | 109 | extern struct parser_t parser; 110 | 111 | void init_parser(unsigned long flags, unsigned long filter, 112 | unsigned short defpsm, unsigned short defcompid, 113 | int pppdump_fd, int audio_fd); 114 | 115 | static inline int p_filter(unsigned long f) 116 | { 117 | return !(parser.filter & f); 118 | } 119 | 120 | static inline void p_indent(int level, struct frame *f) 121 | { 122 | if (level < 0) { 123 | parser.state = 0; 124 | return; 125 | } 126 | 127 | if (!parser.state) { 128 | if (parser.flags & DUMP_TSTAMP) { 129 | if (parser.flags & DUMP_VERBOSE) { 130 | struct tm tm; 131 | time_t t = f->ts.tv_sec; 132 | localtime_r(&t, &tm); 133 | printf("%04d-%02d-%02d %02d:%02d:%02d.%06lu ", 134 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 135 | tm.tm_hour, tm.tm_min, tm.tm_sec, f->ts.tv_usec); 136 | } else 137 | printf("%8lu.%06lu ", f->ts.tv_sec, f->ts.tv_usec); 138 | } 139 | printf("%c ", (f->in ? '>' : '<')); 140 | parser.state = 1; 141 | } else 142 | printf(" "); 143 | 144 | if (level) 145 | printf("%*c", (level*2), ' '); 146 | } 147 | 148 | static inline void p_ba2str(const bdaddr_t *ba, char *str) 149 | { 150 | if (parser.flags & DUMP_NOVENDOR) { 151 | uint8_t b[6]; 152 | 153 | baswap((bdaddr_t *) b, ba); 154 | sprintf(str, "%2.2X:%2.2X:%2.2X:*:*:*", b[0], b[1], b[2]); 155 | } else 156 | ba2str(ba, str); 157 | } 158 | 159 | /* get_uXX functions do byte swaping */ 160 | 161 | static inline uint8_t get_u8(struct frame *frm) 162 | { 163 | uint8_t *u8_ptr = frm->ptr; 164 | frm->ptr += 1; 165 | frm->len -= 1; 166 | return *u8_ptr; 167 | } 168 | 169 | static inline uint16_t get_u16(struct frame *frm) 170 | { 171 | uint16_t *u16_ptr = frm->ptr; 172 | frm->ptr += 2; 173 | frm->len -= 2; 174 | return ntohs(bt_get_unaligned(u16_ptr)); 175 | } 176 | 177 | static inline uint32_t get_u32(struct frame *frm) 178 | { 179 | uint32_t *u32_ptr = frm->ptr; 180 | frm->ptr += 4; 181 | frm->len -= 4; 182 | return ntohl(bt_get_unaligned(u32_ptr)); 183 | } 184 | 185 | static inline uint64_t get_u64(struct frame *frm) 186 | { 187 | uint64_t *u64_ptr = frm->ptr; 188 | uint64_t u64 = bt_get_unaligned(u64_ptr), tmp; 189 | frm->ptr += 8; 190 | frm->len -= 8; 191 | tmp = ntohl(u64 & 0xffffffff); 192 | u64 = (tmp << 32) | ntohl(u64 >> 32); 193 | return u64; 194 | } 195 | 196 | static inline void get_u128(struct frame *frm, uint64_t *l, uint64_t *h) 197 | { 198 | *h = get_u64(frm); 199 | *l = get_u64(frm); 200 | } 201 | 202 | char *get_uuid_name(int uuid); 203 | 204 | void set_proto(uint16_t handle, uint16_t psm, uint8_t channel, uint32_t proto); 205 | uint32_t get_proto(uint16_t handle, uint16_t psm, uint8_t channel); 206 | 207 | struct frame *add_frame(struct frame *frm); 208 | void del_frame(uint16_t handle, uint8_t dlci); 209 | 210 | uint8_t get_opcode(uint16_t handle, uint8_t dlci); 211 | void set_opcode(uint16_t handle, uint8_t dlci, uint8_t opcode); 212 | 213 | uint8_t get_status(uint16_t handle, uint8_t dlci); 214 | void set_status(uint16_t handle, uint8_t dlci, uint8_t status); 215 | 216 | void l2cap_clear(uint16_t handle); 217 | 218 | void ascii_dump(int level, struct frame *frm, int num); 219 | void hex_dump(int level, struct frame *frm, int num); 220 | void ext_dump(int level, struct frame *frm, int num); 221 | void raw_dump(int level, struct frame *frm); 222 | void raw_ndump(int level, struct frame *frm, int num); 223 | 224 | void lmp_dump(int level, struct frame *frm); 225 | void hci_dump(int level, struct frame *frm); 226 | void l2cap_dump(int level, struct frame *frm); 227 | void rfcomm_dump(int level, struct frame *frm); 228 | void sdp_dump(int level, struct frame *frm); 229 | void bnep_dump(int level, struct frame *frm); 230 | void cmtp_dump(int level, struct frame *frm); 231 | void hidp_dump(int level, struct frame *frm); 232 | void hcrp_dump(int level, struct frame *frm); 233 | void avdtp_dump(int level, struct frame *frm); 234 | void avctp_dump(int level, struct frame *frm); 235 | void avrcp_dump(int level, struct frame *frm); 236 | void att_dump(int level, struct frame *frm); 237 | void smp_dump(int level, struct frame *frm); 238 | 239 | void obex_dump(int level, struct frame *frm); 240 | void capi_dump(int level, struct frame *frm); 241 | void ppp_dump(int level, struct frame *frm); 242 | void arp_dump(int level, struct frame *frm); 243 | void ip_dump(int level, struct frame *frm); 244 | void ericsson_dump(int level, struct frame *frm); 245 | void csr_dump(int level, struct frame *frm); 246 | void bpa_dump(int level, struct frame *frm); 247 | 248 | static inline void parse(struct frame *frm) 249 | { 250 | p_indent(-1, NULL); 251 | if (parser.flags & DUMP_RAW) 252 | raw_dump(0, frm); 253 | else 254 | hci_dump(0, frm); 255 | fflush(stdout); 256 | } 257 | 258 | #endif /* __PARSER_H */ 259 | -------------------------------------------------------------------------------- /jni/parser/ppp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | #define PPP_U8(frm) (get_u8(frm)) 37 | #define PPP_U16(frm) (btohs(htons(get_u16(frm)))) 38 | #define PPP_U32(frm) (btohl(htonl(get_u32(frm)))) 39 | 40 | static int ppp_traffic = 0; 41 | 42 | static unsigned char ppp_magic1[] = { 0x7e, 0xff, 0x03, 0xc0, 0x21 }; 43 | static unsigned char ppp_magic2[] = { 0x7e, 0xff, 0x7d, 0x23, 0xc0, 0x21 }; 44 | static unsigned char ppp_magic3[] = { 0x7e, 0x7d, 0xdf, 0x7d, 0x23, 0xc0, 0x21 }; 45 | 46 | static inline int check_for_ppp_traffic(unsigned char *data, int size) 47 | { 48 | unsigned int i; 49 | 50 | for (i = 0; i < size - sizeof(ppp_magic1); i++) 51 | if (!memcmp(data + i, ppp_magic1, sizeof(ppp_magic1))) { 52 | ppp_traffic = 1; 53 | return i; 54 | } 55 | 56 | for (i = 0; i < size - sizeof(ppp_magic2); i++) 57 | if (!memcmp(data + i, ppp_magic2, sizeof(ppp_magic2))) { 58 | ppp_traffic = 1; 59 | return i; 60 | } 61 | 62 | for (i = 0; i < size - sizeof(ppp_magic3); i++) 63 | if (!memcmp(data + i, ppp_magic3, sizeof(ppp_magic3))) { 64 | ppp_traffic = 1; 65 | return i; 66 | } 67 | 68 | return -1; 69 | } 70 | 71 | static inline char *dir2str(uint8_t in) 72 | { 73 | return in ? "DCE" : "DTE"; 74 | } 75 | 76 | static inline char *proto2str(uint16_t proto) 77 | { 78 | switch (proto) { 79 | case 0x0001: 80 | return "Padding Protocol"; 81 | case 0x0021: 82 | return "IP"; 83 | case 0x8021: 84 | return "IP Control Protocol"; 85 | case 0x80fd: 86 | return "Compression Control Protocol"; 87 | case 0xc021: 88 | return "Link Control Protocol"; 89 | case 0xc023: 90 | return "Password Authentication Protocol"; 91 | case 0xc025: 92 | return "Link Quality Report"; 93 | case 0xc223: 94 | return "Challenge Handshake Authentication Protocol"; 95 | default: 96 | return "Unknown Protocol"; 97 | } 98 | } 99 | 100 | static void hdlc_dump(int level, struct frame *frm) 101 | { 102 | uint8_t addr = get_u8(frm); 103 | uint8_t ctrl = get_u8(frm); 104 | uint16_t fcs, proto; 105 | 106 | fcs = bt_get_unaligned((uint16_t *) (frm->ptr + frm->len - 2)); 107 | frm->len -= 2; 108 | 109 | p_indent(level, frm); 110 | 111 | if (addr != 0xff || ctrl != 0x03) { 112 | frm->ptr -= 2; 113 | frm->len += 2; 114 | printf("HDLC: %s: len %d fcs 0x%04x\n", 115 | dir2str(frm->in), frm->len, fcs); 116 | } else 117 | printf("HDLC: %s: addr 0x%02x ctrl 0x%02x len %d fcs 0x%04x\n", 118 | dir2str(frm->in), addr, ctrl, frm->len, fcs); 119 | 120 | if (*((uint8_t *) frm->ptr) & 0x80) 121 | proto = get_u16(frm); 122 | else 123 | proto = get_u8(frm); 124 | 125 | p_indent(level + 1, frm); 126 | printf("PPP: %s (0x%04x): len %d\n", proto2str(proto), proto, frm->len); 127 | 128 | raw_dump(level + 1, frm); 129 | } 130 | 131 | static inline void unslip_frame(int level, struct frame *frm, int len) 132 | { 133 | struct frame msg; 134 | unsigned char *data, *ptr; 135 | int i, p = 0; 136 | 137 | data = malloc(len * 2); 138 | if (!data) 139 | return; 140 | 141 | ptr = frm->ptr; 142 | 143 | for (i = 0; i < len; i++) { 144 | if (ptr[i] == 0x7d) { 145 | data[p++] = ptr[i + 1] ^ 0x20; 146 | i++; 147 | } else 148 | data[p++] = ptr[i]; 149 | } 150 | 151 | memset(&msg, 0, sizeof(msg)); 152 | msg.data = data; 153 | msg.data_len = len * 2; 154 | msg.ptr = msg.data; 155 | msg.len = p; 156 | msg.in = frm->in; 157 | msg.ts = frm->ts; 158 | msg.handle = frm->handle; 159 | msg.cid = frm->cid; 160 | 161 | hdlc_dump(level, &msg); 162 | 163 | free(data); 164 | } 165 | 166 | void ppp_dump(int level, struct frame *frm) 167 | { 168 | void *ptr, *end; 169 | int err, len, pos = 0; 170 | 171 | if (frm->pppdump_fd > fileno(stderr)) { 172 | unsigned char id; 173 | uint16_t len = htons(frm->len); 174 | uint32_t ts = htonl(frm->ts.tv_sec & 0xffffffff); 175 | 176 | id = 0x07; 177 | err = write(frm->pppdump_fd, &id, 1); 178 | if (err < 0) 179 | return; 180 | 181 | err = write(frm->pppdump_fd, &ts, 4); 182 | if (err < 0) 183 | return; 184 | 185 | id = frm->in ? 0x02 : 0x01; 186 | err = write(frm->pppdump_fd, &id, 1); 187 | if (err < 0) 188 | return; 189 | err = write(frm->pppdump_fd, &len, 2); 190 | if (err < 0) 191 | return; 192 | err = write(frm->pppdump_fd, frm->ptr, frm->len); 193 | if (err < 0) 194 | return; 195 | } 196 | 197 | if (!ppp_traffic) { 198 | pos = check_for_ppp_traffic(frm->ptr, frm->len); 199 | if (pos < 0) { 200 | raw_dump(level, frm); 201 | return; 202 | } 203 | 204 | if (pos > 0) { 205 | raw_ndump(level, frm, pos); 206 | frm->ptr += pos; 207 | frm->len -= pos; 208 | } 209 | } 210 | 211 | frm = add_frame(frm); 212 | 213 | while (frm->len > 0) { 214 | ptr = memchr(frm->ptr, 0x7e, frm->len); 215 | if (!ptr) 216 | break; 217 | 218 | if (frm->ptr != ptr) { 219 | frm->len -= (ptr - frm->ptr); 220 | frm->ptr = ptr; 221 | } 222 | 223 | end = memchr(frm->ptr + 1, 0x7e, frm->len - 1); 224 | if (!end) 225 | break; 226 | 227 | len = end - ptr - 1; 228 | 229 | frm->ptr++; 230 | frm->len--; 231 | 232 | if (len > 0) { 233 | unslip_frame(level, frm, len); 234 | 235 | frm->ptr += len; 236 | frm->len -= len; 237 | } 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /jni/parser/rfcomm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2001-2002 Wayne Lee 6 | * Copyright (C) 2003-2011 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | #include 27 | #endif 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "parser/parser.h" 36 | #include "parser/rfcomm.h" 37 | #include "parser/sdp.h" 38 | 39 | static char *cr_str[] = { 40 | "RSP", 41 | "CMD" 42 | }; 43 | 44 | #define CR_STR(mcc_head) cr_str[mcc_head->type.cr] 45 | #define GET_DLCI(addr) ((addr.server_chn << 1) | (addr.d & 1)) 46 | 47 | static void print_rfcomm_hdr(long_frame_head* head, uint8_t *ptr, int len) 48 | { 49 | address_field addr = head->addr; 50 | uint8_t ctr = head->control; 51 | uint16_t ilen = head->length.bits.len; 52 | uint8_t pf, dlci, fcs; 53 | 54 | dlci = GET_DLCI(addr); 55 | pf = GET_PF(ctr); 56 | fcs = *(ptr + len - 1); 57 | 58 | printf("cr %d dlci %d pf %d ilen %d fcs 0x%x ", addr.cr, dlci, pf, ilen, fcs); 59 | } 60 | 61 | static void print_mcc(mcc_long_frame_head* mcc_head) 62 | { 63 | printf("mcc_len %d\n", mcc_head->length.bits.len); 64 | } 65 | 66 | static inline void mcc_test(int level, uint8_t *ptr, int len, 67 | long_frame_head *head, mcc_long_frame_head *mcc_head) 68 | { 69 | printf("TEST %s: ", CR_STR(mcc_head)); 70 | print_rfcomm_hdr(head, ptr, len); 71 | print_mcc(mcc_head); 72 | } 73 | static inline void mcc_fcon(int level, uint8_t *ptr, int len, 74 | long_frame_head *head, mcc_long_frame_head *mcc_head) 75 | { 76 | printf("FCON %s: ", CR_STR(mcc_head)); 77 | print_rfcomm_hdr(head, ptr, len); 78 | print_mcc(mcc_head); 79 | } 80 | 81 | static inline void mcc_fcoff(int level, uint8_t *ptr, int len, 82 | long_frame_head *head, mcc_long_frame_head *mcc_head) 83 | { 84 | printf("FCOFF %s: ", CR_STR(mcc_head)); 85 | print_rfcomm_hdr(head, ptr, len); 86 | print_mcc(mcc_head); 87 | } 88 | 89 | static inline void mcc_msc(int level, uint8_t *ptr, unsigned int len, 90 | long_frame_head *head, mcc_long_frame_head *mcc_head) 91 | { 92 | msc_msg *msc = (void*) (ptr - STRUCT_END(msc_msg, mcc_s_head)); 93 | 94 | printf("MSC %s: ", CR_STR(mcc_head)); 95 | print_rfcomm_hdr(head, ptr, len); 96 | print_mcc(mcc_head); 97 | p_indent(level, 0); 98 | printf("dlci %d fc %d rtc %d rtr %d ic %d dv %d", 99 | GET_DLCI(msc->dlci), msc->v24_sigs.fc, msc->v24_sigs.rtc, 100 | msc->v24_sigs.rtr, msc->v24_sigs.ic, msc->v24_sigs.dv ); 101 | 102 | /* Assuming that break_signals field is _not declared_ in struct msc_msg... */ 103 | if (len > STRUCT_OFFSET(msc_msg, fcs) - STRUCT_END(msc_msg, v24_sigs)) { 104 | break_signals *brk = (break_signals *) 105 | (ptr + STRUCT_END(msc_msg, v24_sigs)); 106 | printf(" b1 %d b2 %d b3 %d len %d\n", 107 | brk->b1, brk->b2, brk->b3, brk->len); 108 | } else 109 | printf("\n"); 110 | } 111 | 112 | static inline void mcc_rpn(int level, uint8_t *ptr, unsigned int len, 113 | long_frame_head *head, mcc_long_frame_head *mcc_head) 114 | { 115 | rpn_msg *rpn = (void *) (ptr - STRUCT_END(rpn_msg, mcc_s_head)); 116 | 117 | printf("RPN %s: ", CR_STR(mcc_head)); 118 | print_rfcomm_hdr(head, ptr, len); 119 | print_mcc(mcc_head); 120 | 121 | p_indent(level, 0); 122 | printf("dlci %d ", GET_DLCI(rpn->dlci)); 123 | 124 | /* Assuming that rpn_val is _declared_ as a member of rpn_msg... */ 125 | if (len <= STRUCT_OFFSET(rpn_msg, rpn_val) - STRUCT_END(rpn_msg, mcc_s_head)) { 126 | printf("\n"); 127 | return; 128 | } 129 | 130 | printf("br %d db %d sb %d p %d pt %d xi %d xo %d\n", 131 | rpn->rpn_val.bit_rate, rpn->rpn_val.data_bits, 132 | rpn->rpn_val.stop_bit, rpn->rpn_val.parity, 133 | rpn->rpn_val.parity_type, rpn->rpn_val.xon_input, 134 | rpn->rpn_val.xon_output); 135 | 136 | p_indent(level, 0); 137 | printf("rtri %d rtro %d rtci %d rtco %d xon %d xoff %d pm 0x%04x\n", 138 | rpn->rpn_val.rtr_input, rpn->rpn_val.rtr_output, 139 | rpn->rpn_val.rtc_input, rpn->rpn_val.rtc_output, 140 | rpn->rpn_val.xon, rpn->rpn_val.xoff, btohs(rpn->rpn_val.pm)); 141 | } 142 | 143 | static inline void mcc_rls(int level, uint8_t *ptr, int len, 144 | long_frame_head *head, mcc_long_frame_head *mcc_head) 145 | { 146 | rls_msg* rls = (void*) (ptr - STRUCT_END(rls_msg, mcc_s_head)); 147 | 148 | printf("RLS %s: ", CR_STR(mcc_head)); 149 | print_rfcomm_hdr(head, ptr, len); 150 | print_mcc(mcc_head); 151 | printf("dlci %d error: %d", GET_DLCI(rls->dlci), rls->error); 152 | } 153 | 154 | static inline void mcc_pn(int level, uint8_t *ptr, int len, 155 | long_frame_head *head, mcc_long_frame_head *mcc_head) 156 | { 157 | pn_msg *pn = (void*) (ptr - STRUCT_END(pn_msg, mcc_s_head)); 158 | 159 | printf("PN %s: ", CR_STR(mcc_head)); 160 | print_rfcomm_hdr(head, ptr, len); 161 | print_mcc(mcc_head); 162 | 163 | p_indent(level, 0); 164 | printf("dlci %d frame_type %d credit_flow %d pri %d ack_timer %d\n", 165 | pn->dlci, pn->frame_type, pn->credit_flow, pn->prior, pn->ack_timer); 166 | p_indent(level, 0); 167 | printf("frame_size %d max_retrans %d credits %d\n", 168 | btohs(pn->frame_size), pn->max_nbrof_retrans, pn->credits); 169 | } 170 | 171 | static inline void mcc_nsc(int level, uint8_t *ptr, int len, 172 | long_frame_head *head, mcc_long_frame_head *mcc_head) 173 | { 174 | 175 | nsc_msg *nsc = (void*) (ptr - STRUCT_END(nsc_msg, mcc_s_head)); 176 | 177 | printf("NSC %s: ", CR_STR(mcc_head)); 178 | print_rfcomm_hdr(head, ptr, len); 179 | print_mcc(mcc_head); 180 | 181 | p_indent(level, 0); 182 | printf("cr %d, mcc_cmd_type %x\n", 183 | nsc->command_type.cr, nsc->command_type.type ); 184 | } 185 | 186 | static inline void mcc_frame(int level, struct frame *frm, long_frame_head *head) 187 | { 188 | mcc_short_frame_head *mcc_short_head_p = frm->ptr; 189 | mcc_long_frame_head mcc_head; 190 | uint8_t hdr_size; 191 | 192 | if ( mcc_short_head_p->length.ea == EA ) { 193 | mcc_head.type = mcc_short_head_p->type; 194 | mcc_head.length.bits.len = mcc_short_head_p->length.len; 195 | hdr_size = sizeof(mcc_short_frame_head); 196 | } else { 197 | mcc_head = *(mcc_long_frame_head *)frm->ptr; 198 | mcc_head.length.val = btohs(mcc_head.length.val); 199 | hdr_size = sizeof(mcc_long_frame_head); 200 | } 201 | 202 | frm->ptr += hdr_size; 203 | frm->len -= hdr_size; 204 | 205 | p_indent(level, frm); 206 | printf("RFCOMM(s): "); 207 | 208 | switch (mcc_head.type.type) { 209 | case TEST: 210 | mcc_test(level, frm->ptr, frm->len, head, &mcc_head); 211 | raw_dump(level, frm); 212 | break; 213 | case FCON: 214 | mcc_fcon(level, frm->ptr, frm->len, head, &mcc_head); 215 | break; 216 | case FCOFF: 217 | mcc_fcoff(level, frm->ptr, frm->len, head, &mcc_head); 218 | break; 219 | case MSC: 220 | mcc_msc(level, frm->ptr, frm->len, head, &mcc_head); 221 | break; 222 | case RPN: 223 | mcc_rpn(level, frm->ptr, frm->len, head, &mcc_head); 224 | break; 225 | case RLS: 226 | mcc_rls(level, frm->ptr, frm->len, head, &mcc_head); 227 | break; 228 | case PN: 229 | mcc_pn(level, frm->ptr, frm->len, head, &mcc_head); 230 | break; 231 | case NSC: 232 | mcc_nsc(level, frm->ptr, frm->len, head, &mcc_head); 233 | break; 234 | default: 235 | printf("MCC message type 0x%02x: ", mcc_head.type.type); 236 | print_rfcomm_hdr(head, frm->ptr, frm->len); 237 | printf("\n"); 238 | 239 | frm->len--; 240 | raw_dump(level, frm); 241 | } 242 | } 243 | 244 | static inline void uih_frame(int level, struct frame *frm, long_frame_head *head) 245 | { 246 | uint32_t proto; 247 | 248 | if (!head->addr.server_chn) { 249 | mcc_frame(level, frm, head); 250 | } else { 251 | p_indent(level, frm); 252 | printf("RFCOMM(d): UIH: "); 253 | print_rfcomm_hdr(head, frm->ptr, frm->len); 254 | if (GET_PF(head->control)) { 255 | printf("credits %d\n", *(uint8_t *)(frm->ptr)); 256 | frm->ptr++; 257 | frm->len--; 258 | } else 259 | printf("\n"); 260 | 261 | frm->len--; 262 | frm->dlci = GET_DLCI(head->addr); 263 | frm->channel = head->addr.server_chn; 264 | 265 | proto = get_proto(frm->handle, RFCOMM_PSM, frm->channel); 266 | 267 | if (frm->len > 0) { 268 | switch (proto) { 269 | case SDP_UUID_OBEX: 270 | if (!p_filter(FILT_OBEX)) 271 | obex_dump(level + 1, frm); 272 | else 273 | raw_dump(level, frm); 274 | break; 275 | 276 | case SDP_UUID_LAN_ACCESS_PPP: 277 | case SDP_UUID_DIALUP_NETWORKING: 278 | if (!p_filter(FILT_PPP)) 279 | ppp_dump(level + 1, frm); 280 | else 281 | raw_dump(level, frm); 282 | break; 283 | 284 | default: 285 | if (p_filter(FILT_RFCOMM)) 286 | break; 287 | 288 | raw_dump(level, frm); 289 | break; 290 | } 291 | } 292 | } 293 | } 294 | 295 | void rfcomm_dump(int level, struct frame *frm) 296 | { 297 | uint8_t hdr_size, ctr_type; 298 | short_frame_head *short_head_p = (void *) frm->ptr; 299 | long_frame_head head; 300 | 301 | if (short_head_p->length.ea == EA) { 302 | head.addr = short_head_p->addr; 303 | head.control = short_head_p->control; 304 | head.length.bits.len = short_head_p->length.len; 305 | hdr_size = sizeof(short_frame_head); 306 | } else { 307 | head = *(long_frame_head *) frm->ptr; 308 | head.length.val = btohs(head.length.val); 309 | hdr_size = sizeof(long_frame_head); 310 | } 311 | 312 | frm->ptr += hdr_size; 313 | frm->len -= hdr_size; 314 | 315 | ctr_type = CLR_PF(head.control); 316 | 317 | if (ctr_type == UIH) { 318 | uih_frame(level, frm, &head); 319 | } else { 320 | p_indent(level, frm); 321 | printf("RFCOMM(s): "); 322 | 323 | switch (ctr_type) { 324 | case SABM: 325 | printf("SABM: "); 326 | break; 327 | case UA: 328 | printf("UA: "); 329 | break; 330 | case DM: 331 | printf("DM: "); 332 | break; 333 | case DISC: 334 | printf("DISC: "); 335 | del_frame(frm->handle, GET_DLCI(head.addr)); 336 | break; 337 | default: 338 | printf("ERR: "); 339 | } 340 | print_rfcomm_hdr(&head, frm->ptr, frm->len); 341 | printf("\n"); 342 | } 343 | } 344 | -------------------------------------------------------------------------------- /jni/parser/rfcomm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2001-2002 Wayne Lee 6 | * Copyright (C) 2003-2011 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __RFCOMM_H 26 | #define __RFCOMM_H 27 | 28 | #include 29 | 30 | #define RFCOMM_PSM 3 31 | 32 | #define TRUE 1 33 | #define FALSE 0 34 | 35 | #define RFCOMM_MAX_CONN 10 36 | #define BT_NBR_DATAPORTS RFCOMM_MAX_CONN 37 | 38 | #define GET_BIT(pos,bitfield) ((bitfield[(pos)/32]) & (1 << ((pos) % 32))) 39 | #define SET_BIT(pos,bitfield) ((bitfield[(pos)/32]) |= (1 << ((pos) % 32))) 40 | #define CLR_BIT(pos,bitfield) ((bitfield[(pos)/32]) &= ((1 << ((pos) % 32)) ^ (~0))) 41 | 42 | /* Sets the P/F-bit in the control field */ 43 | #define SET_PF(ctr) ((ctr) | (1 << 4)) 44 | /* Clears the P/F-bit in the control field */ 45 | #define CLR_PF(ctr) ((ctr) & 0xef) 46 | /* Returns the P/F-bit */ 47 | #define GET_PF(ctr) (((ctr) >> 4) & 0x1) 48 | 49 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 50 | 51 | /* Endian-swapping macros for structs */ 52 | #define swap_long_frame(x) ((x)->h.length.val = le16_to_cpu((x)->h.length.val)) 53 | #define swap_mcc_long_frame(x) (swap_long_frame(x)) 54 | 55 | /* Used for UIH packets */ 56 | #define SHORT_CRC_CHECK 2 57 | /* Used for all packet exepts for the UIH packets */ 58 | #define LONG_CRC_CHECK 3 59 | /* Short header for short UIH packets */ 60 | #define SHORT_HDR 2 61 | /* Long header for long UIH packets */ 62 | #define LONG_HDR 3 63 | 64 | /* FIXME: Should this one be defined here? */ 65 | #define SHORT_PAYLOAD_SIZE 127 66 | /* Used for setting the EA field in different packets, really neccessary? */ 67 | #define EA 1 68 | /* Yes the FCS size is only one byte */ 69 | #define FCS_SIZE 1 70 | 71 | #define RFCOMM_MAX_HDR_SIZE 5 72 | 73 | #define MAX_CREDITS 30 74 | #define START_CREDITS 7 75 | #define MIN_CREDITS 6 76 | 77 | #define DEF_RFCOMM_MTU 127 78 | 79 | /* The values in the control field when sending ordinary rfcomm packets */ 80 | #define SABM 0x2f /* set asynchronous balanced mode */ 81 | #define UA 0x63 /* unnumbered acknolodgement */ 82 | #define DM 0x0f /* disconnected mode */ 83 | #define DISC 0x43 /* disconnect */ 84 | #define UIH 0xef /* unnumbered information with header check (only) */ 85 | #define UI 0x03 /* unnumbered information (with all data check) */ 86 | 87 | #define SABM_SIZE 4 88 | #define UA_SIZE 4 89 | 90 | /* The values in the type field in a multiplexer command packet */ 91 | #define PN (0x80 >> 2) /* parameter negotiation */ 92 | #define PSC (0x40 >> 2) /* power saving control */ 93 | #define CLD (0xc0 >> 2) /* close down */ 94 | #define TEST (0x20 >> 2) /* test */ 95 | #define FCON (0xa0 >> 2) /* flow control on */ 96 | #define FCOFF (0x60 >> 2) /* flow control off */ 97 | #define MSC (0xe0 >> 2) /* modem status command */ 98 | #define NSC (0x10 >> 2) /* not supported command response */ 99 | #define RPN (0x90 >> 2) /* remote port negotiation */ 100 | #define RLS (0x50 >> 2) /* remote line status */ 101 | #define SNC (0xd0 >> 2) /* service negotiation command */ 102 | 103 | /* Define of some V.24 signals modem control signals in RFCOMM */ 104 | #define DV 0x80 /* data valid */ 105 | #define IC 0x40 /* incoming call */ 106 | #define RTR 0x08 /* ready to receive */ 107 | #define RTC 0x04 /* ready to communicate */ 108 | #define FC 0x02 /* flow control (unable to accept frames) */ 109 | 110 | #define CTRL_CHAN 0 /* The control channel is defined as DLCI 0 in rfcomm */ 111 | #define MCC_CMD 1 /* Multiplexer command */ 112 | #define MCC_RSP 0 /* Multiplexer response */ 113 | 114 | #if __BYTE_ORDER == __LITTLE_ENDIAN 115 | 116 | typedef struct parameter_mask { 117 | uint8_t bit_rate:1; 118 | uint8_t data_bits:1; 119 | uint8_t stop_bit:1; 120 | uint8_t parity:1; 121 | uint8_t parity_type:1; 122 | uint8_t xon:1; 123 | uint8_t xoff:1; 124 | uint8_t res1:1; 125 | uint8_t xon_input:1; 126 | uint8_t xon_output:1; 127 | uint8_t rtr_input:1; 128 | uint8_t rtr_output:1; 129 | uint8_t rtc_input:1; 130 | uint8_t rtc_output:1; 131 | uint8_t res2:2; 132 | } __attribute__ ((packed)) parameter_mask; 133 | 134 | typedef struct rpn_values { 135 | uint8_t bit_rate; 136 | uint8_t data_bits:2; 137 | uint8_t stop_bit:1; 138 | uint8_t parity:1; 139 | uint8_t parity_type:2; 140 | uint8_t res1:2; 141 | uint8_t xon_input:1; 142 | uint8_t xon_output:1; 143 | uint8_t rtr_input:1; 144 | uint8_t rtr_output:1; 145 | uint8_t rtc_input:1; 146 | uint8_t rtc_output:1; 147 | uint8_t res2:2; 148 | uint8_t xon; 149 | uint8_t xoff; 150 | uint16_t pm; 151 | //parameter_mask pm; 152 | } __attribute__ ((packed)) rpn_values; 153 | 154 | #elif __BYTE_ORDER == __BIG_ENDIAN 155 | 156 | typedef struct parameter_mask { 157 | uint8_t res1:1; 158 | uint8_t xoff:1; 159 | uint8_t xon:1; 160 | uint8_t parity_type:1; 161 | uint8_t parity:1; 162 | uint8_t stop_bit:1; 163 | uint8_t data_bits:1; 164 | uint8_t bit_rate:1; 165 | uint8_t res2:2; 166 | uint8_t rtc_output:1; 167 | uint8_t rtc_input:1; 168 | uint8_t rtr_output:1; 169 | uint8_t rtr_input:1; 170 | uint8_t xon_output:1; 171 | uint8_t xon_input:1; 172 | 173 | } __attribute__ ((packed)) parameter_mask; 174 | 175 | typedef struct rpn_values { 176 | uint8_t bit_rate; 177 | uint8_t res1:2; 178 | uint8_t parity_type:2; 179 | uint8_t parity:1; 180 | uint8_t stop_bit:1; 181 | uint8_t data_bits:2; 182 | uint8_t res2:2; 183 | uint8_t rtc_output:1; 184 | uint8_t rtc_input:1; 185 | uint8_t rtr_output:1; 186 | uint8_t rtr_input:1; 187 | uint8_t xon_output:1; 188 | uint8_t xon_input:1; 189 | uint8_t xon; 190 | uint8_t xoff; 191 | uint16_t pm; 192 | //parameter_mask pm; 193 | } __attribute__ ((packed)) rpn_values; 194 | 195 | #else 196 | #error "Unknown byte order" 197 | #endif 198 | 199 | /* Typedefinitions of stuctures used for creating and parsing packets, for a 200 | * further description of the structures please se the bluetooth core 201 | * specification part F:1 and the ETSI TS 07.10 specification */ 202 | 203 | #if __BYTE_ORDER == __LITTLE_ENDIAN 204 | 205 | typedef struct address_field { 206 | uint8_t ea:1; 207 | uint8_t cr:1; 208 | uint8_t d:1; 209 | uint8_t server_chn:5; 210 | } __attribute__ ((packed)) address_field; 211 | 212 | typedef struct short_length { 213 | uint8_t ea:1; 214 | uint8_t len:7; 215 | } __attribute__ ((packed)) short_length; 216 | 217 | typedef union long_length { 218 | struct bits { 219 | uint8_t ea:1; 220 | unsigned short len:15; 221 | } __attribute__ ((packed)) bits ; 222 | uint16_t val ; 223 | } __attribute__ ((packed)) long_length; 224 | 225 | typedef struct short_frame_head { 226 | address_field addr; 227 | uint8_t control; 228 | short_length length; 229 | } __attribute__ ((packed)) short_frame_head; 230 | 231 | typedef struct short_frame { 232 | short_frame_head h; 233 | uint8_t data[0]; 234 | } __attribute__ ((packed)) short_frame; 235 | 236 | typedef struct long_frame_head { 237 | address_field addr; 238 | uint8_t control; 239 | long_length length; 240 | uint8_t data[0]; 241 | } __attribute__ ((packed)) long_frame_head; 242 | 243 | typedef struct long_frame { 244 | long_frame_head h; 245 | uint8_t data[0]; 246 | } __attribute__ ((packed)) long_frame; 247 | 248 | /* Typedefinitions for structures used for the multiplexer commands */ 249 | typedef struct mcc_type { 250 | uint8_t ea:1; 251 | uint8_t cr:1; 252 | uint8_t type:6; 253 | } __attribute__ ((packed)) mcc_type; 254 | 255 | typedef struct mcc_short_frame_head { 256 | mcc_type type; 257 | short_length length; 258 | uint8_t value[0]; 259 | } __attribute__ ((packed)) mcc_short_frame_head; 260 | 261 | typedef struct mcc_short_frame { 262 | mcc_short_frame_head h; 263 | uint8_t value[0]; 264 | } __attribute__ ((packed)) mcc_short_frame; 265 | 266 | typedef struct mcc_long_frame_head { 267 | mcc_type type; 268 | long_length length; 269 | uint8_t value[0]; 270 | } __attribute__ ((packed)) mcc_long_frame_head; 271 | 272 | typedef struct mcc_long_frame { 273 | mcc_long_frame_head h; 274 | uint8_t value[0]; 275 | } __attribute__ ((packed)) mcc_long_frame; 276 | 277 | /* MSC-command */ 278 | typedef struct v24_signals { 279 | uint8_t ea:1; 280 | uint8_t fc:1; 281 | uint8_t rtc:1; 282 | uint8_t rtr:1; 283 | uint8_t reserved:2; 284 | uint8_t ic:1; 285 | uint8_t dv:1; 286 | } __attribute__ ((packed)) v24_signals; 287 | 288 | typedef struct break_signals { 289 | uint8_t ea:1; 290 | uint8_t b1:1; 291 | uint8_t b2:1; 292 | uint8_t b3:1; 293 | uint8_t len:4; 294 | } __attribute__ ((packed)) break_signals; 295 | 296 | typedef struct msc_msg { 297 | short_frame_head s_head; 298 | mcc_short_frame_head mcc_s_head; 299 | address_field dlci; 300 | v24_signals v24_sigs; 301 | //break_signals break_sigs; 302 | uint8_t fcs; 303 | } __attribute__ ((packed)) msc_msg; 304 | 305 | typedef struct rpn_msg { 306 | short_frame_head s_head; 307 | mcc_short_frame_head mcc_s_head; 308 | address_field dlci; 309 | rpn_values rpn_val; 310 | uint8_t fcs; 311 | } __attribute__ ((packed)) rpn_msg; 312 | 313 | /* RLS-command */ 314 | typedef struct rls_msg { 315 | short_frame_head s_head; 316 | mcc_short_frame_head mcc_s_head; 317 | address_field dlci; 318 | uint8_t error:4; 319 | uint8_t res:4; 320 | uint8_t fcs; 321 | } __attribute__ ((packed)) rls_msg; 322 | 323 | /* PN-command */ 324 | typedef struct pn_msg { 325 | short_frame_head s_head; 326 | mcc_short_frame_head mcc_s_head; 327 | /* The res1, res2 and res3 values have to be set to 0 by the sender */ 328 | uint8_t dlci:6; 329 | uint8_t res1:2; 330 | uint8_t frame_type:4; 331 | uint8_t credit_flow:4; 332 | uint8_t prior:6; 333 | uint8_t res2:2; 334 | uint8_t ack_timer; 335 | uint16_t frame_size:16; 336 | uint8_t max_nbrof_retrans; 337 | uint8_t credits; 338 | uint8_t fcs; 339 | } __attribute__ ((packed)) pn_msg; 340 | 341 | /* NSC-command */ 342 | typedef struct nsc_msg { 343 | short_frame_head s_head; 344 | mcc_short_frame_head mcc_s_head; 345 | mcc_type command_type; 346 | uint8_t fcs; 347 | } __attribute__ ((packed)) nsc_msg; 348 | 349 | #elif __BYTE_ORDER == __BIG_ENDIAN 350 | 351 | typedef struct address_field { 352 | uint8_t server_chn:5; 353 | uint8_t d:1; 354 | uint8_t cr:1; 355 | uint8_t ea:1; 356 | } __attribute__ ((packed)) address_field; 357 | 358 | typedef struct short_length { 359 | uint8_t len:7; 360 | uint8_t ea:1; 361 | } __attribute__ ((packed)) short_length; 362 | 363 | typedef union long_length { 364 | struct bits { 365 | unsigned short len:15; 366 | uint8_t ea:1; 367 | } __attribute__ ((packed)) bits; 368 | uint16_t val; 369 | } __attribute__ ((packed)) long_length; 370 | 371 | typedef struct short_frame_head { 372 | address_field addr; 373 | uint8_t control; 374 | short_length length; 375 | } __attribute__ ((packed)) short_frame_head; 376 | 377 | typedef struct short_frame { 378 | short_frame_head h; 379 | uint8_t data[0]; 380 | } __attribute__ ((packed)) short_frame; 381 | 382 | typedef struct long_frame_head { 383 | address_field addr; 384 | uint8_t control; 385 | long_length length; 386 | uint8_t data[0]; 387 | } __attribute__ ((packed)) long_frame_head; 388 | 389 | typedef struct long_frame { 390 | long_frame_head h; 391 | uint8_t data[0]; 392 | } __attribute__ ((packed)) long_frame; 393 | 394 | typedef struct mcc_type { 395 | uint8_t type:6; 396 | uint8_t cr:1; 397 | uint8_t ea:1; 398 | } __attribute__ ((packed)) mcc_type; 399 | 400 | typedef struct mcc_short_frame_head { 401 | mcc_type type; 402 | short_length length; 403 | uint8_t value[0]; 404 | } __attribute__ ((packed)) mcc_short_frame_head; 405 | 406 | typedef struct mcc_short_frame { 407 | mcc_short_frame_head h; 408 | uint8_t value[0]; 409 | } __attribute__ ((packed)) mcc_short_frame; 410 | 411 | typedef struct mcc_long_frame_head { 412 | mcc_type type; 413 | long_length length; 414 | uint8_t value[0]; 415 | } __attribute__ ((packed)) mcc_long_frame_head; 416 | 417 | typedef struct mcc_long_frame { 418 | mcc_long_frame_head h; 419 | uint8_t value[0]; 420 | } __attribute__ ((packed)) mcc_long_frame; 421 | 422 | typedef struct v24_signals { 423 | uint8_t dv:1; 424 | uint8_t ic:1; 425 | uint8_t reserved:2; 426 | uint8_t rtr:1; 427 | uint8_t rtc:1; 428 | uint8_t fc:1; 429 | uint8_t ea:1; 430 | } __attribute__ ((packed)) v24_signals; 431 | 432 | typedef struct break_signals { 433 | uint8_t len:4; 434 | uint8_t b3:1; 435 | uint8_t b2:1; 436 | uint8_t b1:1; 437 | uint8_t ea:1; 438 | } __attribute__ ((packed)) break_signals; 439 | 440 | typedef struct msc_msg { 441 | short_frame_head s_head; 442 | mcc_short_frame_head mcc_s_head; 443 | address_field dlci; 444 | v24_signals v24_sigs; 445 | //break_signals break_sigs; 446 | uint8_t fcs; 447 | } __attribute__ ((packed)) msc_msg; 448 | 449 | typedef struct rpn_msg { 450 | short_frame_head s_head; 451 | mcc_short_frame_head mcc_s_head; 452 | address_field dlci; 453 | rpn_values rpn_val; 454 | uint8_t fcs; 455 | } __attribute__ ((packed)) rpn_msg; 456 | 457 | typedef struct rls_msg { 458 | short_frame_head s_head; 459 | mcc_short_frame_head mcc_s_head; 460 | address_field dlci; 461 | uint8_t res:4; 462 | uint8_t error:4; 463 | uint8_t fcs; 464 | } __attribute__ ((packed)) rls_msg; 465 | 466 | typedef struct pn_msg { 467 | short_frame_head s_head; 468 | mcc_short_frame_head mcc_s_head; 469 | uint8_t res1:2; 470 | uint8_t dlci:6; 471 | uint8_t credit_flow:4; 472 | uint8_t frame_type:4; 473 | uint8_t res2:2; 474 | uint8_t prior:6; 475 | uint8_t ack_timer; 476 | uint16_t frame_size:16; 477 | uint8_t max_nbrof_retrans; 478 | uint8_t credits; 479 | uint8_t fcs; 480 | } __attribute__ ((packed)) pn_msg; 481 | 482 | typedef struct nsc_msg { 483 | short_frame_head s_head; 484 | mcc_short_frame_head mcc_s_head; 485 | mcc_type command_type; 486 | uint8_t fcs; 487 | } __attribute__ ((packed)) nsc_msg; 488 | 489 | #else 490 | #error "Unknown byte order" 491 | #error Processor endianness unknown! 492 | #endif 493 | 494 | #endif /* __RFCOMM_H */ 495 | -------------------------------------------------------------------------------- /jni/parser/sdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2001-2002 Ricky Yuen 6 | * Copyright (C) 2003-2011 Marcel Holtmann 7 | * 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef __SDP_H 26 | #define __SDP_H 27 | 28 | /* Bluetooth assigned UUIDs for protocols */ 29 | #define SDP_UUID_SDP 0x0001 30 | #define SDP_UUID_UDP 0x0002 31 | #define SDP_UUID_RFCOMM 0x0003 32 | #define SDP_UUID_TCP 0x0004 33 | #define SDP_UUID_TCS_BIN 0x0005 34 | #define SDP_UUID_TCS_AT 0x0006 35 | #define SDP_UUID_OBEX 0x0008 36 | #define SDP_UUID_IP 0x0009 37 | #define SDP_UUID_FTP 0x000A 38 | #define SDP_UUID_HTTP 0x000C 39 | #define SDP_UUID_WSP 0x000E 40 | #define SDP_UUID_BNEP 0x000F /* PAN */ 41 | #define SDP_UUID_HIDP 0x0011 /* HID */ 42 | #define SDP_UUID_HARDCOPY_CONTROL_CHANNEL 0x0012 /* HCRP */ 43 | #define SDP_UUID_HARDCOPY_DATA_CHANNEL 0x0014 /* HCRP */ 44 | #define SDP_UUID_HARDCOPY_NOTIFICATION 0x0016 /* HCRP */ 45 | #define SDP_UUID_AVCTP 0x0017 /* AVCTP */ 46 | #define SDP_UUID_AVDTP 0x0019 /* AVDTP */ 47 | #define SDP_UUID_CMTP 0x001B /* CIP */ 48 | #define SDP_UUID_UDI_C_PLANE 0x001D /* UDI */ 49 | #define SDP_UUID_L2CAP 0x0100 50 | 51 | /* Bluetooth assigned UUIDs for Service Classes */ 52 | #define SDP_UUID_SERVICE_DISCOVERY_SERVER 0x1000 53 | #define SDP_UUID_BROWSE_GROUP_DESCRIPTOR 0x1001 54 | #define SDP_UUID_PUBLIC_BROWSE_GROUP 0x1002 55 | #define SDP_UUID_SERIAL_PORT 0x1101 56 | #define SDP_UUID_LAN_ACCESS_PPP 0x1102 57 | #define SDP_UUID_DIALUP_NETWORKING 0x1103 58 | #define SDP_UUID_IR_MC_SYNC 0x1104 59 | #define SDP_UUID_OBEX_OBJECT_PUSH 0x1105 60 | #define SDP_UUID_OBEX_FILE_TRANSFER 0x1106 61 | #define SDP_UUID_IR_MC_SYNC_COMMAND 0x1107 62 | #define SDP_UUID_HEADSET 0x1108 63 | #define SDP_UUID_CORDLESS_TELEPHONY 0x1109 64 | #define SDP_UUID_AUDIO_SOURCE 0x110a /* A2DP */ 65 | #define SDP_UUID_AUDIO_SINK 0x110b /* A2DP */ 66 | #define SDP_UUID_AV_REMOTE_TARGET 0x110c /* AVRCP */ 67 | #define SDP_UUID_ADVANCED_AUDIO 0x110d /* A2DP */ 68 | #define SDP_UUID_AV_REMOTE 0x110e /* AVRCP */ 69 | #define SDP_UUID_VIDEO_CONFERENCING 0x110f /* VCP */ 70 | #define SDP_UUID_INTERCOM 0x1110 71 | #define SDP_UUID_FAX 0x1111 72 | #define SDP_UUID_HEADSET_AUDIO_GATEWAY 0x1112 73 | #define SDP_UUID_WAP 0x1113 74 | #define SDP_UUID_WAP_CLIENT 0x1114 75 | #define SDP_UUID_PANU 0x1115 /* PAN */ 76 | #define SDP_UUID_NAP 0x1116 /* PAN */ 77 | #define SDP_UUID_GN 0x1117 /* PAN */ 78 | #define SDP_UUID_DIRECT_PRINTING 0x1118 /* BPP */ 79 | #define SDP_UUID_REFERENCE_PRINTING 0x1119 /* BPP */ 80 | #define SDP_UUID_IMAGING 0x111a /* BIP */ 81 | #define SDP_UUID_IMAGING_RESPONDER 0x111b /* BIP */ 82 | #define SDP_UUID_IMAGING_AUTOMATIC_ARCHIVE 0x111c /* BIP */ 83 | #define SDP_UUID_IMAGING_REFERENCED_OBJECTS 0x111d /* BIP */ 84 | #define SDP_UUID_HANDSFREE 0x111e 85 | #define SDP_UUID_HANDSFREE_AUDIO_GATEWAY 0x111f 86 | #define SDP_UUID_DIRECT_PRINTING_REF_OBJS 0x1120 /* BPP */ 87 | #define SDP_UUID_DIRECT_PRINTING_REFERENCE_OBJECTS 0x1120 /* BPP */ 88 | #define SDP_UUID_REFLECTED_UI 0x1121 /* BPP */ 89 | #define SDP_UUID_BASIC_PRINTING 0x1122 /* BPP */ 90 | #define SDP_UUID_PRINTING_STATUS 0x1123 /* BPP */ 91 | #define SDP_UUID_HUMAN_INTERFACE_DEVICE 0x1124 /* HID */ 92 | #define SDP_UUID_HARDCOPY_CABLE_REPLACE 0x1125 /* HCRP */ 93 | #define SDP_UUID_HCR_PRINT 0x1126 /* HCRP */ 94 | #define SDP_UUID_HCR_SCAN 0x1127 /* HCRP */ 95 | #define SDP_UUID_COMMON_ISDN_ACCESS 0x1128 /* CIP */ 96 | #define SDP_UUID_VIDEO_CONFERENCING_GW 0x1129 /* VCP */ 97 | #define SDP_UUID_UDI_MT 0x112a /* UDI */ 98 | #define SDP_UUID_UDI_TA 0x112b /* UDI */ 99 | #define SDP_UUID_AUDIO_VIDEO 0x112c /* VCP */ 100 | #define SDP_UUID_SIM_ACCESS 0x112d /* SAP */ 101 | #define SDP_UUID_PHONEBOOK_ACCESS_PCE 0x112e /* PBAP */ 102 | #define SDP_UUID_PHONEBOOK_ACCESS_PSE 0x112f /* PBAP */ 103 | #define SDP_UUID_PHONEBOOK_ACCESS 0x1130 /* PBAP */ 104 | #define SDP_UUID_PNP_INFORMATION 0x1200 105 | #define SDP_UUID_GENERIC_NETWORKING 0x1201 106 | #define SDP_UUID_GENERIC_FILE_TRANSFER 0x1202 107 | #define SDP_UUID_GENERIC_AUDIO 0x1203 108 | #define SDP_UUID_GENERIC_TELEPHONY 0x1204 109 | #define SDP_UUID_UPNP_SERVICE 0x1205 /* ESDP */ 110 | #define SDP_UUID_UPNP_IP_SERVICE 0x1206 /* ESDP */ 111 | #define SDP_UUID_ESDP_UPNP_IP_PAN 0x1300 /* ESDP */ 112 | #define SDP_UUID_ESDP_UPNP_IP_LAP 0x1301 /* ESDP */ 113 | #define SDP_UUID_ESDP_UPNP_L2CAP 0x1302 /* ESDP */ 114 | #define SDP_UUID_VIDEO_SOURCE 0x1303 /* VDP */ 115 | #define SDP_UUID_VIDEO_SINK 0x1304 /* VDP */ 116 | #define SDP_UUID_VIDEO_DISTRIBUTION 0x1305 /* VDP */ 117 | #define SDP_UUID_APPLE_AGENT 0x2112 118 | 119 | /* Bluetooth assigned numbers for Attribute IDs */ 120 | #define SDP_ATTR_ID_SERVICE_RECORD_HANDLE 0x0000 121 | #define SDP_ATTR_ID_SERVICE_CLASS_ID_LIST 0x0001 122 | #define SDP_ATTR_ID_SERVICE_RECORD_STATE 0x0002 123 | #define SDP_ATTR_ID_SERVICE_SERVICE_ID 0x0003 124 | #define SDP_ATTR_ID_PROTOCOL_DESCRIPTOR_LIST 0x0004 125 | #define SDP_ATTR_ID_BROWSE_GROUP_LIST 0x0005 126 | #define SDP_ATTR_ID_LANGUAGE_BASE_ATTRIBUTE_ID_LIST 0x0006 127 | #define SDP_ATTR_ID_SERVICE_INFO_TIME_TO_LIVE 0x0007 128 | #define SDP_ATTR_ID_SERVICE_AVAILABILITY 0x0008 129 | #define SDP_ATTR_ID_BLUETOOTH_PROFILE_DESCRIPTOR_LIST 0x0009 130 | #define SDP_ATTR_ID_DOCUMENTATION_URL 0x000A 131 | #define SDP_ATTR_ID_CLIENT_EXECUTABLE_URL 0x000B 132 | #define SDP_ATTR_ID_ICON_URL 0x000C 133 | #define SDP_ATTR_ID_ADDITIONAL_PROTOCOL_DESC_LISTS 0x000D 134 | #define SDP_ATTR_ID_SERVICE_NAME 0x0100 135 | #define SDP_ATTR_ID_SERVICE_DESCRIPTION 0x0101 136 | #define SDP_ATTR_ID_PROVIDER_NAME 0x0102 137 | #define SDP_ATTR_ID_VERSION_NUMBER_LIST 0x0200 138 | #define SDP_ATTR_ID_GROUP_ID 0x0200 139 | #define SDP_ATTR_ID_SERVICE_DATABASE_STATE 0x0201 140 | #define SDP_ATTR_ID_SERVICE_VERSION 0x0300 141 | 142 | #define SDP_ATTR_ID_EXTERNAL_NETWORK 0x0301 /* Cordless Telephony */ 143 | #define SDP_ATTR_ID_SUPPORTED_DATA_STORES_LIST 0x0301 /* Synchronization */ 144 | #define SDP_ATTR_ID_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 /* GAP */ 145 | #define SDP_ATTR_ID_SUPPORTED_FORMATS_LIST 0x0303 /* OBEX Object Push */ 146 | #define SDP_ATTR_ID_FAX_CLASS_1_SUPPORT 0x0302 /* Fax */ 147 | #define SDP_ATTR_ID_FAX_CLASS_2_0_SUPPORT 0x0303 148 | #define SDP_ATTR_ID_FAX_CLASS_2_SUPPORT 0x0304 149 | #define SDP_ATTR_ID_AUDIO_FEEDBACK_SUPPORT 0x0305 150 | #define SDP_ATTR_ID_SECURITY_DESCRIPTION 0x030a /* PAN */ 151 | #define SDP_ATTR_ID_NET_ACCESS_TYPE 0x030b /* PAN */ 152 | #define SDP_ATTR_ID_MAX_NET_ACCESS_RATE 0x030c /* PAN */ 153 | #define SDP_ATTR_ID_IPV4_SUBNET 0x030d /* PAN */ 154 | #define SDP_ATTR_ID_IPV6_SUBNET 0x030e /* PAN */ 155 | 156 | #define SDP_ATTR_ID_SUPPORTED_CAPABILITIES 0x0310 /* Imaging */ 157 | #define SDP_ATTR_ID_SUPPORTED_FEATURES 0x0311 /* Imaging and Hansfree */ 158 | #define SDP_ATTR_ID_SUPPORTED_FUNCTIONS 0x0312 /* Imaging */ 159 | #define SDP_ATTR_ID_TOTAL_IMAGING_DATA_CAPACITY 0x0313 /* Imaging */ 160 | #define SDP_ATTR_ID_SUPPORTED_REPOSITORIES 0x0314 /* PBAP */ 161 | 162 | #endif /* __SDP_H */ 163 | -------------------------------------------------------------------------------- /jni/parser/smp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2011 Intel Corporation. 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "parser/parser.h" 35 | 36 | /* SMP command codes */ 37 | #define SMP_CMD_PAIRING_REQ 0x01 38 | #define SMP_CMD_PAIRING_RESP 0x02 39 | #define SMP_CMD_PAIRING_CONFIRM 0x03 40 | #define SMP_CMD_PAIRING_RANDOM 0x04 41 | #define SMP_CMD_PAIRING_FAILED 0x05 42 | #define SMP_CMD_ENCRYPT_INFO 0x06 43 | #define SMP_CMD_MASTER_IDENT 0x07 44 | #define SMP_CMD_IDENT_INFO 0X08 45 | #define SMP_CMD_IDENT_ADDR_INFO 0x09 46 | #define SMP_CMD_SIGN_INFO 0x0a 47 | #define SMP_CMD_SECURITY_REQ 0x0b 48 | 49 | /* IO Capabilities values */ 50 | #define SMP_IO_DISPLAY_ONLY 0x00 51 | #define SMP_IO_DISPLAY_YESNO 0x01 52 | #define SMP_IO_KEYBOARD_ONLY 0x02 53 | #define SMP_IO_NO_INPUT_OUTPUT 0x03 54 | #define SMP_IO_KEYBOARD_DISPLAY 0x04 55 | 56 | /* OOB Data Present Values */ 57 | #define SMP_OOB_NOT_PRESENT 0x00 58 | #define SMP_OOB_PRESENT 0x01 59 | 60 | #define SMP_DIST_ENC_KEY 0x01 61 | #define SMP_DIST_ID_KEY 0x02 62 | #define SMP_DIST_SIGN 0x04 63 | 64 | #define SMP_AUTH_NONE 0x00 65 | #define SMP_AUTH_BONDING 0x01 66 | #define SMP_AUTH_MITM 0x04 67 | 68 | #define SMP_REASON_PASSKEY_ENTRY_FAILED 0x01 69 | #define SMP_REASON_OOB_NOT_AVAIL 0x02 70 | #define SMP_REASON_AUTH_REQUIREMENTS 0x03 71 | #define SMP_REASON_CONFIRM_FAILED 0x04 72 | #define SMP_REASON_PAIRING_NOTSUPP 0x05 73 | #define SMP_REASON_ENC_KEY_SIZE 0x06 74 | #define SMP_REASON_CMD_NOTSUPP 0x07 75 | #define SMP_REASON_UNSPECIFIED 0x08 76 | #define SMP_REASON_REPEATED_ATTEMPTS 0x09 77 | 78 | static const char *smpcmd2str(uint8_t cmd) 79 | { 80 | switch (cmd) { 81 | case SMP_CMD_PAIRING_REQ: 82 | return "Pairing Request"; 83 | case SMP_CMD_PAIRING_RESP: 84 | return "Pairing Response"; 85 | case SMP_CMD_PAIRING_CONFIRM: 86 | return "Pairing Confirm"; 87 | case SMP_CMD_PAIRING_RANDOM: 88 | return "Pairing Random"; 89 | case SMP_CMD_PAIRING_FAILED: 90 | return "Pairing Failed"; 91 | case SMP_CMD_ENCRYPT_INFO: 92 | return "Encryption Information"; 93 | case SMP_CMD_MASTER_IDENT: 94 | return "Master Identification"; 95 | case SMP_CMD_IDENT_INFO: 96 | return "Identity Information"; 97 | case SMP_CMD_IDENT_ADDR_INFO: 98 | return "Identity Address Information"; 99 | case SMP_CMD_SIGN_INFO: 100 | return "Signing Information"; 101 | case SMP_CMD_SECURITY_REQ: 102 | return "Security Request"; 103 | default: 104 | return "Unknown"; 105 | } 106 | } 107 | 108 | static const char *smpio2str(uint8_t cap) 109 | { 110 | switch(cap) { 111 | case SMP_IO_DISPLAY_ONLY: 112 | return "DisplayOnly"; 113 | case SMP_IO_DISPLAY_YESNO: 114 | return "DisplayYesNo"; 115 | case SMP_IO_KEYBOARD_ONLY: 116 | return "KeyboardOnly"; 117 | case SMP_IO_NO_INPUT_OUTPUT: 118 | return "NoInputNoOutput"; 119 | case SMP_IO_KEYBOARD_DISPLAY: 120 | return "KeyboardDisplay"; 121 | default: 122 | return "Unkown"; 123 | } 124 | } 125 | 126 | static const char *smpreason2str(uint8_t reason) 127 | { 128 | switch (reason) { 129 | case SMP_REASON_PASSKEY_ENTRY_FAILED: 130 | return "Passkey Entry Failed"; 131 | case SMP_REASON_OOB_NOT_AVAIL: 132 | return "OOB Not Available"; 133 | case SMP_REASON_AUTH_REQUIREMENTS: 134 | return "Authentication Requirements"; 135 | case SMP_REASON_CONFIRM_FAILED: 136 | return "Confirm Value Failed"; 137 | case SMP_REASON_PAIRING_NOTSUPP: 138 | return "Pairing Not Supported"; 139 | case SMP_REASON_ENC_KEY_SIZE: 140 | return "Encryption Key Size"; 141 | case SMP_REASON_CMD_NOTSUPP: 142 | return "Command Not Supported"; 143 | case SMP_REASON_UNSPECIFIED: 144 | return "Unspecified Reason"; 145 | case SMP_REASON_REPEATED_ATTEMPTS: 146 | return "Repeated Attempts"; 147 | default: 148 | return "Unkown"; 149 | } 150 | } 151 | 152 | static void smp_cmd_pairing_dump(int level, struct frame *frm) 153 | { 154 | uint8_t cap = get_u8(frm); 155 | uint8_t oob = get_u8(frm); 156 | uint8_t auth = get_u8(frm); 157 | uint8_t key_size = get_u8(frm); 158 | uint8_t int_dist = get_u8(frm); 159 | uint8_t resp_dist = get_u8(frm); 160 | 161 | p_indent(level, frm); 162 | printf("capability 0x%2.2x oob 0x%2.2x auth req 0x%2.2x\n", cap, oob, 163 | auth); 164 | 165 | p_indent(level , frm); 166 | printf("max key size 0x%2.2x init key dist 0x%2.2x " 167 | "resp key dist 0x%2.2x\n", key_size, int_dist, resp_dist); 168 | 169 | p_indent(level , frm); 170 | printf("Capability: %s (OOB data %s)\n", smpio2str(cap), 171 | oob == 0x00 ? "not present" : "available"); 172 | 173 | p_indent(level , frm); 174 | printf("Authentication: %s (%s)\n", 175 | auth & SMP_AUTH_BONDING ? "Bonding" : "No Bonding", 176 | auth & SMP_AUTH_MITM ? "MITM Protection" : 177 | "No MITM Protection"); 178 | 179 | p_indent(level , frm); 180 | printf("Initiator Key Distribution: %s %s %s\n", 181 | int_dist & SMP_DIST_ENC_KEY ? "LTK" : "", 182 | int_dist & SMP_DIST_ID_KEY ? "IRK" : "", 183 | int_dist & SMP_DIST_SIGN ? "CSRK" : ""); 184 | 185 | p_indent(level , frm); 186 | printf("Responder Key Distribution: %s %s %s\n", 187 | resp_dist & SMP_DIST_ENC_KEY ? "LTK" : "", 188 | resp_dist & SMP_DIST_ID_KEY ? "IRK" : "", 189 | resp_dist & SMP_DIST_SIGN ? "CSRK" : ""); 190 | } 191 | 192 | static void smp_cmd_pairing_confirm_dump(int level, struct frame *frm) 193 | { 194 | int i; 195 | 196 | p_indent(level, frm); 197 | printf("key "); 198 | for (i = 0; i < 16; i++) 199 | printf("%2.2x", get_u8(frm)); 200 | printf("\n"); 201 | } 202 | 203 | static void smp_cmd_pairing_random_dump(int level, struct frame *frm) 204 | { 205 | int i; 206 | 207 | p_indent(level, frm); 208 | printf("random "); 209 | for (i = 0; i < 16; i++) 210 | printf("%2.2x", get_u8(frm)); 211 | printf("\n"); 212 | } 213 | 214 | static void smp_cmd_pairing_failed_dump(int level, struct frame *frm) 215 | { 216 | uint8_t reason = get_u8(frm); 217 | 218 | p_indent(level, frm); 219 | printf("reason 0x%2.2x\n", reason); 220 | 221 | p_indent(level, frm); 222 | printf("Reason %s\n", smpreason2str(reason)); 223 | } 224 | 225 | static void smp_cmd_encrypt_info_dump(int level, struct frame *frm) 226 | { 227 | int i; 228 | 229 | p_indent(level, frm); 230 | printf("LTK "); 231 | for (i = 0; i < 16; i++) 232 | printf("%2.2x", get_u8(frm)); 233 | printf("\n"); 234 | } 235 | 236 | static void smp_cmd_master_ident_dump(int level, struct frame *frm) 237 | { 238 | uint16_t ediv = btohs(htons(get_u16(frm))); 239 | int i; 240 | 241 | p_indent(level, frm); 242 | printf("EDIV 0x%4.4x ", ediv); 243 | 244 | printf("Rand 0x"); 245 | for (i = 0; i < 8; i++) 246 | printf("%2.2x", get_u8(frm)); 247 | printf("\n"); 248 | } 249 | 250 | static void smp_cmd_ident_info_dump(int level, struct frame *frm) 251 | { 252 | int i; 253 | 254 | p_indent(level, frm); 255 | printf("IRK "); 256 | for (i = 0; i < 16; i++) 257 | printf("%2.2x", get_u8(frm)); 258 | printf("\n"); 259 | } 260 | 261 | static void smp_cmd_ident_addr_info_dump(int level, struct frame *frm) 262 | { 263 | uint8_t type = get_u8(frm); 264 | char addr[18]; 265 | 266 | p_indent(level, frm); 267 | p_ba2str((bdaddr_t *) frm, addr); 268 | printf("bdaddr %s (%s)\n", addr, type == 0x00 ? "Public" : "Random"); 269 | } 270 | 271 | static void smp_cmd_sign_info_dump(int level, struct frame *frm) 272 | { 273 | int i; 274 | 275 | p_indent(level, frm); 276 | printf("CSRK "); 277 | for (i = 0; i < 16; i++) 278 | printf("%2.2x", get_u8(frm)); 279 | printf("\n"); 280 | } 281 | 282 | static void smp_cmd_security_req_dump(int level, struct frame *frm) 283 | { 284 | uint8_t auth = get_u8(frm); 285 | 286 | p_indent(level, frm); 287 | printf("auth req 0x%2.2x\n", auth); 288 | } 289 | 290 | void smp_dump(int level, struct frame *frm) 291 | { 292 | uint8_t cmd; 293 | 294 | cmd = get_u8(frm); 295 | 296 | p_indent(level, frm); 297 | printf("SMP: %s (0x%.2x)\n", smpcmd2str(cmd), cmd); 298 | 299 | switch (cmd) { 300 | case SMP_CMD_PAIRING_REQ: 301 | smp_cmd_pairing_dump(level + 1, frm); 302 | break; 303 | case SMP_CMD_PAIRING_RESP: 304 | smp_cmd_pairing_dump(level + 1, frm); 305 | break; 306 | case SMP_CMD_PAIRING_CONFIRM: 307 | smp_cmd_pairing_confirm_dump(level + 1, frm); 308 | break; 309 | case SMP_CMD_PAIRING_RANDOM: 310 | smp_cmd_pairing_random_dump(level + 1, frm); 311 | break; 312 | case SMP_CMD_PAIRING_FAILED: 313 | smp_cmd_pairing_failed_dump(level + 1, frm); 314 | break; 315 | case SMP_CMD_ENCRYPT_INFO: 316 | smp_cmd_encrypt_info_dump(level + 1, frm); 317 | break; 318 | case SMP_CMD_MASTER_IDENT: 319 | smp_cmd_master_ident_dump(level + 1, frm); 320 | break; 321 | case SMP_CMD_IDENT_INFO: 322 | smp_cmd_ident_info_dump(level + 1, frm); 323 | break; 324 | case SMP_CMD_IDENT_ADDR_INFO: 325 | smp_cmd_ident_addr_info_dump(level + 1, frm); 326 | break; 327 | case SMP_CMD_SIGN_INFO: 328 | smp_cmd_sign_info_dump(level + 1, frm); 329 | break; 330 | case SMP_CMD_SECURITY_REQ: 331 | smp_cmd_security_req_dump(level + 1, frm); 332 | break; 333 | default: 334 | raw_dump(level, frm); 335 | } 336 | } 337 | -------------------------------------------------------------------------------- /jni/parser/tcpip.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2003-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "parser/parser.h" 43 | 44 | void arp_dump(int level, struct frame *frm) 45 | { 46 | #if 0 47 | int i; 48 | char buf[20]; 49 | struct sockaddr_in sai; 50 | struct ether_arp *arp = (struct ether_arp *) frm->ptr; 51 | 52 | printf("Src "); 53 | for (i = 0; i < 5; i++) 54 | printf("%02x:", arp->arp_sha[i]); 55 | printf("%02x", arp->arp_sha[5]); 56 | sai.sin_family = AF_INET; 57 | memcpy(&sai.sin_addr, &arp->arp_spa, sizeof(sai.sin_addr)); 58 | getnameinfo((struct sockaddr *) &sai, sizeof(sai), buf, sizeof(buf), 59 | NULL, 0, NI_NUMERICHOST); 60 | printf("(%s) ", buf); 61 | printf("Tgt "); 62 | for (i = 0; i < 5; i++) 63 | printf("%02x:", arp->arp_tha[i]); 64 | printf("%02x", arp->arp_tha[5]); 65 | memcpy(&sai.sin_addr, &arp->arp_tpa, sizeof(sai.sin_addr)); 66 | getnameinfo((struct sockaddr *) &sai, sizeof(sai), buf, sizeof(buf), 67 | NULL, 0, NI_NUMERICHOST); 68 | printf("(%s)\n", buf); 69 | frm->ptr += sizeof(struct ether_arp); 70 | frm->len -= sizeof(struct ether_arp); 71 | raw_dump(level, frm); // not needed. 72 | #endif 73 | } 74 | 75 | void ip_dump(int level, struct frame *frm) 76 | { 77 | char src[50], dst[50]; 78 | struct ip *ip = (struct ip *) (frm->ptr); 79 | uint8_t proto; 80 | int len; 81 | 82 | if (ip->ip_v == 4) { 83 | struct sockaddr_in sai; 84 | proto = ip->ip_p; 85 | len = ip->ip_hl << 2; 86 | memset(&sai, 0, sizeof(sai)); 87 | sai.sin_family = AF_INET; 88 | memcpy(&sai.sin_addr, &ip->ip_src, sizeof(struct in_addr)); 89 | getnameinfo((struct sockaddr *) &sai, sizeof(sai), 90 | src, sizeof(src), NULL, 0, NI_NUMERICHOST); 91 | memcpy(&sai.sin_addr, &ip->ip_dst, sizeof(struct in_addr)); 92 | getnameinfo((struct sockaddr *) &sai, sizeof(sai), 93 | dst, sizeof(dst), NULL, 0, NI_NUMERICHOST); 94 | } else if (ip->ip_v == 6) { 95 | struct sockaddr_in6 sai6; 96 | struct ip6_hdr *ip6 = (struct ip6_hdr *) ip; 97 | proto = ip6->ip6_nxt; 98 | len = sizeof(struct ip6_hdr); 99 | memset(&sai6, 0, sizeof(sai6)); 100 | sai6.sin6_family = AF_INET6; 101 | memcpy(&sai6.sin6_addr, &ip6->ip6_src, sizeof(struct in6_addr)); 102 | getnameinfo((struct sockaddr *) &sai6, sizeof(sai6), 103 | src, sizeof(src), NULL, 0, NI_NUMERICHOST); 104 | memcpy(&sai6.sin6_addr, &ip6->ip6_dst, sizeof(struct in6_addr)); 105 | getnameinfo((struct sockaddr *) &sai6, sizeof(sai6), 106 | dst, sizeof(dst), NULL, 0, NI_NUMERICHOST); 107 | } else { 108 | raw_dump(level, frm); 109 | return; 110 | } 111 | 112 | printf("src %s ", src); 113 | printf("dst %s\n", dst); 114 | 115 | frm->ptr += len; 116 | frm->len -= len; 117 | p_indent(++level, frm); 118 | 119 | switch (proto) { 120 | case IPPROTO_TCP: 121 | printf("TCP:\n"); 122 | break; 123 | 124 | case IPPROTO_UDP: 125 | printf("UDP:\n"); 126 | break; 127 | 128 | case IPPROTO_ICMP: 129 | printf("ICMP:\n"); 130 | break; 131 | 132 | case IPPROTO_ICMPV6: 133 | printf("ICMPv6:\n"); 134 | break; 135 | 136 | default: 137 | printf("Unknown Protocol: 0x%02x\n", ip->ip_p); 138 | break; 139 | } 140 | 141 | raw_dump(level, frm); 142 | } 143 | -------------------------------------------------------------------------------- /jni/src/bpasniff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "parser/parser.h" 40 | #include "lib/hci.h" 41 | #include "lib/hci_lib.h" 42 | 43 | static volatile sig_atomic_t __io_canceled = 0; 44 | 45 | static void sig_hup(int sig) 46 | { 47 | } 48 | 49 | static void sig_term(int sig) 50 | { 51 | __io_canceled = 1; 52 | } 53 | 54 | static int read_revision(int dd, char *revision, int size) 55 | { 56 | struct hci_request rq; 57 | unsigned char req[] = { 0x07 }; 58 | unsigned char buf[46]; 59 | 60 | memset(&rq, 0, sizeof(rq)); 61 | rq.ogf = OGF_VENDOR_CMD; 62 | rq.ocf = 0x000e; 63 | rq.cparam = req; 64 | rq.clen = sizeof(req); 65 | rq.rparam = &buf; 66 | rq.rlen = sizeof(buf); 67 | 68 | if (hci_send_req(dd, &rq, 1000) < 0) 69 | return -1; 70 | 71 | if (buf[0] > 0) { 72 | errno = EIO; 73 | return -1; 74 | } 75 | 76 | if (revision) 77 | strncpy(revision, (char *) (buf + 1), size); 78 | 79 | return 0; 80 | } 81 | 82 | static int enable_sniffer(int dd, uint8_t enable) 83 | { 84 | struct hci_request rq; 85 | unsigned char req[] = { 0x00, enable }; 86 | unsigned char buf[1]; 87 | 88 | memset(&rq, 0, sizeof(rq)); 89 | rq.ogf = OGF_VENDOR_CMD; 90 | rq.ocf = 0x000e; 91 | rq.cparam = req; 92 | rq.clen = sizeof(req); 93 | rq.rparam = &buf; 94 | rq.rlen = sizeof(buf); 95 | 96 | if (hci_send_req(dd, &rq, 1000) < 0) 97 | return -1; 98 | 99 | if (buf[0] > 0) { 100 | errno = EIO; 101 | return -1; 102 | } 103 | 104 | return 0; 105 | } 106 | 107 | static int enable_sync(int dd, uint8_t enable, bdaddr_t *bdaddr) 108 | { 109 | struct hci_request rq; 110 | unsigned char req[] = { 0x01, enable, 111 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 112 | 0x00, 0xfa, 0x00 }; 113 | 114 | memcpy(req + 2, bdaddr, 6); 115 | 116 | memset(&rq, 0, sizeof(rq)); 117 | rq.ogf = OGF_VENDOR_CMD; 118 | rq.ocf = 0x000e; 119 | rq.cparam = req; 120 | rq.clen = sizeof(req); 121 | 122 | hci_send_req(dd, &rq, 1000); 123 | 124 | return 0; 125 | } 126 | 127 | static char *type2str(uint8_t type) 128 | { 129 | switch (type) { 130 | case 0x00: 131 | return "NULL"; 132 | case 0x01: 133 | return "POLL"; 134 | case 0x02: 135 | return "FHS"; 136 | case 0x03: 137 | return "DM1"; 138 | case 0x04: 139 | return "DH1"; 140 | case 0x05: 141 | return "HV1"; 142 | case 0x06: 143 | return "HV2"; 144 | case 0x07: 145 | return "HV3"; 146 | case 0x08: 147 | return "DV"; 148 | case 0x09: 149 | return "AUX1"; 150 | case 0x0a: 151 | return "DM3"; 152 | case 0x0b: 153 | return "DH3"; 154 | case 0x0c: 155 | return "EV4"; 156 | case 0x0d: 157 | return "EV5"; 158 | case 0x0e: 159 | return "DM5"; 160 | case 0x0f: 161 | return "DH5"; 162 | case 0xff: 163 | return "ID"; 164 | default: 165 | return "UNK"; 166 | } 167 | } 168 | 169 | static void decode(unsigned char *buf, int count) 170 | { 171 | struct frame frm; 172 | uint8_t id, status, channel; 173 | uint16_t num, len; 174 | uint32_t time; 175 | uint8_t type, addr, temp, hdr; 176 | uint8_t flow, arqn, seqn, hec, llid, pflow; 177 | uint16_t plen; 178 | 179 | if (count < 7) 180 | return; 181 | 182 | id = buf[0]; 183 | num = ntohs(bt_get_unaligned((uint16_t *) (buf + 1))); 184 | len = btohs(bt_get_unaligned((uint16_t *) (buf + 3))); 185 | 186 | status = buf[5]; 187 | time = ntohl(bt_get_unaligned((uint32_t *) (buf + 6))); 188 | channel = buf[10]; 189 | 190 | if (len < 8) 191 | return; 192 | 193 | type = (len < 7) ? 0xff : bt_get_unaligned((uint8_t *) (buf + 11)); 194 | 195 | if (type < 2) 196 | return; 197 | 198 | p_indent(-1, NULL); 199 | 200 | memset(&frm, 0, sizeof(frm)); 201 | frm.data = buf + 12; 202 | frm.data_len = count - 12; 203 | frm.ptr = frm.data; 204 | frm.len = frm.data_len; 205 | frm.in = 0; 206 | frm.master = 0; 207 | frm.handle = 0; 208 | frm.flags = 0; 209 | 210 | p_indent(0, &frm); 211 | 212 | printf("BPA: id %d num %d status 0x%02x time %d channel %2d len %d\n", 213 | id, num, status, time, channel, len - 6); 214 | 215 | if (type < 3) { 216 | printf(" %s\n", type2str(type)); 217 | raw_dump(1, &frm); 218 | return; 219 | } 220 | 221 | addr = bt_get_unaligned((uint8_t *) (buf + 12)); 222 | temp = bt_get_unaligned((uint8_t *) (buf + 13)); 223 | flow = (temp & 0x04) >> 2; 224 | arqn = (temp & 0x02) >> 1; 225 | seqn = (temp & 0x01); 226 | hec = bt_get_unaligned((uint8_t *) (buf + 14)); 227 | 228 | hdr = bt_get_unaligned((uint8_t *) (buf + 20)); 229 | plen = ((hdr & 0x10) >> 4) | ((hdr & 0x08) >> 2) | (hdr & 0x04) | ((hdr & 0x02) << 2) | ((hdr & 0x01) << 4); 230 | pflow = ((hdr & 0x20) >> 5); 231 | llid = ((hdr & 0x80) >> 7) | ((hdr & 0x40) >> 5); 232 | hdr = bt_get_unaligned((uint8_t *) (buf + 21)); 233 | plen = plen | ((hdr & 0x80) >> 2) | (hdr & 0x40) | ((hdr & 0x20) << 2) | ((hdr & 0x08) << 4); 234 | 235 | p_indent(0, &frm); 236 | 237 | printf("%s: addr 0x%02x flow %d arqn %d seqn %d hec 0x%02x llid %d pflow %d plen %d\n", 238 | type2str(type), addr, flow, arqn, seqn, hec, llid, pflow, plen); 239 | 240 | if (type == 0x03 && llid == 3) { 241 | memset(&frm, 0, sizeof(frm)); 242 | frm.data = buf + 22; 243 | frm.data_len = plen; 244 | frm.ptr = frm.data; 245 | frm.len = frm.data_len; 246 | frm.in = 0; 247 | frm.master = 1; 248 | frm.handle = 0; 249 | frm.flags = llid; 250 | 251 | lmp_dump(1, &frm); 252 | return; 253 | } 254 | 255 | raw_dump(1, &frm); 256 | } 257 | 258 | static void process_frames(int dev) 259 | { 260 | struct sigaction sa; 261 | struct hci_filter flt; 262 | unsigned char *buf; 263 | int dd, size = 2048; 264 | 265 | buf = malloc(size); 266 | if (!buf) { 267 | fprintf(stderr, "Can't allocate buffer for hci%d: %s (%d)\n", 268 | dev, strerror(errno), errno); 269 | return; 270 | } 271 | 272 | dd = hci_open_dev(dev); 273 | if (dd < 0) { 274 | fprintf(stderr, "Can't open device hci%d: %s (%d)\n", 275 | dev, strerror(errno), errno); 276 | free(buf); 277 | return; 278 | } 279 | 280 | hci_filter_clear(&flt); 281 | hci_filter_set_ptype(HCI_VENDOR_PKT, &flt); 282 | hci_filter_set_ptype(HCI_EVENT_PKT, &flt); 283 | hci_filter_set_event(EVT_VENDOR, &flt); 284 | 285 | if (setsockopt(dd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { 286 | fprintf(stderr, "Can't set filter for hci%d: %s (%d)\n", 287 | dev, strerror(errno), errno); 288 | hci_close_dev(dd); 289 | free(buf); 290 | return; 291 | } 292 | 293 | memset(&sa, 0, sizeof(sa)); 294 | sa.sa_flags = SA_NOCLDSTOP; 295 | sa.sa_handler = SIG_IGN; 296 | sigaction(SIGCHLD, &sa, NULL); 297 | sigaction(SIGPIPE, &sa, NULL); 298 | 299 | sa.sa_handler = sig_term; 300 | sigaction(SIGTERM, &sa, NULL); 301 | sigaction(SIGINT, &sa, NULL); 302 | 303 | sa.sa_handler = sig_hup; 304 | sigaction(SIGHUP, &sa, NULL); 305 | 306 | while (!__io_canceled) { 307 | int len; 308 | 309 | len = read(dd, buf, size); 310 | if (len < 0) 311 | break; 312 | if (len < 2) 313 | continue; 314 | 315 | if (buf[0] == 0x04 && buf[1] == 0xff) { 316 | if (buf[3] == 0x02) { 317 | switch (buf[4]) { 318 | case 0x00: 319 | printf("Waiting for synchronization...\n"); 320 | break; 321 | case 0x08: 322 | printf("Synchronization lost\n"); 323 | __io_canceled = 1; 324 | break; 325 | default: 326 | printf("Unknown event 0x%02x\n", buf[4]); 327 | break; 328 | } 329 | } 330 | } 331 | 332 | if (buf[0] != 0xff) 333 | continue; 334 | 335 | decode(buf + 1, len - 1); 336 | } 337 | 338 | hci_close_dev(dd); 339 | 340 | free(buf); 341 | } 342 | 343 | static void usage(void) 344 | { 345 | printf("bpasniff - Utility for the BPA 100/105 sniffers\n\n"); 346 | printf("Usage:\n" 347 | "\tbpasniff [-i ] \n"); 348 | } 349 | 350 | static struct option main_options[] = { 351 | { "help", 0, 0, 'h' }, 352 | { "device", 1, 0, 'i' }, 353 | { 0, 0, 0, 0} 354 | }; 355 | 356 | int main(int argc, char *argv[]) 357 | { 358 | struct hci_dev_info di; 359 | struct hci_version ver; 360 | char rev[46]; 361 | bdaddr_t bdaddr; 362 | int dd, opt, dev = 0; 363 | 364 | bacpy(&bdaddr, BDADDR_ANY); 365 | 366 | while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) { 367 | switch (opt) { 368 | case 'i': 369 | dev = hci_devid(optarg); 370 | if (dev < 0) { 371 | perror("Invalid device"); 372 | exit(1); 373 | } 374 | break; 375 | 376 | case 'h': 377 | default: 378 | usage(); 379 | exit(0); 380 | } 381 | } 382 | 383 | argc -= optind; 384 | argv += optind; 385 | optind = 0; 386 | 387 | argc -= optind; 388 | argv += optind; 389 | optind = 0; 390 | 391 | if (argc < 1) { 392 | usage(); 393 | exit(1); 394 | } 395 | 396 | str2ba(argv[0], &bdaddr); 397 | 398 | dd = hci_open_dev(dev); 399 | if (dd < 0) { 400 | fprintf(stderr, "Can't open device hci%d: %s (%d)\n", 401 | dev, strerror(errno), errno); 402 | exit(1); 403 | } 404 | 405 | if (hci_devinfo(dev, &di) < 0) { 406 | fprintf(stderr, "Can't get device info for hci%d: %s (%d)\n", 407 | dev, strerror(errno), errno); 408 | hci_close_dev(dd); 409 | exit(1); 410 | } 411 | 412 | if (hci_read_local_version(dd, &ver, 1000) < 0) { 413 | fprintf(stderr, "Can't read version info for hci%d: %s (%d)\n", 414 | dev, strerror(errno), errno); 415 | hci_close_dev(dd); 416 | exit(1); 417 | } 418 | 419 | if (ver.manufacturer != 12) { 420 | fprintf(stderr, "Can't find sniffer at hci%d: %s (%d)\n", 421 | dev, strerror(ENOSYS), ENOSYS); 422 | hci_close_dev(dd); 423 | exit(1); 424 | } 425 | 426 | if (read_revision(dd, rev, sizeof(rev)) < 0) { 427 | fprintf(stderr, "Can't read revision info for hci%d: %s (%d)\n", 428 | dev, strerror(errno), errno); 429 | hci_close_dev(dd); 430 | exit(1); 431 | } 432 | 433 | printf("%s\n", rev); 434 | 435 | if (enable_sniffer(dd, 0x01) < 0) { 436 | fprintf(stderr, "Can't enable sniffer for hci%d: %s (%d)\n", 437 | dev, strerror(errno), errno); 438 | hci_close_dev(dd); 439 | exit(1); 440 | } 441 | 442 | if (enable_sync(dd, 0x01, &bdaddr) < 0) { 443 | fprintf(stderr, "Can't enable sync for hci%d: %s (%d)\n", 444 | dev, strerror(errno), errno); 445 | enable_sniffer(dd, 0x00); 446 | hci_close_dev(dd); 447 | exit(1); 448 | } 449 | 450 | init_parser(DUMP_EXT | DUMP_VERBOSE, ~0L, 0, DEFAULT_COMPID, -1, -1); 451 | 452 | process_frames(dev); 453 | 454 | if (enable_sync(dd, 0x00, &bdaddr) < 0) { 455 | fprintf(stderr, "Can't disable sync for hci%d: %s (%d)\n", 456 | dev, strerror(errno), errno); 457 | enable_sniffer(dd, 0x00); 458 | hci_close_dev(dd); 459 | exit(1); 460 | } 461 | 462 | if (enable_sniffer(dd, 0x00) < 0) { 463 | fprintf(stderr, "Can't disable sniffer for hci%d: %s (%d)\n", 464 | dev, strerror(errno), errno); 465 | hci_close_dev(dd); 466 | exit(1); 467 | } 468 | 469 | hci_close_dev(dd); 470 | 471 | return 0; 472 | } 473 | -------------------------------------------------------------------------------- /jni/src/csrsniff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * BlueZ - Bluetooth protocol stack for Linux 4 | * 5 | * Copyright (C) 2004-2011 Marcel Holtmann 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "parser/parser.h" 38 | #include "lib/hci.h" 39 | #include "lib/hci_lib.h" 40 | 41 | static volatile sig_atomic_t __io_canceled = 0; 42 | 43 | static void sig_hup(int sig) 44 | { 45 | } 46 | 47 | static void sig_term(int sig) 48 | { 49 | __io_canceled = 1; 50 | } 51 | 52 | static struct { 53 | uint16_t id; 54 | uint16_t ver; 55 | char *date; 56 | } firmware_map[] = { 57 | { 195, 1, "2001-11-27" }, 58 | { 220, 2, "2002-01-03" }, 59 | { 269, 3, "2002-02-22" }, 60 | { 270, 4, "2002-02-26" }, 61 | { 284, 5, "2002-03-12" }, 62 | { 292, 6, "2002-03-20" }, 63 | { 305, 7, "2002-04-12" }, 64 | { 306, 8, "2002-04-12" }, 65 | { 343, 9, "2002-05-02" }, 66 | { 346, 10, "2002-05-03" }, 67 | { 355, 11, "2002-05-16" }, 68 | { 256, 11, "2002-05-16" }, 69 | { 390, 12, "2002-06-26" }, 70 | { 450, 13, "2002-08-16" }, 71 | { 451, 13, "2002-08-16" }, 72 | { 533, 14, "2002-10-11" }, 73 | { 580, 15, "2002-11-14" }, 74 | { 623, 16, "2002-12-12" }, 75 | { 678, 17, "2003-01-29" }, 76 | { 847, 18, "2003-04-17" }, 77 | { 876, 19, "2003-06-10" }, 78 | { 997, 22, "2003-09-05" }, 79 | { 1027, 23, "2003-10-03" }, 80 | { 1029, 24, "2003-10-03" }, 81 | { 1112, 25, "2003-12-03" }, 82 | { 1113, 25, "2003-12-03" }, 83 | { 1133, 26, "2003-12-18" }, 84 | { 1134, 26, "2003-12-18" }, 85 | { 1223, 27, "2004-03-08" }, 86 | { 1224, 27, "2004-03-08" }, 87 | { 1319, 31, "2004-04-22" }, 88 | { 1320, 31, "2004-04-22" }, 89 | { 1427, 34, "2004-06-16" }, 90 | { 1508, 35, "2004-07-19" }, 91 | { 1509, 35, "2004-07-19" }, 92 | { 1587, 36, "2004-08-18" }, 93 | { 1588, 36, "2004-08-18" }, 94 | { 1641, 37, "2004-09-16" }, 95 | { 1642, 37, "2004-09-16" }, 96 | { 1699, 38, "2004-10-07" }, 97 | { 1700, 38, "2004-10-07" }, 98 | { 1752, 39, "2004-11-02" }, 99 | { 1753, 39, "2004-11-02" }, 100 | { 1759, 40, "2004-11-03" }, 101 | { 1760, 40, "2004-11-03" }, 102 | { 1761, 40, "2004-11-03" }, 103 | { 2009, 41, "2005-04-06" }, 104 | { 2010, 41, "2005-04-06" }, 105 | { 2011, 41, "2005-04-06" }, 106 | { 2016, 42, "2005-04-11" }, 107 | { 2017, 42, "2005-04-11" }, 108 | { 2018, 42, "2005-04-11" }, 109 | { 2023, 43, "2005-04-14" }, 110 | { 2024, 43, "2005-04-14" }, 111 | { 2025, 43, "2005-04-14" }, 112 | { 2032, 44, "2005-04-18" }, 113 | { 2033, 44, "2005-04-18" }, 114 | { 2034, 44, "2005-04-18" }, 115 | { 2288, 45, "2005-07-08" }, 116 | { 2289, 45, "2005-07-08" }, 117 | { 2290, 45, "2005-07-08" }, 118 | { 2388, 46, "2005-08-17" }, 119 | { 2389, 46, "2005-08-17" }, 120 | { 2390, 46, "2005-08-17" }, 121 | { 2869, 47, "2006-02-15" }, 122 | { 2870, 47, "2006-02-15" }, 123 | { 2871, 47, "2006-02-15" }, 124 | { 3214, 48, "2006-02-16" }, 125 | { 3215, 48, "2006-02-16" }, 126 | { 3216, 48, "2006-02-16" }, 127 | { 0, } 128 | }; 129 | 130 | static int id2ver(uint16_t id) 131 | { 132 | int i; 133 | 134 | for (i = 0; firmware_map[i].id; i++) 135 | if (firmware_map[i].id == id) 136 | return firmware_map[i].ver; 137 | 138 | return -1; 139 | } 140 | 141 | static void usage(void) 142 | { 143 | printf("csrsniff - Utility for the CSR BlueCore sniffers\n\n"); 144 | printf("Usage:\n" 145 | "\tcsrsniff [-i ] [slave-bdaddr]\n"); 146 | } 147 | 148 | static struct option main_options[] = { 149 | { "help", 0, 0, 'h' }, 150 | { "device", 1, 0, 'i' }, 151 | { 0, 0, 0, 0} 152 | }; 153 | 154 | int main(int argc, char *argv[]) 155 | { 156 | struct sigaction sa; 157 | struct hci_dev_info di; 158 | struct hci_version ver; 159 | struct hci_filter flt; 160 | bdaddr_t bdaddr, master, slave; 161 | int need_raw; 162 | int dd, opt, dev = 0; 163 | 164 | bacpy(&slave, BDADDR_ANY); 165 | 166 | while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) { 167 | switch (opt) { 168 | case 'i': 169 | dev = hci_devid(optarg); 170 | if (dev < 0) { 171 | perror("Invalid device"); 172 | exit(1); 173 | } 174 | break; 175 | 176 | case 'h': 177 | default: 178 | usage(); 179 | exit(0); 180 | } 181 | } 182 | 183 | argc -= optind; 184 | argv += optind; 185 | optind = 0; 186 | 187 | if (argc < 1) { 188 | usage(); 189 | exit(1); 190 | } 191 | 192 | str2ba(argv[0], &master); 193 | 194 | if (argc > 1) 195 | str2ba(argv[1], &slave); 196 | 197 | dd = hci_open_dev(dev); 198 | if (dd < 0) { 199 | fprintf(stderr, "Can't open device hci%d: %s (%d)\n", 200 | dev, strerror(errno), errno); 201 | exit(1); 202 | } 203 | 204 | if (hci_devinfo(dev, &di) < 0) { 205 | fprintf(stderr, "Can't get device info for hci%d: %s (%d)\n", 206 | dev, strerror(errno), errno); 207 | hci_close_dev(dd); 208 | exit(1); 209 | } 210 | 211 | if (hci_read_local_version(dd, &ver, 1000) < 0) { 212 | fprintf(stderr, "Can't read version for hci%d: %s (%d)\n", 213 | dev, strerror(errno), errno); 214 | hci_close_dev(dd); 215 | exit(1); 216 | } 217 | 218 | if (ver.manufacturer != 10 || id2ver(ver.hci_rev) < 0) { 219 | fprintf(stderr, "Can't find sniffer at hci%d: %s (%d)\n", 220 | dev, strerror(ENOSYS), ENOSYS); 221 | hci_close_dev(dd); 222 | exit(1); 223 | } 224 | 225 | if (!bacmp(&di.bdaddr, BDADDR_ANY)) { 226 | if (hci_read_bd_addr(dd, &bdaddr, 1000) < 0) { 227 | fprintf(stderr, "Can't read address for hci%d: %s (%d)\n", 228 | dev, strerror(errno), errno); 229 | hci_close_dev(dd); 230 | exit(1); 231 | } 232 | } else 233 | bacpy(&bdaddr, &di.bdaddr); 234 | 235 | need_raw = !hci_test_bit(HCI_RAW, &di.flags); 236 | 237 | hci_filter_clear(&flt); 238 | hci_filter_set_ptype(HCI_ACLDATA_PKT, &flt); 239 | hci_filter_set_ptype(HCI_EVENT_PKT, &flt); 240 | hci_filter_set_event(EVT_VENDOR, &flt); 241 | 242 | if (setsockopt(dd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) { 243 | fprintf(stderr, "Can't set filter for hci%d: %s (%d)\n", 244 | dev, strerror(errno), errno); 245 | hci_close_dev(dd); 246 | exit(1); 247 | } 248 | 249 | memset(&sa, 0, sizeof(sa)); 250 | sa.sa_flags = SA_NOCLDSTOP; 251 | sa.sa_handler = SIG_IGN; 252 | sigaction(SIGCHLD, &sa, NULL); 253 | sigaction(SIGPIPE, &sa, NULL); 254 | 255 | sa.sa_handler = sig_term; 256 | sigaction(SIGTERM, &sa, NULL); 257 | sigaction(SIGINT, &sa, NULL); 258 | 259 | sa.sa_handler = sig_hup; 260 | sigaction(SIGHUP, &sa, NULL); 261 | 262 | if (need_raw) { 263 | if (ioctl(dd, HCISETRAW, 1) < 0) { 264 | fprintf(stderr, "Can't set raw mode on hci%d: %s (%d)\n", 265 | dev, strerror(errno), errno); 266 | hci_close_dev(dd); 267 | exit(1); 268 | } 269 | } 270 | 271 | printf("CSR sniffer - Bluetooth packet analyzer ver %s\n", VERSION); 272 | 273 | if (need_raw) { 274 | if (ioctl(dd, HCISETRAW, 0) < 0) 275 | fprintf(stderr, "Can't clear raw mode on hci%d: %s (%d)\n", 276 | dev, strerror(errno), errno); 277 | } 278 | 279 | hci_close_dev(dd); 280 | 281 | return 0; 282 | } 283 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | 7 | # location of the SDK. This is only used by Ant 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | sdk.dir=/home/azheng/projects/android/android-sdk-linux 11 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-15 15 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | hcidump 4 | 5 | --------------------------------------------------------------------------------