test-eir.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2011 Intel Corporation
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #include <stdbool.h>
  14. #include <glib.h>
  15. #include "lib/bluetooth.h"
  16. #include "lib/hci.h"
  17. #include "lib/sdp.h"
  18. #include "src/shared/tester.h"
  19. #include "src/shared/util.h"
  20. #include "src/eir.h"
  21. struct test_data {
  22. const void *eir_data;
  23. size_t eir_size;
  24. unsigned int flags;
  25. const char *name;
  26. bool name_complete;
  27. int8_t tx_power;
  28. const char **uuid;
  29. };
  30. static const unsigned char macbookair_data[] = {
  31. 0x17, 0x09, 0x4d, 0x61, 0x72, 0x63, 0x65, 0x6c,
  32. 0xe2, 0x80, 0x99, 0x73, 0x20, 0x4d, 0x61, 0x63,
  33. 0x42, 0x6f, 0x6f, 0x6b, 0x20, 0x41, 0x69, 0x72,
  34. 0x11, 0x03, 0x12, 0x11, 0x0c, 0x11, 0x0a, 0x11,
  35. 0x1f, 0x11, 0x01, 0x11, 0x00, 0x10, 0x0a, 0x11,
  36. 0x17, 0x11, 0x11, 0xff, 0x4c, 0x00, 0x01, 0x4d,
  37. 0x61, 0x63, 0x42, 0x6f, 0x6f, 0x6b, 0x41, 0x69,
  38. 0x72, 0x33, 0x2c, 0x31, 0x00, 0x00, 0x00, 0x00,
  39. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  49. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  51. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  52. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  53. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  60. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  61. };
  62. static const char *macbookair_uuid[] = {
  63. "00001112-0000-1000-8000-00805f9b34fb",
  64. "0000110c-0000-1000-8000-00805f9b34fb",
  65. "0000110a-0000-1000-8000-00805f9b34fb",
  66. "0000111f-0000-1000-8000-00805f9b34fb",
  67. "00001101-0000-1000-8000-00805f9b34fb",
  68. "00001000-0000-1000-8000-00805f9b34fb",
  69. "0000110a-0000-1000-8000-00805f9b34fb",
  70. "00001117-0000-1000-8000-00805f9b34fb",
  71. NULL
  72. };
  73. static const struct test_data macbookair_test = {
  74. .eir_data = macbookair_data,
  75. .eir_size = sizeof(macbookair_data),
  76. .name = "Marcel’s MacBook Air",
  77. .name_complete = true,
  78. .tx_power = 127,
  79. .uuid = macbookair_uuid,
  80. };
  81. static const unsigned char iphone5_data[] = {
  82. 0x14, 0x09, 0x4d, 0x61, 0x72, 0x63, 0x65, 0x6c,
  83. 0xe2, 0x80, 0x99, 0x73, 0x20, 0x69, 0x50, 0x68,
  84. 0x6f, 0x6e, 0x65, 0x20, 0x35, 0x0f, 0x03, 0x00,
  85. 0x12, 0x1f, 0x11, 0x2f, 0x11, 0x0a, 0x11, 0x0c,
  86. 0x11, 0x16, 0x11, 0x32, 0x11, 0x01, 0x05, 0x11,
  87. 0x07, 0xfe, 0xca, 0xca, 0xde, 0xaf, 0xde, 0xca,
  88. 0xde, 0xde, 0xfa, 0xca, 0xde, 0x00, 0x00, 0x00,
  89. 0x00, 0x27, 0xff, 0x00, 0x4c, 0x02, 0x24, 0x02,
  90. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  91. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  92. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  93. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  94. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  95. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  96. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  97. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  98. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  99. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  100. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  101. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  102. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  103. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  105. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  106. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  107. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  108. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  109. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  110. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  111. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  112. };
  113. static const char *iphone5_uuid[] = {
  114. "00001200-0000-1000-8000-00805f9b34fb",
  115. "0000111f-0000-1000-8000-00805f9b34fb",
  116. "0000112f-0000-1000-8000-00805f9b34fb",
  117. "0000110a-0000-1000-8000-00805f9b34fb",
  118. "0000110c-0000-1000-8000-00805f9b34fb",
  119. "00001116-0000-1000-8000-00805f9b34fb",
  120. "00001132-0000-1000-8000-00805f9b34fb",
  121. "00000000-deca-fade-deca-deafdecacafe",
  122. NULL
  123. };
  124. static const struct test_data iphone5_test = {
  125. .eir_data = iphone5_data,
  126. .eir_size = sizeof(iphone5_data),
  127. .name = "Marcel’s iPhone 5",
  128. .name_complete = true,
  129. .tx_power = 127,
  130. .uuid = iphone5_uuid,
  131. };
  132. static const unsigned char ipadmini_data[] = {
  133. 0x13, 0x09, 0x4d, 0x61, 0x72, 0x63, 0x65, 0x6c,
  134. 0x27, 0x73, 0x20, 0x69, 0x50, 0x61, 0x64, 0x20,
  135. 0x6d, 0x69, 0x6e, 0x69, 0x0b, 0x03, 0x00, 0x12,
  136. 0x1f, 0x11, 0x0a, 0x11, 0x0c, 0x11, 0x32, 0x11,
  137. 0x01, 0x05, 0x11, 0x07, 0xfe, 0xca, 0xca, 0xde,
  138. 0xaf, 0xde, 0xca, 0xde, 0xde, 0xfa, 0xca, 0xde,
  139. 0x00, 0x00, 0x00, 0x00, 0x27, 0xff, 0x00, 0x4c,
  140. 0x02, 0x24, 0x02, 0x0c, 0x00, 0x00, 0x00, 0x00,
  141. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  142. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  143. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  144. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  145. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  147. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  148. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  149. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  150. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  151. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  152. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  153. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  154. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  155. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  156. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  157. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  158. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  159. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  160. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  161. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  162. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  163. };
  164. static const char *ipadmini_uuid[] = {
  165. "00001200-0000-1000-8000-00805f9b34fb",
  166. "0000111f-0000-1000-8000-00805f9b34fb",
  167. "0000110a-0000-1000-8000-00805f9b34fb",
  168. "0000110c-0000-1000-8000-00805f9b34fb",
  169. "00001132-0000-1000-8000-00805f9b34fb",
  170. "00000000-deca-fade-deca-deafdecacafe",
  171. NULL
  172. };
  173. static const struct test_data ipadmini_test = {
  174. .eir_data = ipadmini_data,
  175. .eir_size = sizeof(ipadmini_data),
  176. .name = "Marcel's iPad mini",
  177. .name_complete = true,
  178. .tx_power = 127,
  179. .uuid = ipadmini_uuid,
  180. };
  181. static const unsigned char gigaset_sl400h_data[] = {
  182. 0x0b, 0x03, 0x01, 0x11, 0x05, 0x11, 0x12, 0x11,
  183. 0x03, 0x12, 0x1f, 0x11, 0x10, 0x09, 0x4d, 0x61,
  184. 0x72, 0x63, 0x65, 0x6c, 0x27, 0x73, 0x20, 0x53,
  185. 0x4c, 0x34, 0x30, 0x30, 0x48, 0x00, 0x00, 0x00,
  186. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  187. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  188. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  189. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  190. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  191. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  192. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  193. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  194. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  195. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  196. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  197. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  198. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  199. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  200. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  201. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  202. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  203. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  204. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  205. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  206. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  207. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  208. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  209. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  210. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  211. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  212. };
  213. static const char *gigaset_sl400h_uuid[] = {
  214. "00001101-0000-1000-8000-00805f9b34fb",
  215. "00001105-0000-1000-8000-00805f9b34fb",
  216. "00001112-0000-1000-8000-00805f9b34fb",
  217. "00001203-0000-1000-8000-00805f9b34fb",
  218. "0000111f-0000-1000-8000-00805f9b34fb",
  219. NULL
  220. };
  221. static const struct test_data gigaset_sl400h_test = {
  222. .eir_data = gigaset_sl400h_data,
  223. .eir_size = sizeof(gigaset_sl400h_data),
  224. .name = "Marcel's SL400H",
  225. .name_complete = true,
  226. .tx_power = 127,
  227. .uuid = gigaset_sl400h_uuid,
  228. };
  229. static const unsigned char gigaset_sl910_data[] = {
  230. 0x0b, 0x03, 0x01, 0x11, 0x05, 0x11, 0x12, 0x11,
  231. 0x03, 0x12, 0x1f, 0x11, 0x0f, 0x09, 0x4d, 0x61,
  232. 0x72, 0x63, 0x65, 0x6c, 0x27, 0x73, 0x20, 0x53,
  233. 0x4c, 0x39, 0x31, 0x30, 0x00, 0x00, 0x00, 0x00,
  234. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  235. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  236. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  237. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  238. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  239. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  240. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  241. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  242. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  243. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  244. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  245. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  246. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  247. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  248. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  249. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  250. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  251. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  252. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  253. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  254. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  255. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  256. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  257. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  258. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  259. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  260. };
  261. static const char *gigaset_sl910_uuid[] = {
  262. "00001101-0000-1000-8000-00805f9b34fb",
  263. "00001105-0000-1000-8000-00805f9b34fb",
  264. "00001112-0000-1000-8000-00805f9b34fb",
  265. "00001203-0000-1000-8000-00805f9b34fb",
  266. "0000111f-0000-1000-8000-00805f9b34fb",
  267. NULL
  268. };
  269. static const struct test_data gigaset_sl910_test = {
  270. .eir_data = gigaset_sl910_data,
  271. .eir_size = sizeof(gigaset_sl910_data),
  272. .name = "Marcel's SL910",
  273. .name_complete = true,
  274. .tx_power = 127,
  275. .uuid = gigaset_sl910_uuid,
  276. };
  277. static const unsigned char nokia_bh907_data[] = {
  278. 0x16, 0x09, 0x4e, 0x6f, 0x6b, 0x69, 0x61, 0x20,
  279. 0x52, 0x65, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e,
  280. 0x20, 0x42, 0x48, 0x2d, 0x39, 0x30, 0x37, 0x02,
  281. 0x0a, 0x04, 0x0f, 0x02, 0x0d, 0x11, 0x0b, 0x11,
  282. 0x0e, 0x11, 0x0f, 0x11, 0x1e, 0x11, 0x08, 0x11,
  283. 0x31, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  284. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  285. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  286. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  287. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  288. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  289. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  290. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  291. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  292. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  293. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  294. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  295. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  296. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  297. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  298. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  299. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  300. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  301. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  302. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  303. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  304. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  305. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  306. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  307. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  308. };
  309. static const char *nokia_bh907_uuid[] = {
  310. "0000110d-0000-1000-8000-00805f9b34fb",
  311. "0000110b-0000-1000-8000-00805f9b34fb",
  312. "0000110e-0000-1000-8000-00805f9b34fb",
  313. "0000110f-0000-1000-8000-00805f9b34fb",
  314. "0000111e-0000-1000-8000-00805f9b34fb",
  315. "00001108-0000-1000-8000-00805f9b34fb",
  316. "00001131-0000-1000-8000-00805f9b34fb",
  317. NULL
  318. };
  319. static const struct test_data nokia_bh907_test = {
  320. .eir_data = nokia_bh907_data,
  321. .eir_size = sizeof(nokia_bh907_data),
  322. .name = "Nokia Reaction BH-907",
  323. .name_complete = true,
  324. .tx_power = 4,
  325. .uuid = nokia_bh907_uuid,
  326. };
  327. static const unsigned char fuelband_data[] = {
  328. 0x0f, 0x09, 0x4e, 0x69, 0x6b, 0x65, 0x2b, 0x20,
  329. 0x46, 0x75, 0x65, 0x6c, 0x42, 0x61, 0x6e, 0x64,
  330. 0x11, 0x07, 0x00, 0x00, 0x00, 0x00, 0xde, 0xca,
  331. 0xfa, 0xde, 0xde, 0xca, 0xde, 0xaf, 0xde, 0xca,
  332. 0xca, 0xff, 0x02, 0x0a, 0x00, 0x00, 0x00, 0x00,
  333. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  334. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  335. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  336. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  337. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  338. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  339. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  340. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  341. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  342. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  343. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  344. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  345. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  346. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  347. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  348. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  349. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  350. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  351. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  352. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  353. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  354. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  355. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  356. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  357. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  358. };
  359. static const char *fuelband_uuid[] = {
  360. "ffcacade-afde-cade-defa-cade00000000",
  361. NULL
  362. };
  363. static const struct test_data fuelband_test = {
  364. .eir_data = fuelband_data,
  365. .eir_size = sizeof(fuelband_data),
  366. .name = "Nike+ FuelBand",
  367. .name_complete = true,
  368. .tx_power = 0,
  369. .uuid = fuelband_uuid,
  370. };
  371. static const unsigned char bluesc_data[] = {
  372. 0x02, 0x01, 0x06, 0x03, 0x02, 0x16, 0x18, 0x12,
  373. 0x09, 0x57, 0x61, 0x68, 0x6f, 0x6f, 0x20, 0x42,
  374. 0x6c, 0x75, 0x65, 0x53, 0x43, 0x20, 0x76, 0x31,
  375. 0x2e, 0x34,
  376. };
  377. static const char *bluesc_uuid[] = {
  378. "00001816-0000-1000-8000-00805f9b34fb",
  379. NULL
  380. };
  381. static const struct test_data bluesc_test = {
  382. .eir_data = bluesc_data,
  383. .eir_size = sizeof(bluesc_data),
  384. .flags = 0x06,
  385. .name = "Wahoo BlueSC v1.4",
  386. .name_complete = true,
  387. .tx_power = 127,
  388. .uuid = bluesc_uuid,
  389. };
  390. static const unsigned char wahoo_scale_data[] = {
  391. 0x02, 0x01, 0x06, 0x03, 0x02, 0x01, 0x19, 0x11,
  392. 0x09, 0x57, 0x61, 0x68, 0x6f, 0x6f, 0x20, 0x53,
  393. 0x63, 0x61, 0x6c, 0x65, 0x20, 0x76, 0x31, 0x2e,
  394. 0x33, 0x05, 0xff, 0x00, 0x00, 0x00, 0x9c,
  395. };
  396. static const char *wahoo_scale_uuid[] = {
  397. "00001901-0000-1000-8000-00805f9b34fb",
  398. NULL
  399. };
  400. static const struct test_data wahoo_scale_test = {
  401. .eir_data = wahoo_scale_data,
  402. .eir_size = sizeof(wahoo_scale_data),
  403. .flags = 0x06,
  404. .name = "Wahoo Scale v1.3",
  405. .name_complete = true,
  406. .tx_power = 127,
  407. .uuid = wahoo_scale_uuid,
  408. };
  409. static const unsigned char mio_alpha_data[] = {
  410. 0x02, 0x01, 0x06, 0x03, 0x02, 0x0d, 0x18, 0x06,
  411. 0x09, 0x41, 0x4c, 0x50, 0x48, 0x41,
  412. };
  413. static const char *mio_alpha_uuid[] = {
  414. "0000180d-0000-1000-8000-00805f9b34fb",
  415. NULL
  416. };
  417. static const struct test_data mio_alpha_test = {
  418. .eir_data = mio_alpha_data,
  419. .eir_size = sizeof(mio_alpha_data),
  420. .flags = 0x06,
  421. .name = "ALPHA",
  422. .name_complete = true,
  423. .tx_power = 127,
  424. .uuid = mio_alpha_uuid,
  425. };
  426. static const unsigned char cookoo_data[] = {
  427. 0x02, 0x01, 0x05, 0x05, 0x02, 0x02, 0x18, 0x0a,
  428. 0x18, 0x0d, 0x09, 0x43, 0x4f, 0x4f, 0x4b, 0x4f,
  429. 0x4f, 0x20, 0x77, 0x61, 0x74, 0x63, 0x68,
  430. };
  431. static const char *cookoo_uuid[] = {
  432. "00001802-0000-1000-8000-00805f9b34fb",
  433. "0000180a-0000-1000-8000-00805f9b34fb",
  434. NULL
  435. };
  436. static const struct test_data cookoo_test = {
  437. .eir_data = cookoo_data,
  438. .eir_size = sizeof(cookoo_data),
  439. .flags = 0x05,
  440. .name = "COOKOO watch",
  441. .name_complete = true,
  442. .tx_power = 127,
  443. .uuid = cookoo_uuid,
  444. };
  445. static const unsigned char citizen_adv_data[] = {
  446. 0x02, 0x01, 0x05, 0x05, 0x12, 0x7f, 0x01, 0x8f,
  447. 0x01, 0x14, 0x09, 0x45, 0x63, 0x6f, 0x2d, 0x44,
  448. 0x72, 0x69, 0x76, 0x65, 0x20, 0x50, 0x72, 0x6f,
  449. 0x78, 0x69, 0x6d, 0x69, 0x74, 0x79,
  450. };
  451. static const struct test_data citizen_adv_test = {
  452. .eir_data = citizen_adv_data,
  453. .eir_size = sizeof(citizen_adv_data),
  454. .flags = 0x05,
  455. .name = "Eco-Drive Proximity",
  456. .name_complete = true,
  457. .tx_power = 127,
  458. };
  459. static const unsigned char citizen_scan_data[] = {
  460. 0x02, 0x0a, 0x00, 0x11, 0x07, 0x1b, 0xc5, 0xd5,
  461. 0xa5, 0x02, 0x00, 0x46, 0x9a, 0xe1, 0x11, 0xb7,
  462. 0x8d, 0x60, 0xb4, 0x45, 0x2d,
  463. };
  464. static const char *citizen_scan_uuid[] = {
  465. "2d45b460-8db7-11e1-9a46-0002a5d5c51b",
  466. NULL
  467. };
  468. static const struct test_data citizen_scan_test = {
  469. .eir_data = citizen_scan_data,
  470. .eir_size = sizeof(citizen_scan_data),
  471. .tx_power = 0,
  472. .uuid = citizen_scan_uuid,
  473. };
  474. static void test_basic(const void *data)
  475. {
  476. struct eir_data eir;
  477. unsigned char buf[HCI_MAX_EIR_LENGTH];
  478. memset(buf, 0, sizeof(buf));
  479. memset(&eir, 0, sizeof(eir));
  480. eir_parse(&eir, buf, HCI_MAX_EIR_LENGTH);
  481. g_assert(eir.services == NULL);
  482. g_assert(eir.name == NULL);
  483. eir_data_free(&eir);
  484. tester_test_passed();
  485. }
  486. static void print_debug(const char *str, void *user_data)
  487. {
  488. char *prefix = user_data;
  489. tester_debug("%s%s", prefix, str);
  490. }
  491. static void test_parsing(gconstpointer data)
  492. {
  493. const struct test_data *test = data;
  494. struct eir_data eir;
  495. GSList *list;
  496. memset(&eir, 0, sizeof(eir));
  497. eir_parse(&eir, test->eir_data, test->eir_size);
  498. tester_debug("Flags: %d", eir.flags);
  499. tester_debug("Name: %s", eir.name);
  500. tester_debug("TX power: %d", eir.tx_power);
  501. for (list = eir.services; list; list = list->next) {
  502. char *uuid_str = list->data;
  503. tester_debug("UUID: %s", uuid_str);
  504. }
  505. g_assert_cmpint(eir.flags, ==, test->flags);
  506. if (test->name) {
  507. g_assert_cmpstr(eir.name, ==, test->name);
  508. g_assert(eir.name_complete == test->name_complete);
  509. } else {
  510. g_assert(eir.name == NULL);
  511. }
  512. g_assert(eir.tx_power == test->tx_power);
  513. if (test->uuid) {
  514. GSList *list;
  515. int n = 0;
  516. for (list = eir.services; list; list = list->next, n++) {
  517. char *uuid_str = list->data;
  518. g_assert(test->uuid[n]);
  519. g_assert_cmpstr(test->uuid[n], ==, uuid_str);
  520. }
  521. } else {
  522. g_assert(eir.services == NULL);
  523. }
  524. for (list = eir.msd_list; list; list = list->next) {
  525. struct eir_msd *msd = list->data;
  526. tester_debug("Manufacturer ID: 0x%04x", msd->company);
  527. util_hexdump(' ', msd->data, msd->data_len, print_debug,
  528. "Manufacturer Data:");
  529. }
  530. for (list = eir.sd_list; list; list = list->next) {
  531. struct eir_sd *sd = list->data;
  532. tester_debug("Service UUID: %s", sd->uuid);
  533. util_hexdump(' ', sd->data, sd->data_len, print_debug,
  534. "Service Data:");
  535. }
  536. eir_data_free(&eir);
  537. tester_test_passed();
  538. }
  539. static const unsigned char gigaset_gtag_data[] = {
  540. 0x02, 0x01, 0x06, 0x0d, 0xff, 0x80, 0x01, 0x02,
  541. 0x15, 0x12, 0x34, 0x80, 0x91, 0xd0, 0xf2, 0xbb,
  542. 0xc5, 0x03, 0x02, 0x0f, 0x18, 0x00, 0x00, 0x00,
  543. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  544. };
  545. static const char *gigaset_gtag_uuid[] = {
  546. "0000180f-0000-1000-8000-00805f9b34fb",
  547. NULL
  548. };
  549. static const struct test_data gigaset_gtag_test = {
  550. .eir_data = gigaset_gtag_data,
  551. .eir_size = sizeof(gigaset_gtag_data),
  552. .flags = 0x06,
  553. .tx_power = 127,
  554. .uuid = gigaset_gtag_uuid,
  555. };
  556. static const char *uri_beacon_uuid[] = {
  557. "0000fed8-0000-1000-8000-00805f9b34fb",
  558. NULL
  559. };
  560. static const unsigned char uri_beacon_data[] = {
  561. 0x03, 0x03, 0xd8, 0xfe, 0x0c, 0x16, 0xd8, 0xfe, 0x00,
  562. 0x20, 0x00, 'b', 'l', 'u', 'e', 'z', 0x08
  563. };
  564. static const struct test_data uri_beacon_test = {
  565. .eir_data = uri_beacon_data,
  566. .eir_size = sizeof(uri_beacon_data),
  567. .tx_power = 127,
  568. .uuid = uri_beacon_uuid,
  569. };
  570. int main(int argc, char *argv[])
  571. {
  572. tester_init(&argc, &argv);
  573. tester_add("/eir/basic", NULL, NULL, test_basic, NULL);
  574. tester_add("/eir/macbookair", &macbookair_test, NULL, test_parsing,
  575. NULL);
  576. tester_add("/eir/iphone5", &iphone5_test, NULL, test_parsing, NULL);
  577. tester_add("/eir/ipadmini", &ipadmini_test, NULL, test_parsing, NULL);
  578. tester_add("/eir/sl400h", &gigaset_sl400h_test, NULL, test_parsing,
  579. NULL);
  580. tester_add("/eir/sl910", &gigaset_sl910_test, NULL, test_parsing, NULL);
  581. tester_add("/eir/bh907", &nokia_bh907_test, NULL, test_parsing, NULL);
  582. tester_add("/eir/fuelband", &fuelband_test, NULL, test_parsing, NULL);
  583. tester_add("/ad/bluesc", &bluesc_test, NULL, test_parsing, NULL);
  584. tester_add("/ad/wahooscale", &wahoo_scale_test, NULL, test_parsing,
  585. NULL);
  586. tester_add("/ad/mioalpha", &mio_alpha_test, NULL, test_parsing, NULL);
  587. tester_add("/ad/cookoo", &cookoo_test, NULL, test_parsing, NULL);
  588. tester_add("/ad/citizen1", &citizen_adv_test, NULL, test_parsing, NULL);
  589. tester_add("/ad/citizen2", &citizen_scan_test, NULL, test_parsing,
  590. NULL);
  591. tester_add("ad/g-tag", &gigaset_gtag_test, NULL, test_parsing, NULL);
  592. tester_add("ad/uri-beacon", &uri_beacon_test, NULL, test_parsing, NULL);
  593. return tester_run();
  594. }