appl_prov.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  1. /**
  2. * \file appl_prov.c
  3. *
  4. *
  5. */
  6. /*
  7. * Copyright (C) 2013. Mindtree Limited.
  8. * All rights reserved.
  9. */
  10. /* --------------------------------------------- Header File Inclusion */
  11. #include "MS_prov_api.h"
  12. #include "prov_pl.h"
  13. #include "appl_main.h"
  14. #include "blebrr.h"
  15. #include "cry.h"
  16. static inline uint32 clock_time_rtc(void){
  17. return (*(volatile unsigned int *)0x4000f028) & 0xffffff;
  18. }
  19. /**
  20. * Compilation switch to use selected Capabilities and Keys for ease of
  21. * PTS testing.
  22. * This Flag needs to be disabled by default to explore full range of
  23. * provisioning capabilities and have specific peer provided OOB Pbulic keys etc.
  24. */
  25. /* #define MESH_PTS_TEST */
  26. /* --------------------------------------------- Global Definitions */
  27. /** Size of beacon list to be maintained by Provisioner */
  28. #define APPL_UNPROV_BEACON_LIST_SIZE 8
  29. /** Beacon setup timeout in seconds */
  30. #define APPL_PROV_SETUP_TIMEOUT_SECS 30
  31. /** Attention timeout for device in seconds */
  32. #define APPL_PROV_DEVICE_ATTENTION_TIMEOUT 30
  33. /** Output OOB Actions supported */
  34. #ifndef MESH_PTS_TEST
  35. #define APPL_PROV_OUTPUT_OOB_ACTIONS \
  36. (PROV_MASK_OOOB_ACTION_BLINK | PROV_MASK_OOOB_ACTION_BEEP | \
  37. PROV_MASK_OOOB_ACTION_VIBRATE | PROV_MASK_OOOB_ACTION_NUMERIC | \
  38. PROV_MASK_OOOB_ACTION_ALPHANUMERIC)
  39. /** Output OOB Maximum size supported */
  40. #define APPL_PROV_OUTPUT_OOB_SIZE 0x08
  41. /** Input OOB Actions supported */
  42. #define APPL_PROV_INPUT_OOB_ACTIONS \
  43. (PROV_MASK_IOOB_ACTION_PUSH | PROV_MASK_IOOB_ACTION_TWIST | \
  44. PROV_MASK_IOOB_ACTION_NUMERIC | PROV_MASK_IOOB_ACTION_ALPHANUMERIC)
  45. /** Input OOB Maximum size supported */
  46. #define APPL_PROV_INPUT_OOB_SIZE 0x08
  47. #else /* MESH_PTS_TEST */
  48. #define APPL_PROV_OUTPUT_OOB_ACTIONS \
  49. PROV_MASK_OOOB_ACTION_NUMERIC
  50. /** Output OOB Maximum size supported */
  51. #define APPL_PROV_OUTPUT_OOB_SIZE 0x04
  52. /** Input OOB Actions supported */
  53. #define APPL_PROV_INPUT_OOB_ACTIONS \
  54. PROV_MASK_IOOB_ACTION_NUMERIC
  55. /** Input OOB Maximum size supported */
  56. #define APPL_PROV_INPUT_OOB_SIZE 0x04
  57. #endif /* MESH_PTS_TEST */
  58. /** Authentication values for OOB Display - To be made random */
  59. #define APPL_DISPLAY_AUTH_DIGIT 3
  60. #define APPL_DISPLAY_AUTH_NUMERIC 35007
  61. #define APPL_DISPLAY_AUTH_STRING "f00l"
  62. /** Base address as a provisioner */
  63. #define APPL_UADDR_BASE 0x0001
  64. #define APPL_DEVICE_PRIMARY_ELEMENT_UCAST_ADDR 0x0100
  65. /* --------------------------------------------- External Global Variables */
  66. /* --------------------------------------------- Exported Global Variables */
  67. void appl_prov_setup_provisioner(void);
  68. void appl_prov_start_provisioning(void);
  69. void appl_prov_register(void);
  70. void appl_prov_input_auth_val (UCHAR mode, void * data, UINT16 datalen);
  71. void appl_prov_set_dev_public_key(void);
  72. void appl_prov_get_local_public_key(void);
  73. void appl_prov_set_debug_keys(void);
  74. void appl_prov_set_auth_action
  75. (
  76. UCHAR mode,
  77. UCHAR * s_oob_val,
  78. UCHAR oob_act,
  79. UCHAR oob_sz
  80. );
  81. void main_prov_operations (void);
  82. void appl_prov_setup_device(void);
  83. API_RESULT appl_prov_callback
  84. (
  85. PROV_HANDLE * phandle,
  86. UCHAR event_type,
  87. API_RESULT event_result,
  88. void * event_data,
  89. UINT16 event_datalen
  90. );
  91. /* --------------------------------------------- Static Global Variables */
  92. /** Registration state of provisioning */
  93. DECL_STATIC UCHAR appl_prov_ready;
  94. /** Current role of application - Provisioner/Device */
  95. DECL_STATIC UCHAR appl_prov_role;
  96. DECL_STATIC UCHAR appl_prov_device_num_elements;
  97. /** Provisioning capabilities of local device */
  98. #ifdef MESH_PTS_TEST
  99. DECL_STATIC PROV_CAPABILITIES_S appl_prov_capab =
  100. {
  101. /** Number of Elements */
  102. 0x01,
  103. /** Supported algorithms */
  104. PROV_MASK_ALGO_EC_FIPS_P256,
  105. /** Public key type */
  106. PROV_MASK_PUBKEY_OOBINFO,
  107. /** Static OOB type */
  108. PROV_MASK_STATIC_OOBINFO,
  109. /** Output OOB information */
  110. { APPL_PROV_OUTPUT_OOB_ACTIONS, APPL_PROV_OUTPUT_OOB_SIZE },
  111. /** Input OOB information */
  112. { APPL_PROV_INPUT_OOB_ACTIONS, APPL_PROV_INPUT_OOB_SIZE },
  113. };
  114. #else /* MESH_PTS_TEST */
  115. /**
  116. * Choose this if application needs to use bare minimum capabilities
  117. * to get provisioned against popular mobile phone Mesh Applications.
  118. */
  119. DECL_STATIC PROV_CAPABILITIES_S appl_prov_capab =
  120. {
  121. /** Number of Elements */
  122. 0x01,
  123. /** Supported algorithms */
  124. PROV_MASK_ALGO_EC_FIPS_P256,
  125. /** Public key type */
  126. 0x00,
  127. /** Static OOB type */
  128. 0x00,
  129. /** Output OOB information */
  130. { 0x00, 0x00 },
  131. /** Input OOB information */
  132. { 0x00, 0x00 },
  133. };
  134. #endif /* MESH_PTS_TEST */
  135. /** Default Provisioning method to start */
  136. DECL_STATIC PROV_METHOD_S appl_prov_method =
  137. {
  138. /** Algorithm */
  139. PROV_ALGO_EC_FIPS_P256,
  140. /** Public Key */
  141. PROV_PUBKEY_NO_OOB,
  142. /** Authentication Method */
  143. PROV_AUTH_OOB_NONE,
  144. /** OOB Information */
  145. {0x0000, 0x00}
  146. };
  147. /** Unprovisioned device identifier */
  148. DECL_STATIC PROV_DEVICE_S appl_lprov_device =
  149. {
  150. /** UUID */
  151. /* {0x45, 0x74, 0x68, 0x65, 0x72, 0x4d, 0x69, 0x6e, 0x64, 0x4d, 0x65, 0x73, 0x68, 0x44, 0x65, 0x76}, */
  152. /* {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, */
  153. {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF},
  154. /** OOB Flag */
  155. 0x00,
  156. /**
  157. * Encoded URI Information
  158. * For example, to give a web address, "https://www.abc.com"
  159. * the URI encoded data would be -
  160. * 0x17 0x2F 0x2F 0x77 0x77 0x77 0x2E 0x61 0x62 0x63 0x2E 0x63 0x6F 0x6D
  161. * where 0x17 is the URI encoding for https:
  162. */
  163. NULL
  164. };
  165. /** Data exchanged during Provisiong procedure */
  166. DECL_STATIC PROV_DATA_S appl_prov_data =
  167. {
  168. /** NetKey */
  169. {0x45, 0x74, 0x68, 0x65, 0x72, 0x4d, 0x69, 0x6e, 0x64, 0x4e, 0x65, 0x74, 0x4b, 0x65, 0x79, 0x00},
  170. /** Index of the NetKey */
  171. 0x0000,
  172. /** Flags bitmask */
  173. 0x00,
  174. /** Current value of the IV index */
  175. 0x00000001,
  176. /** Unicast address of the primary element */
  177. APPL_DEVICE_PRIMARY_ELEMENT_UCAST_ADDR
  178. };
  179. /** Unprovisioned device beacons list */
  180. DECL_STATIC PROV_DEVICE_S appl_rprov_device[APPL_UNPROV_BEACON_LIST_SIZE];
  181. /** Unprovisioned device beacons count */
  182. DECL_STATIC CHAR appl_num_devices;
  183. /** Provisioning Handle */
  184. DECL_STATIC PROV_HANDLE appl_prov_handle;
  185. DECL_STATIC const char main_prov_options[] = "\n\
  186. ========= Provisioning Menu =============== \n\
  187. 0. Exit. \n\
  188. 1. Refresh \n\
  189. \n\
  190. 10. Register Provisioning. \n\
  191. \n\
  192. 11. Setup Provisioner. \n\
  193. 12. Setup Device. \n\
  194. \n\
  195. 15. Bind Device. \n\
  196. 16. Enter OOB Authval. \n\
  197. \n\
  198. 30. Set OOB Public Key for Device. \n\
  199. 31. Set OOB Authentication. \n\
  200. 32. Get Current Public Key. \n\
  201. 33. Set ECDH Debug Key Pairs. \n\
  202. \n\
  203. 40. Abort Procedure. \n\
  204. \n\
  205. 100. Provide Provisioning Data to Network and Transport Layer (for testing)\n\
  206. \n\
  207. Your Option ? \0";
  208. /* --------------------------------------------- Functions */
  209. void appl_prov_set_uuid (UCHAR * uuid)
  210. {
  211. EM_mem_copy (appl_lprov_device.uuid, uuid, MS_DEVICE_UUID_SIZE);
  212. }
  213. void appl_prov_update_uuid(UCHAR octet)
  214. {
  215. appl_lprov_device.uuid[0] = octet;
  216. }
  217. void appl_prov_bind_device(UCHAR brr)
  218. {
  219. API_RESULT retval;
  220. PROV_DEVICE_S * appl_tmp_dev_to_bind;
  221. if (PROV_ROLE_PROVISIONER == appl_prov_role)
  222. {
  223. appl_tmp_dev_to_bind = &appl_rprov_device[0x00];
  224. }
  225. else
  226. {
  227. appl_tmp_dev_to_bind = &appl_lprov_device;
  228. }
  229. printf("Binding device for provisioning...\n");
  230. retval = MS_prov_bind
  231. (
  232. PROV_BRR_GATT,
  233. appl_tmp_dev_to_bind,
  234. APPL_PROV_DEVICE_ATTENTION_TIMEOUT,
  235. &appl_prov_handle
  236. );
  237. printf("Retval - 0x%04X\n", retval);
  238. }
  239. API_RESULT appl_prov_callback
  240. (
  241. PROV_HANDLE * phandle,
  242. UCHAR event_type,
  243. API_RESULT event_result,
  244. void * event_data,
  245. UINT16 event_datalen
  246. )
  247. {
  248. PROV_DEVICE_S * rdev;
  249. PROV_CAPABILITIES_S * rcap;
  250. PROV_DATA_S * rdata;
  251. PROV_OOB_TYPE_S * oob_info;
  252. API_RESULT retval;
  253. UCHAR i;
  254. UCHAR authstr[PROV_AUTHVAL_SIZE_PL << 1];
  255. UINT32 authnum;
  256. UCHAR authtype;
  257. UCHAR * pauth;
  258. UINT16 authsize;
  259. UCHAR pdata[(MS_DEVICE_UUID_SIZE * 2) + 1];
  260. UCHAR * t_data;
  261. static UCHAR prov_flag;
  262. static UINT16 prov_keyid;
  263. /* printf("\n"); */
  264. switch (event_type)
  265. {
  266. case PROV_EVT_UNPROVISIONED_BEACON:
  267. if (APPL_UNPROV_BEACON_LIST_SIZE == appl_num_devices)
  268. {
  269. /* printf ("Device List Full. Dropping Beacon...\n"); */
  270. break;
  271. }
  272. /* Reference the beacon pointer */
  273. rdev = (PROV_DEVICE_S *)event_data;
  274. retval = API_SUCCESS;
  275. for (i = 0; i < APPL_UNPROV_BEACON_LIST_SIZE; i++)
  276. {
  277. if (0 == EM_mem_cmp(rdev->uuid, appl_rprov_device[i].uuid, 16))
  278. {
  279. /* Mark for filtering */
  280. retval = API_FAILURE;
  281. /**
  282. * Break when there is an exisiting instance for incoming
  283. * UUID of the unprovisioned device.
  284. */
  285. break;
  286. }
  287. }
  288. if (API_SUCCESS != retval)
  289. {
  290. retval = API_SUCCESS;
  291. break;
  292. }
  293. printf ("Recvd PROV_EVT_UNPROVISIONED_BEACON\n");
  294. printf ("Status - 0x%04X\n", event_result);
  295. printf("\nID: %d", appl_num_devices);
  296. printf("\nUUID : [");
  297. #if 0
  298. for (i = 0; i < MS_DEVICE_UUID_SIZE; i++)
  299. {
  300. printf("%02X", rdev->uuid[i]);
  301. }
  302. #else /* 0 */
  303. EM_mem_set(pdata, 0x0, sizeof(pdata));
  304. t_data = pdata;
  305. for (i = 0; i < (MS_DEVICE_UUID_SIZE); i++)
  306. {
  307. sprintf((char *)t_data,"%02X", rdev->uuid[i]);
  308. t_data += 2;
  309. }
  310. printf(" %s ", pdata);
  311. #endif /* 0 */
  312. printf("]");
  313. printf("\nOOB : 0x%04X", rdev->oob);
  314. printf("\nURI : 0x%08X", rdev->uri);
  315. printf("\n\n");
  316. /* Copy the beacon to the list */
  317. EM_mem_copy (&appl_rprov_device[appl_num_devices], rdev, sizeof (PROV_DEVICE_S));
  318. appl_num_devices++;
  319. break;
  320. case PROV_EVT_PROVISIONING_SETUP:
  321. printf ("Recvd PROV_EVT_PROVISIONING_SETUP\n");
  322. printf ("Status - 0x%04X\n", event_result);
  323. /* Decipher the data based on the role */
  324. if (PROV_ROLE_PROVISIONER == appl_prov_role)
  325. {
  326. /* Display the capabilities */
  327. rcap = (PROV_CAPABILITIES_S *)event_data;
  328. printf ("Remote Device Capabilities:\n");
  329. printf ("\tNum Elements - %d\n", rcap->num_elements);
  330. printf ("\tSupp Algorithms - 0x%04X\n", rcap->supp_algorithms);
  331. printf ("\tSupp PublicKey - 0x%02X\n", rcap->supp_pubkey);
  332. printf ("\tSupp Static OOB - 0x%02X\n", rcap->supp_soob);
  333. printf ("\tOutput OOB Size - %d\n", rcap->ooob.size);
  334. printf ("\tOutput OOB Action- 0x%04X\n", rcap->ooob.action);
  335. printf ("\tInput OOB Size - %d\n", rcap->ioob.size);
  336. printf ("\tInput OOB Action - 0x%04X\n", rcap->ioob.action);
  337. /* Store the current number of elements */
  338. appl_prov_device_num_elements = rcap->num_elements;
  339. /* Start with default method */
  340. printf ("Start Provisioning with default method...\n");
  341. retval = MS_prov_start (phandle, &appl_prov_method);
  342. printf ("Retval - 0x%04X\n", retval);
  343. }
  344. else
  345. {
  346. /* Display the attention timeout */
  347. printf ("Attention Timeout - %d\n", *((UCHAR *)event_data));
  348. }
  349. break;
  350. case PROV_EVT_OOB_DISPLAY:
  351. printf ("Recvd PROV_EVT_OOB_DISPLAY\n");
  352. printf ("Status - 0x%04X\n", event_result);
  353. /* Reference the Authenticatio Type information */
  354. oob_info = (PROV_OOB_TYPE_S *)event_data;
  355. printf("Authenticaion Action - 0x%02X\n", oob_info->action);
  356. printf("Authenticaion Size - 0x%02X\n", oob_info->size);
  357. /* If role is Device, the action is of Output OOB, else Input OOB */
  358. if (PROV_ROLE_DEVICE == appl_prov_role)
  359. {
  360. if (PROV_OOOB_ACTION_ALPHANUMERIC == oob_info->action)
  361. {
  362. authtype = 1;
  363. }
  364. else if (PROV_OOOB_ACTION_NUMERIC == oob_info->action)
  365. {
  366. authtype = 2;
  367. }
  368. else
  369. {
  370. authtype = 0;
  371. }
  372. }
  373. else
  374. {
  375. if (PROV_IOOB_ACTION_ALPHANUMERIC == oob_info->action)
  376. {
  377. authtype = 1;
  378. }
  379. else if (PROV_IOOB_ACTION_NUMERIC == oob_info->action)
  380. {
  381. authtype = 2;
  382. }
  383. else
  384. {
  385. authtype = 0;
  386. }
  387. }
  388. if (1 == authtype)
  389. {
  390. EM_str_copy (authstr, APPL_DISPLAY_AUTH_STRING);
  391. printf("\n\n>>> AuthVal - %s <<<\n\n", authstr);
  392. pauth = authstr;
  393. authsize = EM_str_len(authstr);
  394. }
  395. else if (2 == authtype)
  396. {
  397. authnum = (UINT32)APPL_DISPLAY_AUTH_NUMERIC;
  398. printf("\n\n>>> AuthVal - %d <<<\n\n", authnum);
  399. pauth = (UCHAR *)&authnum;
  400. authsize = sizeof(UINT32);
  401. }
  402. else
  403. {
  404. authnum = (UINT32)APPL_DISPLAY_AUTH_DIGIT;
  405. printf("\n\n>>> AuthVal - %d <<<\n\n", authnum);
  406. pauth = (UCHAR *)&authnum;
  407. authsize = sizeof(UINT32);
  408. }
  409. /* Call to input the oob */
  410. printf("Setting the Authval...\n");
  411. retval = MS_prov_set_authval(&appl_prov_handle, pauth, authsize);
  412. printf("Retval - 0x%04X\n", retval);
  413. break;
  414. case PROV_EVT_OOB_ENTRY:
  415. printf ("Recvd PROV_EVT_OOB_ENTRY\n");
  416. printf ("Status - 0x%04X\n", event_result);
  417. /* Reference the Authenticatio Type information */
  418. oob_info = (PROV_OOB_TYPE_S *)event_data;
  419. printf("Authenticaion Action - 0x%02X\n", oob_info->action);
  420. printf("Authenticaion Size - 0x%02X\n", oob_info->size);
  421. break;
  422. case PROV_EVT_DEVINPUT_COMPLETE:
  423. printf ("Recvd PROV_EVT_DEVINPUT_COMPLETE\n");
  424. printf ("Status - 0x%04X\n", event_result);
  425. break;
  426. case PROV_EVT_PROVDATA_INFO_REQ:
  427. printf ("Recvd PROV_EVT_PROVDATA_INFO_REQ\n");
  428. printf ("Status - 0x%04X\n", event_result);
  429. /* Send Provisioning Data */
  430. printf ("Send Provisioning Data...\n");
  431. retval = MS_prov_data (phandle, &appl_prov_data);
  432. printf ("Retval - 0x%04X\n", retval);
  433. printf ("NetKey : "); appl_dump_bytes(appl_prov_data.netkey, PROV_KEY_NETKEY_SIZE);
  434. printf ("Key ID : 0x%04X\n", appl_prov_data.keyid);
  435. printf ("Flags : 0x%02X\n", appl_prov_data.flags);
  436. printf ("IVIndex : 0x%08X\n", appl_prov_data.ivindex);
  437. printf ("UAddr : 0x%04X\n", appl_prov_data.uaddr);
  438. break;
  439. case PROV_EVT_PROVDATA_INFO:
  440. printf ("Recvd PROV_EVT_PROVDATA_INFO\n");
  441. printf ("Status - 0x%04X\n", event_result);
  442. /* Reference the Provisioning Data */
  443. rdata = (PROV_DATA_S *)event_data;
  444. printf ("NetKey : "); appl_dump_bytes(rdata->netkey, PROV_KEY_NETKEY_SIZE);
  445. printf ("Key ID : 0x%04X\n", rdata->keyid);
  446. printf ("Flags : 0x%02X\n", rdata->flags);
  447. printf ("IVIndex : 0x%08X\n", rdata->ivindex);
  448. printf ("UAddr : 0x%04X\n", rdata->uaddr);
  449. // ========HZF
  450. UINT32 T1, T2;
  451. blebrr_scan_pl(FALSE);
  452. T1 = clock_time_rtc();//read_current_fine_time();
  453. /* Provide Provisioning Data to Access Layer */
  454. MS_access_cm_set_prov_data
  455. (
  456. rdata
  457. );
  458. T2 = clock_time_rtc();
  459. printf("consume time of function MS_access_cm_set_prov_data-1: %d RTC tick\r\n", (T2 - T1));
  460. /* Cache the Flags and Key Index to the Globals */
  461. prov_flag = rdata->flags;
  462. prov_keyid = rdata->keyid;
  463. break;
  464. case PROV_EVT_PROVISIONING_COMPLETE:
  465. printf ("Recvd PROV_EVT_PROVISIONING_COMPLETE\n");
  466. printf ("Status - 0x%04X\n", event_result);
  467. printf ("appl_prov_role - 0x%02X\n", appl_prov_role);
  468. if (API_SUCCESS == event_result)
  469. {
  470. if (PROV_ROLE_PROVISIONER == appl_prov_role)
  471. {
  472. if (APPL_DEVICE_PRIMARY_ELEMENT_UCAST_ADDR == appl_prov_data.uaddr)
  473. {
  474. /* Holding a temporary structure for local prov data */
  475. PROV_DATA_S temp_ps_prov_data;
  476. EM_mem_copy
  477. (
  478. &temp_ps_prov_data,
  479. &appl_prov_data,
  480. sizeof(appl_prov_data)
  481. );
  482. /**
  483. * Assigning the Local Unicast Address of the Provisioner
  484. * to the Access Layer along with other related keys.
  485. */
  486. temp_ps_prov_data.uaddr = 0x0001;
  487. // ========HZF
  488. UINT32 T1, T2;
  489. blebrr_scan_pl(FALSE);
  490. T1 = clock_time_rtc();//read_current_fine_time();
  491. /* Provide Provisioning Data to Access Layer */
  492. MS_access_cm_set_prov_data
  493. (
  494. &temp_ps_prov_data
  495. );
  496. T2 = clock_time_rtc();
  497. printf("consume time of function MS_access_cm_set_prov_data-2: %d RTC tick\r\n", (T2 - T1));
  498. /**
  499. * TODO:
  500. * Increment the appl_prov_data.uaddr for the next
  501. * set of device which is getting provisioned based on
  502. * the address and number of elements present in the last
  503. * provisioned device.
  504. */
  505. }
  506. appl_prov_data.uaddr += appl_prov_device_num_elements;
  507. }
  508. else
  509. {
  510. /* Already Set while handling PROV_EVT_PROVDATA_INFO */
  511. /**
  512. * TODO/NOTE:
  513. * The sending of Secure Network Beacon from Provisioning
  514. * Complete might not be feasible over GATT Bearer.
  515. * This is because the Provisioner might disconnect the
  516. * link once Provisioning is completed!
  517. * To then send an "SNB", one can use the CLI commands or
  518. * make use of the Callback event "BLEBRR_GATT_IFACE_DOWN"
  519. * received through * the callback registered using the API
  520. * \ref blebrr_register_gatt_iface_event_pl(...)
  521. */
  522. if (0x00 != prov_flag)
  523. {
  524. MS_SUBNET_HANDLE subnet;
  525. /* Get associated Subnet Handle */
  526. retval = MS_access_cm_find_subnet
  527. (
  528. prov_keyid,
  529. &subnet
  530. );
  531. if (API_SUCCESS == retval)
  532. {
  533. /* Send the Secure Network Beacon */
  534. MS_net_broadcast_secure_beacon(subnet);
  535. }
  536. }
  537. }
  538. }
  539. #ifdef MESH_PTS_TEST
  540. /**
  541. * This piece is added for Unprovisioned beacon Auto Start.
  542. * This was needed for few invalid behaviour PTS testcases.
  543. */
  544. if (API_SUCCESS != event_result)
  545. {
  546. if (PROV_ROLE_DEVICE == appl_prov_role)
  547. {
  548. printf ("Setting up Device...\n");
  549. retval = MS_prov_setup
  550. (
  551. PROV_BRR_ADV,
  552. PROV_ROLE_DEVICE,
  553. &appl_lprov_device,
  554. APPL_PROV_SETUP_TIMEOUT_SECS,
  555. APPL_PROV_SETUP_TIMEOUT_SECS
  556. );
  557. printf ("Retval - 0x%04X\n", retval);
  558. appl_prov_role = PROV_ROLE_DEVICE;
  559. retval = MS_prov_bind(PROV_BRR_ADV, &appl_rprov_device[0x00], APPL_PROV_DEVICE_ATTENTION_TIMEOUT, &appl_prov_handle);
  560. printf("Retval - 0x%04X\n", retval);
  561. }
  562. }
  563. #endif /* MESH_PTS_TEST */
  564. break;
  565. default:
  566. printf ("Unknown Event - 0x%02X\n", event_type);
  567. }
  568. return API_SUCCESS;
  569. }
  570. void main_prov_operations (void)
  571. {
  572. UCHAR pubkey[PROV_PUBKEY_SIZE_PL];
  573. UCHAR auth[PROV_AUTHVAL_SIZE_PL];
  574. API_RESULT retval;
  575. int choice;
  576. UCHAR brr, i;
  577. UCHAR authstr[PROV_AUTHVAL_SIZE_PL << 1];
  578. UINT32 authnum;
  579. UCHAR * pauth;
  580. UINT16 authsize;
  581. while (1)
  582. {
  583. printf("%s", main_prov_options);
  584. scanf("%d", &choice);
  585. if (choice < 0)
  586. {
  587. printf("*** Invalid Choice. Try Again.\n");
  588. continue;
  589. }
  590. switch (choice)
  591. {
  592. case 0:
  593. return;
  594. case 1:
  595. break;
  596. case 10:
  597. appl_prov_register();
  598. break;
  599. case 11:
  600. appl_prov_setup_provisioner();
  601. break;
  602. case 12:
  603. printf ("Select the Bearer (0: PB-ADV, 1: PB-GATT): "); fflush (stdout);
  604. scanf ("%d", &choice);
  605. /* Set the Bearer */
  606. brr = (0 != choice)? PROV_BRR_GATT: PROV_BRR_ADV;
  607. if (PROV_BRR_GATT == brr)
  608. {
  609. blebrr_gatt_mode_set(BLEBRR_GATT_PROV_MODE);
  610. }
  611. printf ("Setting up Device...\n");
  612. retval = MS_prov_setup
  613. (
  614. brr,
  615. PROV_ROLE_DEVICE,
  616. &appl_lprov_device,
  617. APPL_PROV_SETUP_TIMEOUT_SECS,
  618. APPL_PROV_SETUP_TIMEOUT_SECS
  619. );
  620. printf ("Retval - 0x%04X\n", retval);
  621. appl_prov_role = PROV_ROLE_DEVICE;
  622. break;
  623. case 15:
  624. appl_prov_start_provisioning();
  625. break;
  626. case 16:
  627. printf("Select OOB type (0 - Number, 1- String): ");
  628. scanf("%d", &choice);
  629. if (0 != choice)
  630. {
  631. printf("Enter the Authentication String: ");
  632. scanf("%s", authstr);
  633. pauth = authstr;
  634. authsize = EM_str_len(authstr);
  635. }
  636. else
  637. {
  638. printf("Enter the Authentication Value: ");
  639. scanf("%d", &choice);
  640. authnum = (UINT32)choice;
  641. pauth = (UCHAR *)&authnum;
  642. authsize = sizeof (UINT32);
  643. }
  644. /* Call to input the oob */
  645. printf("Input the Authval...\n");
  646. retval = MS_prov_input_authval(&appl_prov_handle, pauth, authsize);
  647. printf("Retval - 0x%04X\n", retval);
  648. break;
  649. case 30:
  650. #ifndef MESH_PTS_TEST
  651. printf("Device supports OOB Public Key? (1/0): ");
  652. scanf("%d", &choice);
  653. /* Update the Public Key OOB in method */
  654. appl_prov_method.pubkey = (choice)? PROV_PUBKEY_OOB: PROV_PUBKEY_OOB;
  655. if (0 != choice)
  656. {
  657. /* Set the OOB Public Key */
  658. printf("Enter OOB Public Key of device (64 octets):\n");
  659. for (i = 0; i < sizeof(pubkey); i++)
  660. {
  661. scanf("%x", &choice);
  662. pubkey[i] = (UCHAR)choice;
  663. }
  664. prov_set_device_oob_pubkey_pl(pubkey, sizeof(pubkey));
  665. }
  666. #else /* MESH_PTS_TEST */
  667. appl_prov_set_dev_public_key();
  668. #endif /* MESH_PTS_TEST */
  669. break;
  670. case 31:
  671. printf("Select OOB Authentication type?\n 0 - None\n 1 - Static\n 2 - Output\n 3 - Input\n: ");
  672. scanf("%d", &choice);
  673. /* Update the Public Key OOB in method */
  674. appl_prov_method.auth = choice;
  675. if (PROV_AUTH_OOB_STATIC == choice)
  676. {
  677. /* Set the Static OOB Auth Key */
  678. printf("Enter OOB Authrntication value (16 octets):\n");
  679. for (i = 0; i < sizeof(auth); i++)
  680. {
  681. #ifndef MESH_PTS_TEST
  682. scanf("%x", &choice);
  683. auth[i] = (UCHAR)choice;
  684. #else /* MESH_PTS_TEST */
  685. /**
  686. * Set the STATIC OOB value in PTS PIXIT table:
  687. * OOB: 0x11111111111111111111111111111111[16 Octets 0f 0x11]
  688. */
  689. auth[i] = 0x11;
  690. #endif /* MESH_PTS_TEST */
  691. }
  692. prov_set_static_oob_auth_pl(auth, sizeof(auth));
  693. }
  694. else if (PROV_AUTH_OOB_OUTPUT == choice)
  695. {
  696. /* Enter the OOB action to be used */
  697. printf("Enter OOB Action?\n 0 - Blink\n 1 - Beep\n 2 - Vibrate\n 3 - Numeric\n 4 - Alphanumeric\n: ");
  698. scanf("%d", &choice);
  699. appl_prov_method.oob.action = (UCHAR)choice;
  700. /* Enter the OOB size to be used */
  701. printf("Enter OOB Size (1 - 8): ");
  702. scanf("%d", &choice);
  703. appl_prov_method.oob.size = (UCHAR)choice;
  704. }
  705. else if (PROV_AUTH_OOB_INPUT == choice)
  706. {
  707. /* Enter the OOB action to be used */
  708. printf("Enter OOB Action?\n 0 - Push\n 1 - Twist\n 2 - Numeric\n 3 - Alphanumeric\n: ");
  709. scanf("%d", &choice);
  710. appl_prov_method.oob.action = (UCHAR)choice;
  711. /* Enter the OOB size to be used */
  712. printf("Enter OOB Size (1 - 8): ");
  713. scanf("%d", &choice);
  714. appl_prov_method.oob.size = (UCHAR)choice;
  715. }
  716. break;
  717. case 32:
  718. /* Print the Local ECDH Public Key */
  719. appl_prov_get_local_public_key();
  720. break;
  721. case 33:
  722. #ifdef MESH_PTS_TEST
  723. /* PTS defines the below Public/PrivateKey as its Default in PIXIT */
  724. appl_prov_set_debug_keys();
  725. #endif /* MESH_PTS_TEST */
  726. break;
  727. case 40:
  728. printf("Enter the reason to Abort (in Hex): ");
  729. scanf("%x", &choice);
  730. printf("Aborting...\n");
  731. retval = MS_prov_abort(&appl_prov_handle, (UCHAR)choice);
  732. printf("Retval - 0x%04X\n", retval);
  733. break;
  734. case 100:
  735. break;
  736. default:
  737. break;
  738. }
  739. }
  740. }
  741. API_RESULT appl_prov_update_remote_uuid
  742. (
  743. UCHAR * uuid,
  744. UINT16 uuid_len,
  745. UINT16 oob_info,
  746. UCHAR * uri
  747. )
  748. {
  749. API_RESULT retval;
  750. UINT32 i;
  751. retval = API_SUCCESS;
  752. for (i = 0; i < APPL_UNPROV_BEACON_LIST_SIZE; i++)
  753. {
  754. if (0 == EM_mem_cmp(uuid, appl_rprov_device[i].uuid, 16))
  755. {
  756. /* Mark for filtering */
  757. retval = API_FAILURE;
  758. /**
  759. * Break when there is an exisiting instance for incoming
  760. * UUID of the unprovisioned device.
  761. */
  762. break;
  763. }
  764. }
  765. if (API_SUCCESS != retval)
  766. {
  767. return retval;
  768. }
  769. printf ("Recvd PROV_EVT_UNPROVISIONED_BEACON");
  770. printf ("Status - 0x%04X", API_SUCCESS);
  771. /* printf("\nID: %d", appl_num_devices); */
  772. printf("UUID : [%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X]",
  773. uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5],
  774. uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11],
  775. uuid[2], uuid[13], uuid[14], uuid[15]);
  776. printf("OOB : 0x%04X", oob_info);
  777. if (NULL != uri)
  778. {
  779. printf("\nURI : 0x%08X", uri);
  780. }
  781. /* Copy the beacon to the list */
  782. EM_mem_copy (&appl_rprov_device[appl_num_devices].uuid, uuid, MS_DEVICE_UUID_SIZE);
  783. appl_rprov_device[appl_num_devices].oob = oob_info;
  784. /* appl_rprov_device[appl_num_devices].uri = uri; */
  785. /* Increment the list */
  786. appl_num_devices++;
  787. return retval;
  788. }
  789. void appl_prov_register(void)
  790. {
  791. API_RESULT retval;
  792. MS_PROV_DEV_ENTRY prov_dev_list[MS_MAX_DEV_KEYS];
  793. UINT16 num_entries;
  794. UINT16 pointer_entries;
  795. if (MS_TRUE == appl_prov_ready)
  796. {
  797. return;
  798. }
  799. appl_prov_ready = MS_TRUE;
  800. /* Fetch the number of elements in local node */
  801. MS_access_cm_get_element_count(&appl_prov_capab.num_elements);
  802. num_entries = MS_MAX_DEV_KEYS;
  803. /* Update the next device address if provisioned devices are present in database */
  804. retval = MS_access_cm_get_prov_devices_list
  805. (
  806. &prov_dev_list[0],
  807. &num_entries,
  808. &pointer_entries
  809. );
  810. if ((API_SUCCESS == retval) &&
  811. (0 != num_entries))
  812. {
  813. appl_prov_data.uaddr = prov_dev_list[num_entries - 1].uaddr +
  814. prov_dev_list[num_entries - 1].num_elements;
  815. printf("Updating Provisioning Start Addr to 0x%04X\n", appl_prov_data.uaddr);
  816. }
  817. printf("Registering with Provisioning layer...\n");
  818. retval = MS_prov_register(&appl_prov_capab, appl_prov_callback);
  819. printf("Retval - 0x%04X\n", retval);
  820. }
  821. void appl_prov_setup(UCHAR role, UCHAR brr)
  822. {
  823. API_RESULT retval;
  824. if (PROV_BRR_GATT == brr)
  825. {
  826. blebrr_gatt_mode_set(BLEBRR_GATT_PROV_MODE);
  827. }
  828. if (PROV_ROLE_PROVISIONER != role)
  829. {
  830. printf("Setting up Device for Provisioning ...\n");
  831. retval = MS_prov_setup
  832. (
  833. brr,
  834. role,
  835. &appl_lprov_device,
  836. APPL_PROV_SETUP_TIMEOUT_SECS,
  837. APPL_PROV_SETUP_TIMEOUT_SECS
  838. );
  839. appl_prov_role = PROV_ROLE_DEVICE;
  840. }
  841. else
  842. {
  843. printf("Setting up Provisioner for Provisioning ...\n");
  844. retval = MS_prov_setup
  845. (
  846. brr,
  847. role,
  848. NULL,
  849. APPL_PROV_SETUP_TIMEOUT_SECS,
  850. APPL_PROV_SETUP_TIMEOUT_SECS
  851. );
  852. appl_prov_role = PROV_ROLE_PROVISIONER;
  853. appl_num_devices = 0;
  854. /* Clear the list of Unprovisioned Device Here */
  855. EM_mem_set(appl_rprov_device, 0x0, sizeof(appl_rprov_device));
  856. /* Enable Scan */
  857. blebrr_scan_enable();
  858. }
  859. printf("Retval - 0x%04X\n", retval);
  860. }
  861. void appl_prov_bind(UCHAR brr, UCHAR index)
  862. {
  863. API_RESULT retval;
  864. /* Call to bind with the selected device */
  865. printf("Binding with the selected device...\n");
  866. if (PROV_ROLE_PROVISIONER == appl_prov_role)
  867. {
  868. retval = MS_prov_bind(brr, &appl_rprov_device[index], APPL_PROV_DEVICE_ATTENTION_TIMEOUT, &appl_prov_handle);
  869. }
  870. else
  871. {
  872. retval = MS_prov_bind(brr, &appl_lprov_device, APPL_PROV_DEVICE_ATTENTION_TIMEOUT, &appl_prov_handle);
  873. }
  874. printf("Retval - 0x%04X\n", retval);
  875. }
  876. void appl_prov_setup_provisioner(void)
  877. {
  878. // API_RESULT retval;
  879. UCHAR brr;
  880. int choice;
  881. printf ("Select the Bearer (0: PB-ADV, 1: PB-GATT): "); fflush (stdout);
  882. scanf ("%d", &choice);
  883. /* Set the Bearer */
  884. brr = (0 != choice)? PROV_BRR_GATT: PROV_BRR_ADV;
  885. appl_prov_setup(PROV_ROLE_PROVISIONER, brr);
  886. }
  887. void appl_prov_setup_device(void)
  888. {
  889. // API_RESULT retval;
  890. UCHAR brr;
  891. int choice;
  892. printf("Select the Bearer (0: PB-ADV, 1: PB-GATT): "); fflush(stdout);
  893. scanf("%d", &choice);
  894. /* Set the Bearer */
  895. brr = (0 != choice) ? PROV_BRR_GATT : PROV_BRR_ADV;
  896. appl_prov_setup(PROV_ROLE_DEVICE, brr);
  897. if (PROV_BRR_ADV == brr)
  898. {
  899. appl_prov_bind(brr, 0);
  900. }
  901. }
  902. static void appl_list_beacons(void)
  903. {
  904. UINT8 i, j;
  905. if (0 == appl_num_devices)
  906. {
  907. printf("No Unprovisioned beacon in list...\n");
  908. return;
  909. }
  910. for (i = 0; i < appl_num_devices; i++)
  911. {
  912. printf("%d. [", i);
  913. for (j = 0; j < MS_DEVICE_UUID_SIZE; j++)
  914. {
  915. printf("%02X", appl_rprov_device[i].uuid[j]);
  916. }
  917. printf("]\n");
  918. }
  919. }
  920. void appl_prov_start_provisioning(void)
  921. {
  922. // API_RESULT retval;
  923. UCHAR brr, i;
  924. int choice;
  925. if (PROV_ROLE_PROVISIONER == appl_prov_role)
  926. {
  927. if (0 == appl_num_devices)
  928. {
  929. printf("No Unprovisioned beacon in list...\n");
  930. return;
  931. }
  932. printf("Select the device to provision:\n");
  933. appl_list_beacons();
  934. scanf("%d", &choice);
  935. i = choice;
  936. }
  937. else
  938. {
  939. i = 0;
  940. }
  941. printf("Select the Bearer (0: PB-ADV, 1: PB-GATT): "); fflush(stdout);
  942. scanf("%d", &choice);
  943. /* Set the Bearer */
  944. brr = (0 != choice) ? PROV_BRR_GATT : PROV_BRR_ADV;
  945. appl_prov_bind(brr, i);
  946. }
  947. void appl_prov_input_auth_val (UCHAR mode, void * data, UINT16 datalen)
  948. {
  949. UCHAR * pauth;
  950. UINT16 authsize;
  951. UINT32 authnum;
  952. API_RESULT retval;
  953. /**
  954. * MODE = 0 -> Numeric
  955. * MODE = 1 -> Alphanumeric
  956. */
  957. if (0 != mode)
  958. {
  959. pauth = (UCHAR *) data;
  960. authsize = datalen;
  961. }
  962. else
  963. {
  964. authnum = *((UINT32 *)data);
  965. pauth = (UCHAR *)&authnum;
  966. authsize = sizeof (UINT32);
  967. }
  968. /* Call to input the oob */
  969. printf("Input the Authval...\n");
  970. retval = MS_prov_input_authval(&appl_prov_handle, pauth, authsize);
  971. printf("Retval - 0x%04X\n", retval);
  972. }
  973. void appl_prov_set_dev_public_key(void)
  974. {
  975. /* PTS defines the below Publickey as its Default in PIXIT */
  976. UCHAR appl_t_pub_key[PROV_PUBKEY_SIZE_PL] =
  977. {
  978. 0xF4, 0x65, 0xE4, 0x3F, 0xF2, 0x3D, 0x3F, 0x1B,
  979. 0x9D, 0xC7, 0xDF, 0xC0, 0x4D, 0xA8, 0x75, 0x81,
  980. 0x84, 0xDB, 0xC9, 0x66, 0x20, 0x47, 0x96, 0xEC,
  981. 0xCF, 0x0D, 0x6C, 0xF5, 0xE1, 0x65, 0x00, 0xCC,
  982. 0x02, 0x01, 0xD0, 0x48, 0xBC, 0xBB, 0xD8, 0x99,
  983. 0xEE, 0xEF, 0xC4, 0x24, 0x16, 0x4E, 0x33, 0xC2,
  984. 0x01, 0xC2, 0xB0, 0x10, 0xCA, 0x6B, 0x4D, 0x43,
  985. 0xA8, 0xA1, 0x55, 0xCA, 0xD8, 0xEC, 0xB2, 0x79
  986. };
  987. /* Update the Public Key OOB in method */
  988. appl_prov_method.pubkey = PROV_PUBKEY_OOB;
  989. prov_set_device_oob_pubkey_pl(appl_t_pub_key, sizeof(appl_t_pub_key));
  990. printf ("Setting Device Public Key : \n");
  991. appl_dump_bytes(appl_t_pub_key, sizeof(appl_t_pub_key));
  992. }
  993. void appl_prov_get_local_public_key(void)
  994. {
  995. UCHAR appl_t_pub_key[PROV_PUBKEY_SIZE_PL];
  996. UCHAR pdata[(PROV_PUBKEY_SIZE_PL * 2) + 1];
  997. UCHAR * t_data;
  998. // INT32 ret;
  999. UINT32 i;
  1000. EM_mem_set(appl_t_pub_key, 0x0, PROV_PUBKEY_SIZE_PL);
  1001. EM_mem_set(pdata, 0x0, sizeof(pdata));
  1002. t_data = pdata;
  1003. MS_prov_get_local_public_key(appl_t_pub_key);
  1004. printf("\n Local ECDH P256 Public Key: [Dump]\n");
  1005. appl_dump_bytes(appl_t_pub_key, PROV_PUBKEY_SIZE_PL);
  1006. printf("\n Local ECDH P256 Public Key: [MSB-LSB]:\n");
  1007. #if 0
  1008. for (i = 0; i < PROV_PUBKEY_SIZE_PL; i++)
  1009. {
  1010. printf("%02X", appl_t_pub_key[i]);
  1011. }
  1012. printf("\n");
  1013. #else
  1014. for (i = 0; i < (PROV_PUBKEY_SIZE_PL); i++)
  1015. {
  1016. sprintf((char *)t_data,"%02X", appl_t_pub_key[i]);
  1017. t_data += 2;
  1018. }
  1019. printf("%s\n", pdata);
  1020. #endif
  1021. }
  1022. void appl_prov_set_debug_keys(void)
  1023. {
  1024. /* PTS defines the below Public/PrivateKey as its Default in PIXIT */
  1025. UCHAR appl_t_pvt_key[(PROV_PUBKEY_SIZE_PL/2)] =
  1026. {
  1027. 0x52, 0x9A, 0xA0, 0x67, 0x0D, 0x72, 0xCD, 0x64,
  1028. 0x97, 0x50, 0x2E, 0xD4, 0x73, 0x50, 0x2B, 0x03,
  1029. 0x7E, 0x88, 0x03, 0xB5, 0xC6, 0x08, 0x29, 0xA5,
  1030. 0xA3, 0xCA, 0xA2, 0x19, 0x50, 0x55, 0x30, 0xBA
  1031. };
  1032. UCHAR appl_t_pub_key[PROV_PUBKEY_SIZE_PL] =
  1033. {
  1034. 0xF4, 0x65, 0xE4, 0x3F, 0xF2, 0x3D, 0x3F, 0x1B,
  1035. 0x9D, 0xC7, 0xDF, 0xC0, 0x4D, 0xA8, 0x75, 0x81,
  1036. 0x84, 0xDB, 0xC9, 0x66, 0x20, 0x47, 0x96, 0xEC,
  1037. 0xCF, 0x0D, 0x6C, 0xF5, 0xE1, 0x65, 0x00, 0xCC,
  1038. 0x02, 0x01, 0xD0, 0x48, 0xBC, 0xBB, 0xD8, 0x99,
  1039. 0xEE, 0xEF, 0xC4, 0x24, 0x16, 0x4E, 0x33, 0xC2,
  1040. 0x01, 0xC2, 0xB0, 0x10, 0xCA, 0x6B, 0x4D, 0x43,
  1041. 0xA8, 0xA1, 0x55, 0xCA, 0xD8, 0xEC, 0xB2, 0x79
  1042. };
  1043. cry_set_ecdh_debug_keypair(appl_t_pvt_key, appl_t_pub_key);
  1044. printf ("Setting Debug Public Key : \n");
  1045. appl_dump_bytes(appl_t_pub_key, sizeof(appl_t_pub_key));
  1046. printf ("Setting Debug Private Key : \n");
  1047. appl_dump_bytes(appl_t_pvt_key, sizeof(appl_t_pvt_key));
  1048. }
  1049. void appl_prov_set_auth_action
  1050. (
  1051. UCHAR mode,
  1052. UCHAR * s_oob_val,
  1053. UCHAR oob_act,
  1054. UCHAR oob_sz
  1055. )
  1056. {
  1057. UCHAR auth[PROV_AUTHVAL_SIZE_PL];
  1058. /**
  1059. * Valid Values of Mode for OOB usage are:
  1060. * 0x00 - None
  1061. * 0x01 - Static
  1062. * 0x02 - Output
  1063. * 0x03 - Input
  1064. */
  1065. /* Update the Authentication method based on "Mode" in "method" */
  1066. appl_prov_method.auth = mode;
  1067. if (PROV_AUTH_OOB_STATIC == mode)
  1068. {
  1069. /**
  1070. * TODO: Have a User provided value from CLI through "s_oob_val"
  1071. */
  1072. /**
  1073. * Set the STATIC OOB value in PTS PIXIT table:
  1074. * OOB: 0x11111111111111111111111111111111[16 Octets 0f 0x11]
  1075. */
  1076. EM_mem_set(auth, 0x11, sizeof(auth));
  1077. prov_set_static_oob_auth_pl(auth, sizeof(auth));
  1078. printf("\n Setting PROV_AUTH_OOB_STATIC mode");
  1079. printf("\n Static OOB used is:\n");
  1080. appl_dump_bytes(auth, sizeof(auth));
  1081. }
  1082. else if (PROV_AUTH_OOB_OUTPUT == mode)
  1083. {
  1084. /**
  1085. * Output OOB Action valid values
  1086. * 0x00 - Blink
  1087. * 0x01 - Beep
  1088. * 0x02 - Vibrate
  1089. * 0x03 - Numeric
  1090. * 0x04 - Alphanumeric
  1091. */
  1092. appl_prov_method.oob.action = oob_act;
  1093. appl_prov_method.oob.size = oob_sz;
  1094. printf("\n Setting PROV_AUTH_OOB_OUTPUT mode\n");
  1095. printf("\n OOB of size: %02d", oob_sz);
  1096. printf("\n OOB action : %s\n",
  1097. (0x00 == oob_act) ? "Blink" :
  1098. (0x01 == oob_act) ? "Beep":
  1099. (0x02 == oob_act) ? "Vibrate":
  1100. (0x03 == oob_act) ? "Numeric":
  1101. (0x04 == oob_act) ? "Alphanumeric": "Unknown");
  1102. }
  1103. else if (PROV_AUTH_OOB_INPUT == mode)
  1104. {
  1105. /**
  1106. * Input OOB Action valid values
  1107. * 0x00 - Push
  1108. * 0x01 - Twist
  1109. * 0x02 - Numeric
  1110. * 0x03 - Alphanumeric
  1111. */
  1112. appl_prov_method.oob.action = oob_act;
  1113. appl_prov_method.oob.size = oob_sz;
  1114. printf("\n Setting PROV_AUTH_OOB_INPUT mode");
  1115. printf("\n OOB of size: %02d", oob_sz);
  1116. printf("\n OOB action : %s\n",
  1117. (0x00 == oob_act) ? "Push" :
  1118. (0x01 == oob_act) ? "Twist":
  1119. (0x02 == oob_act) ? "Numeric":
  1120. (0x03 == oob_act) ? "Alphanumeric": "Unknown");
  1121. }
  1122. else
  1123. {
  1124. /* Assign default OOB mode */
  1125. appl_prov_method.auth = PROV_AUTH_OOB_NONE;
  1126. printf("\n Setting PROV_AUTH_OOB_NONE mode\n");
  1127. }
  1128. }
  1129. API_RESULT appl_is_configured (void)
  1130. {
  1131. MS_APPKEY_HANDLE handle;
  1132. UINT8 * key;
  1133. UINT8 aid;
  1134. DECL_CONST UINT8 t_key[16] = {0};
  1135. MS_NET_ADDR addr;
  1136. API_RESULT retval;
  1137. CONSOLE_OUT("Check for Primary Unicast Address\n");
  1138. retval = MS_access_cm_get_primary_unicast_address(&addr);
  1139. if ((API_SUCCESS != retval) ||
  1140. (MS_NET_ADDR_UNASSIGNED == addr))
  1141. {
  1142. return API_FAILURE;
  1143. }
  1144. CONSOLE_OUT("Fetching App Key for Handle 0x0000\n");
  1145. handle = 0x0000;
  1146. retval = MS_access_cm_get_app_key
  1147. (
  1148. handle,
  1149. &key,
  1150. &aid
  1151. );
  1152. /* Check Retval. Print App Key */
  1153. if (API_SUCCESS == retval)
  1154. {
  1155. CONSOLE_OUT("App Key[0x%02X]: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\r\n",
  1156. handle, key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7],
  1157. key[8], key[9], key[10], key[11], key[12], key[13], key[14], key[15]);
  1158. if (0 == EM_mem_cmp(key, t_key, 16))
  1159. {
  1160. /* NO AppKey Bound */
  1161. retval = API_FAILURE;
  1162. }
  1163. else
  1164. {
  1165. /* Found a Valid App Key */
  1166. /* Keeping the retval as API_SUCCESS */
  1167. }
  1168. }
  1169. return retval;
  1170. }