conn_mw_ant.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include <string.h>
  41. #include "ant_conn.h"
  42. #include "conn_mw_ant.h"
  43. #include "ble_serialization.h"
  44. #include "nrf_log_ctrl.h"
  45. #include "sdk_config.h"
  46. #define ANT_BUFFER_SIZE_FOR_SD ANT_ENABLE_GET_REQUIRED_SPACE(ANT_SER_CONFIG_TOTAL_CHANNELS_ALLOCATED, \
  47. ANT_SER_CONFIG_ENCRYPTED_CHANNELS, \
  48. ANT_SER_CONFIG_BURST_QUEUE_SIZE, \
  49. ANT_SER_CONFIG_EVENT_QUEUE_SIZE)
  50. #define ANT_ADV_BURST_CFG_SIZE_MAX (11u)
  51. #define ANT_CRYPTO_INFO_SIZE (((MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE) - \
  52. (MESG_CHANNEL_NUM_SIZE)) + \
  53. ((MESG_CONFIG_ENCRYPT_REQ_CONFIG_ID_SIZE) - \
  54. (MESG_CHANNEL_NUM_SIZE)))
  55. #define ANT_CRYPTO_INFO_MAX_SIZE (MESG_CONFIG_ENCRYPT_REQ_CONFIG_USER_DATA_SIZE - \
  56. MESG_CHANNEL_NUM_SIZE)
  57. #ifdef ANT_STACK_SUPPORT_REQD
  58. static union
  59. {
  60. uint8_t u8[ANT_BUFFER_SIZE_FOR_SD];
  61. uint32_t u32[1]; // force allign to uint32_t
  62. }ant_stack_buffer; /*!< Memory buffer provided in order to support channel configuration */
  63. #endif
  64. uint32_t conn_mw_ant_enable(uint8_t const * const p_rx_buf,
  65. uint32_t rx_buf_len,
  66. uint8_t * const p_tx_buf,
  67. uint32_t * const p_tx_buf_len)
  68. {
  69. SER_ASSERT_NOT_NULL(p_rx_buf);
  70. SER_ASSERT_NOT_NULL(p_tx_buf);
  71. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  72. ANT_ENABLE params;
  73. ANT_ENABLE * p_params = &params;
  74. uint32_t err_code = NRF_SUCCESS;
  75. uint32_t sd_err_code = 0;
  76. err_code = ant_enable_req_dec(p_rx_buf, rx_buf_len, &p_params);
  77. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  78. SER_ASSERT(p_params -> ucTotalNumberOfChannels == ANT_SER_CONFIG_TOTAL_CHANNELS_ALLOCATED, err_code);
  79. SER_ASSERT(p_params -> ucNumberOfEncryptedChannels == ANT_SER_CONFIG_ENCRYPTED_CHANNELS, err_code);
  80. SER_ASSERT(p_params -> usNumberOfEvents == ANT_SER_CONFIG_EVENT_QUEUE_SIZE, err_code);
  81. SER_ASSERT(p_params -> usMemoryBlockByteSize == ANT_BUFFER_SIZE_FOR_SD, err_code);
  82. ANT_ENABLE m_ant_enable_cfg =
  83. {
  84. .ucTotalNumberOfChannels = p_params -> ucTotalNumberOfChannels,
  85. .ucNumberOfEncryptedChannels = p_params -> ucNumberOfEncryptedChannels,
  86. .usNumberOfEvents = p_params -> usNumberOfEvents,
  87. .pucMemoryBlockStartLocation = ant_stack_buffer.u8,
  88. .usMemoryBlockByteSize = p_params -> usMemoryBlockByteSize
  89. };
  90. sd_err_code = sd_ant_enable(&m_ant_enable_cfg);
  91. err_code = ant_enable_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  92. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  93. return err_code;
  94. }
  95. uint32_t conn_ant_channel_assign(uint8_t const * const p_rx_buf,
  96. uint32_t rx_buf_len,
  97. uint8_t * const p_tx_buf,
  98. uint32_t * const p_tx_buf_len)
  99. {
  100. SER_ASSERT_NOT_NULL(p_rx_buf);
  101. SER_ASSERT_NOT_NULL(p_tx_buf);
  102. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  103. uint8_t channel;
  104. uint8_t type;
  105. uint8_t network;
  106. uint8_t ext_assign;
  107. uint32_t err_code = NRF_SUCCESS;
  108. uint32_t sd_err_code = 0;
  109. err_code =ant_channel_assign_req_dec(p_rx_buf, rx_buf_len, &channel, &type, &network, &ext_assign);
  110. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  111. //disabled till codec is adopted.
  112. sd_err_code = sd_ant_channel_assign(channel, type, network, ext_assign);
  113. err_code = ant_channel_assign_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  114. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  115. return err_code;
  116. }
  117. uint32_t conn_ant_channel_open_with_offset(uint8_t const * const p_rx_buf,
  118. uint32_t rx_buf_len,
  119. uint8_t * const p_tx_buf,
  120. uint32_t * const p_tx_buf_len)
  121. {
  122. SER_ASSERT_NOT_NULL(p_rx_buf);
  123. SER_ASSERT_NOT_NULL(p_tx_buf);
  124. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  125. uint8_t channel;
  126. uint16_t usOffset;
  127. uint32_t err_code = NRF_SUCCESS;
  128. uint32_t sd_err_code = 0;
  129. err_code = ant_channel_open_with_offset_req_dec(p_rx_buf, rx_buf_len, &channel, &usOffset);
  130. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  131. sd_err_code = sd_ant_channel_open_with_offset(channel, usOffset);
  132. err_code = ant_channel_open_with_offset_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  133. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  134. return err_code;
  135. }
  136. uint32_t conn_ant_channel_id_set(uint8_t const * const p_rx_buf,
  137. uint32_t rx_buf_len,
  138. uint8_t * const p_tx_buf,
  139. uint32_t * const p_tx_buf_len)
  140. {
  141. SER_ASSERT_NOT_NULL(p_rx_buf);
  142. SER_ASSERT_NOT_NULL(p_tx_buf);
  143. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  144. uint8_t channel;
  145. uint16_t device_number;
  146. uint8_t device_type;
  147. uint8_t transmission_type;
  148. uint32_t err_code = NRF_SUCCESS;
  149. uint32_t sd_err_code = 0;
  150. err_code =ant_channel_id_set_req_dec(p_rx_buf, rx_buf_len, &channel, &device_number, &device_type, &transmission_type);
  151. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  152. //disabled till codec is adopted.
  153. sd_err_code = sd_ant_channel_id_set(channel, device_number, device_type, transmission_type);
  154. err_code = ant_channel_id_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  155. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  156. return err_code;
  157. }
  158. uint32_t conn_ant_channel_period_set(uint8_t const * const p_rx_buf,
  159. uint32_t rx_buf_len,
  160. uint8_t * const p_tx_buf,
  161. uint32_t * const p_tx_buf_len)
  162. {
  163. SER_ASSERT_NOT_NULL(p_rx_buf);
  164. SER_ASSERT_NOT_NULL(p_tx_buf);
  165. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  166. uint8_t channel;
  167. uint16_t period;
  168. uint32_t err_code = NRF_SUCCESS;
  169. uint32_t sd_err_code = 0;
  170. err_code = ant_channel_period_set_req_dec(p_rx_buf, rx_buf_len, &channel, &period);
  171. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  172. sd_err_code = sd_ant_channel_period_set(channel, period);
  173. err_code = ant_channel_period_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  174. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  175. return err_code;
  176. }
  177. uint32_t conn_ant_channel_radio_freq_set(uint8_t const * const p_rx_buf,
  178. uint32_t rx_buf_len,
  179. uint8_t * const p_tx_buf,
  180. uint32_t * const p_tx_buf_len)
  181. {
  182. SER_ASSERT_NOT_NULL(p_rx_buf);
  183. SER_ASSERT_NOT_NULL(p_tx_buf);
  184. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  185. uint8_t channel;
  186. uint8_t freq;
  187. uint32_t err_code = NRF_SUCCESS;
  188. uint32_t sd_err_code = 0;
  189. err_code = ant_channel_radio_freq_set_req_dec(p_rx_buf, rx_buf_len, &channel, &freq);
  190. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  191. sd_err_code = sd_ant_channel_radio_freq_set(channel, freq);
  192. err_code = ant_channel_radio_freq_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  193. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  194. return err_code;
  195. }
  196. uint32_t conn_ant_broadcast_message_tx(uint8_t const * const p_rx_buf,
  197. uint32_t rx_buf_len,
  198. uint8_t * const p_tx_buf,
  199. uint32_t * const p_tx_buf_len)
  200. {
  201. SER_ASSERT_NOT_NULL(p_rx_buf);
  202. SER_ASSERT_NOT_NULL(p_tx_buf);
  203. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  204. uint8_t channel;
  205. uint8_t size;
  206. uint8_t mesg[ANT_STANDARD_DATA_PAYLOAD_SIZE];
  207. uint8_t * p_mesg = mesg;
  208. uint32_t err_code = NRF_SUCCESS;
  209. uint32_t sd_err_code = 0;
  210. err_code = ant_broadcast_message_tx_req_dec(p_rx_buf, rx_buf_len, &channel, &size, &p_mesg);
  211. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  212. sd_err_code = sd_ant_broadcast_message_tx(channel, size, p_mesg);
  213. err_code = ant_broadcast_message_tx_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  214. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  215. return err_code;
  216. }
  217. uint32_t conn_ant_acknowledge_message_tx(uint8_t const * const p_rx_buf,
  218. uint32_t rx_buf_len,
  219. uint8_t * const p_tx_buf,
  220. uint32_t * const p_tx_buf_len)
  221. {
  222. SER_ASSERT_NOT_NULL(p_rx_buf);
  223. SER_ASSERT_NOT_NULL(p_tx_buf);
  224. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  225. uint8_t channel;
  226. uint8_t size;
  227. uint8_t mesg[ANT_STANDARD_DATA_PAYLOAD_SIZE];
  228. uint8_t * p_mesg = mesg;
  229. uint32_t err_code = NRF_SUCCESS;
  230. uint32_t sd_err_code = 0;
  231. err_code = ant_acknowledge_message_tx_req_dec(p_rx_buf, rx_buf_len, &channel, &size, &p_mesg);
  232. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  233. sd_err_code = sd_ant_acknowledge_message_tx(channel, size, p_mesg);
  234. err_code = ant_acknowledge_message_tx_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  235. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  236. return err_code;
  237. }
  238. uint32_t conn_ant_channel_unassign(uint8_t const * const p_rx_buf,
  239. uint32_t rx_buf_len,
  240. uint8_t * const p_tx_buf,
  241. uint32_t * const p_tx_buf_len)
  242. {
  243. SER_ASSERT_NOT_NULL(p_rx_buf);
  244. SER_ASSERT_NOT_NULL(p_tx_buf);
  245. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  246. uint8_t channel;
  247. uint32_t err_code = NRF_SUCCESS;
  248. uint32_t sd_err_code = 0;
  249. err_code = ant_channel_unassign_req_dec(p_rx_buf, rx_buf_len, &channel);
  250. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  251. sd_err_code = sd_ant_channel_unassign(channel);
  252. err_code = ant_channel_unassign_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  253. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  254. return err_code;
  255. }
  256. uint32_t conn_ant_channel_close(uint8_t const * const p_rx_buf,
  257. uint32_t rx_buf_len,
  258. uint8_t * const p_tx_buf,
  259. uint32_t * const p_tx_buf_len)
  260. {
  261. SER_ASSERT_NOT_NULL(p_rx_buf);
  262. SER_ASSERT_NOT_NULL(p_tx_buf);
  263. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  264. uint8_t channel;
  265. uint32_t err_code = NRF_SUCCESS;
  266. uint32_t sd_err_code = 0;
  267. err_code = ant_channel_close_req_dec(p_rx_buf, rx_buf_len, &channel);
  268. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  269. sd_err_code = sd_ant_channel_close(channel);
  270. err_code = ant_channel_close_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  271. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  272. return err_code;
  273. }
  274. uint32_t conn_ant_network_address_set(uint8_t const * const p_rx_buf,
  275. uint32_t rx_buf_len,
  276. uint8_t * const p_tx_buf,
  277. uint32_t * const p_tx_buf_len)
  278. {
  279. SER_ASSERT_NOT_NULL(p_rx_buf);
  280. SER_ASSERT_NOT_NULL(p_tx_buf);
  281. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  282. uint8_t network;
  283. uint8_t network_address[MESG_NETWORK_KEY_SIZE - MESG_CHANNEL_NUM_SIZE];
  284. uint8_t * p_network_address = network_address;
  285. uint32_t err_code = NRF_SUCCESS;
  286. uint32_t sd_err_code = 0;
  287. err_code = ant_network_address_set_req_dec(p_rx_buf, rx_buf_len, &network, &p_network_address);
  288. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  289. sd_err_code = sd_ant_network_address_set(network, p_network_address);
  290. err_code = ant_network_address_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  291. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  292. return err_code;
  293. }
  294. uint32_t conn_ant_channel_radio_tx_power_set(uint8_t const * const p_rx_buf,
  295. uint32_t rx_buf_len,
  296. uint8_t * const p_tx_buf,
  297. uint32_t * const p_tx_buf_len)
  298. {
  299. SER_ASSERT_NOT_NULL(p_rx_buf);
  300. SER_ASSERT_NOT_NULL(p_tx_buf);
  301. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  302. uint8_t channel;
  303. uint8_t tx_power;
  304. uint8_t custom_tx_power;
  305. uint32_t err_code = NRF_SUCCESS;
  306. uint32_t sd_err_code = 0;
  307. err_code = ant_channel_radio_tx_power_set_req_dec(p_rx_buf, rx_buf_len, &channel, &tx_power, &custom_tx_power);
  308. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  309. sd_err_code = sd_ant_channel_radio_tx_power_set(channel, tx_power, custom_tx_power);
  310. err_code = ant_channel_radio_tx_power_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  311. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  312. return err_code;
  313. }
  314. uint32_t conn_ant_channel_rx_search_timeout_set(uint8_t const * const p_rx_buf,
  315. uint32_t rx_buf_len,
  316. uint8_t * const p_tx_buf,
  317. uint32_t * const p_tx_buf_len)
  318. {
  319. SER_ASSERT_NOT_NULL(p_rx_buf);
  320. SER_ASSERT_NOT_NULL(p_tx_buf);
  321. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  322. uint8_t channel;
  323. uint8_t timeout;
  324. uint32_t err_code = NRF_SUCCESS;
  325. uint32_t sd_err_code = 0;
  326. err_code = ant_channel_rx_search_timeout_set_req_dec(p_rx_buf, rx_buf_len, &channel, &timeout);
  327. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  328. sd_err_code = sd_ant_channel_rx_search_timeout_set(channel, timeout);
  329. err_code = ant_channel_rx_search_timeout_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  330. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  331. return err_code;
  332. }
  333. uint32_t conn_ant_channel_low_priority_rx_search_timeout_set(uint8_t const * const p_rx_buf,
  334. uint32_t rx_buf_len,
  335. uint8_t * const p_tx_buf,
  336. uint32_t * const p_tx_buf_len)
  337. {
  338. SER_ASSERT_NOT_NULL(p_rx_buf);
  339. SER_ASSERT_NOT_NULL(p_tx_buf);
  340. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  341. uint8_t channel;
  342. uint8_t timeout;
  343. uint32_t err_code = NRF_SUCCESS;
  344. uint32_t sd_err_code = 0;
  345. err_code = ant_channel_low_priority_rx_search_timeout_set_req_dec(p_rx_buf, rx_buf_len, &channel, &timeout);
  346. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  347. sd_err_code = sd_ant_channel_low_priority_rx_search_timeout_set(channel, timeout);
  348. err_code = ant_channel_low_priority_rx_search_timeout_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  349. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  350. return err_code;
  351. }
  352. uint32_t conn_ant_prox_search_set(uint8_t const * const p_rx_buf,
  353. uint32_t rx_buf_len,
  354. uint8_t * const p_tx_buf,
  355. uint32_t * const p_tx_buf_len)
  356. {
  357. SER_ASSERT_NOT_NULL(p_rx_buf);
  358. SER_ASSERT_NOT_NULL(p_tx_buf);
  359. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  360. uint8_t channel;
  361. uint8_t prox_threshold;
  362. uint8_t custom_prox_threshold;
  363. uint32_t err_code = NRF_SUCCESS;
  364. uint32_t sd_err_code = 0;
  365. err_code = ant_prox_search_set_req_dec(p_rx_buf, rx_buf_len, &channel, &prox_threshold, &custom_prox_threshold);
  366. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  367. sd_err_code = sd_ant_prox_search_set(channel, prox_threshold, custom_prox_threshold);
  368. err_code = ant_prox_search_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  369. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  370. return err_code;
  371. }
  372. uint32_t conn_ant_search_waveform_set(uint8_t const * const p_rx_buf,
  373. uint32_t rx_buf_len,
  374. uint8_t * const p_tx_buf,
  375. uint32_t * const p_tx_buf_len)
  376. {
  377. SER_ASSERT_NOT_NULL(p_rx_buf);
  378. SER_ASSERT_NOT_NULL(p_tx_buf);
  379. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  380. uint8_t channel;
  381. uint16_t waveform;
  382. uint32_t err_code = NRF_SUCCESS;
  383. uint32_t sd_err_code = 0;
  384. err_code = ant_search_waveform_set_req_dec(p_rx_buf, rx_buf_len, &channel, &waveform);
  385. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  386. sd_err_code = sd_ant_search_waveform_set(channel, waveform);
  387. err_code = ant_search_waveform_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  388. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  389. return err_code;
  390. }
  391. uint32_t conn_ant_channel_id_get(uint8_t const * const p_rx_buf,
  392. uint32_t rx_buf_len,
  393. uint8_t * const p_tx_buf,
  394. uint32_t * const p_tx_buf_len)
  395. {
  396. SER_ASSERT_NOT_NULL(p_rx_buf);
  397. SER_ASSERT_NOT_NULL(p_tx_buf);
  398. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  399. uint16_t device_number;
  400. uint8_t device_type;
  401. uint8_t transmit_type;
  402. uint8_t channel;
  403. uint16_t * p_device_number = &device_number;
  404. uint8_t * p_device_type = &device_type;
  405. uint8_t * p_transmit_type = &transmit_type;
  406. uint32_t err_code = NRF_SUCCESS;
  407. uint32_t sd_err_code = 0;
  408. err_code = ant_channel_id_get_req_dec(p_rx_buf, rx_buf_len, &channel);
  409. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  410. sd_err_code = sd_ant_channel_id_get(channel, p_device_number, p_device_type, p_transmit_type);
  411. err_code = ant_channel_id_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_device_number, p_device_type, p_transmit_type);
  412. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  413. return err_code;
  414. }
  415. uint32_t conn_ant_channel_radio_freq_get(uint8_t const * const p_rx_buf,
  416. uint32_t rx_buf_len,
  417. uint8_t * const p_tx_buf,
  418. uint32_t * const p_tx_buf_len)
  419. {
  420. SER_ASSERT_NOT_NULL(p_rx_buf);
  421. SER_ASSERT_NOT_NULL(p_tx_buf);
  422. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  423. uint8_t r_freq;
  424. uint8_t channel;
  425. uint8_t * p_r_freq = &r_freq;
  426. uint32_t err_code = NRF_SUCCESS;
  427. uint32_t sd_err_code = 0;
  428. err_code = ant_channel_radio_freq_get_req_dec(p_rx_buf, rx_buf_len, &channel);
  429. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  430. sd_err_code = sd_ant_channel_radio_freq_get(channel, p_r_freq);
  431. err_code = ant_channel_radio_freq_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_r_freq);
  432. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  433. return err_code;
  434. }
  435. uint32_t conn_ant_channel_period_get(uint8_t const * const p_rx_buf,
  436. uint32_t rx_buf_len,
  437. uint8_t * const p_tx_buf,
  438. uint32_t * const p_tx_buf_len)
  439. {
  440. SER_ASSERT_NOT_NULL(p_rx_buf);
  441. SER_ASSERT_NOT_NULL(p_tx_buf);
  442. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  443. uint16_t period;
  444. uint8_t channel;
  445. uint16_t * p_period = &period;
  446. uint32_t err_code = NRF_SUCCESS;
  447. uint32_t sd_err_code = 0;
  448. err_code = ant_channel_period_get_req_dec(p_rx_buf, rx_buf_len, &channel);
  449. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  450. sd_err_code = sd_ant_channel_period_get(channel, p_period);
  451. err_code = ant_channel_period_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_period);
  452. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  453. return err_code;
  454. }
  455. uint32_t conn_ant_search_channel_priority_set(uint8_t const * const p_rx_buf,
  456. uint32_t rx_buf_len,
  457. uint8_t * const p_tx_buf,
  458. uint32_t * const p_tx_buf_len)
  459. {
  460. SER_ASSERT_NOT_NULL(p_rx_buf);
  461. SER_ASSERT_NOT_NULL(p_tx_buf);
  462. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  463. uint8_t channel;
  464. uint8_t search_priority;
  465. uint32_t err_code = NRF_SUCCESS;
  466. uint32_t sd_err_code = 0;
  467. err_code = ant_search_channel_priority_set_req_dec(p_rx_buf, rx_buf_len, &channel, &search_priority);
  468. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  469. sd_err_code = sd_ant_search_channel_priority_set(channel, search_priority);
  470. err_code = ant_search_channel_priority_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  471. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  472. return err_code;
  473. }
  474. uint32_t conn_ant_active_search_sharing_cycles_set(uint8_t const * const p_rx_buf,
  475. uint32_t rx_buf_len,
  476. uint8_t * const p_tx_buf,
  477. uint32_t * const p_tx_buf_len)
  478. {
  479. SER_ASSERT_NOT_NULL(p_rx_buf);
  480. SER_ASSERT_NOT_NULL(p_tx_buf);
  481. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  482. uint8_t channel;
  483. uint8_t cycles;
  484. uint32_t err_code = NRF_SUCCESS;
  485. uint32_t sd_err_code = 0;
  486. err_code = ant_active_search_sharing_cycles_set_req_dec(p_rx_buf, rx_buf_len, &channel, &cycles);
  487. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  488. sd_err_code = sd_ant_active_search_sharing_cycles_set(channel, cycles);
  489. err_code = ant_active_search_sharing_cycles_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  490. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  491. return err_code;
  492. }
  493. uint32_t conn_ant_lib_config_set(uint8_t const * const p_rx_buf,
  494. uint32_t rx_buf_len,
  495. uint8_t * const p_tx_buf,
  496. uint32_t * const p_tx_buf_len)
  497. {
  498. SER_ASSERT_NOT_NULL(p_rx_buf);
  499. SER_ASSERT_NOT_NULL(p_tx_buf);
  500. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  501. uint8_t ant_lib_config;
  502. uint32_t err_code = NRF_SUCCESS;
  503. uint32_t sd_err_code = 0;
  504. err_code = ant_lib_config_set_req_dec(p_rx_buf, rx_buf_len, &ant_lib_config);
  505. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  506. sd_err_code = sd_ant_lib_config_set(ant_lib_config);
  507. err_code = ant_lib_config_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  508. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  509. return err_code;
  510. }
  511. uint32_t conn_ant_active_search_sharing_cycles_get(uint8_t const * const p_rx_buf,
  512. uint32_t rx_buf_len,
  513. uint8_t * const p_tx_buf,
  514. uint32_t * const p_tx_buf_len)
  515. {
  516. SER_ASSERT_NOT_NULL(p_rx_buf);
  517. SER_ASSERT_NOT_NULL(p_tx_buf);
  518. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  519. uint8_t cycles;
  520. uint8_t channel;
  521. uint8_t * p_cycles = &cycles;
  522. uint32_t err_code = NRF_SUCCESS;
  523. uint32_t sd_err_code = 0;
  524. err_code = ant_active_search_sharing_cycles_get_req_dec(p_rx_buf, rx_buf_len, &channel);
  525. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  526. sd_err_code = sd_ant_active_search_sharing_cycles_get(channel, p_cycles);
  527. err_code = ant_active_search_sharing_cycles_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_cycles);
  528. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  529. return err_code;
  530. }
  531. uint32_t conn_ant_lib_config_get(uint8_t const * const p_rx_buf,
  532. uint32_t rx_buf_len,
  533. uint8_t * const p_tx_buf,
  534. uint32_t * const p_tx_buf_len)
  535. {
  536. SER_ASSERT_NOT_NULL(p_rx_buf);
  537. SER_ASSERT_NOT_NULL(p_tx_buf);
  538. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  539. uint8_t ant_lib_config;
  540. uint8_t * p_ant_lib_config = &ant_lib_config;
  541. uint32_t err_code = NRF_SUCCESS;
  542. uint32_t sd_err_code = 0;
  543. sd_err_code = sd_ant_lib_config_get(p_ant_lib_config);
  544. err_code = ant_lib_config_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_ant_lib_config);
  545. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  546. return err_code;
  547. }
  548. uint32_t conn_ant_lib_config_clear(uint8_t const * const p_rx_buf,
  549. uint32_t rx_buf_len,
  550. uint8_t * const p_tx_buf,
  551. uint32_t * const p_tx_buf_len)
  552. {
  553. SER_ASSERT_NOT_NULL(p_rx_buf);
  554. SER_ASSERT_NOT_NULL(p_tx_buf);
  555. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  556. uint8_t ant_lib_config;
  557. uint32_t err_code = NRF_SUCCESS;
  558. uint32_t sd_err_code = 0;
  559. err_code = ant_lib_config_clear_req_dec(p_rx_buf, rx_buf_len, &ant_lib_config);
  560. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  561. sd_err_code = sd_ant_lib_config_clear(ant_lib_config);
  562. err_code = ant_lib_config_clear_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  563. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  564. return err_code;
  565. }
  566. uint32_t conn_ant_stack_reset(uint8_t const * const p_rx_buf,
  567. uint32_t rx_buf_len,
  568. uint8_t * const p_tx_buf,
  569. uint32_t * const p_tx_buf_len)
  570. {
  571. SER_ASSERT_NOT_NULL(p_rx_buf);
  572. SER_ASSERT_NOT_NULL(p_tx_buf);
  573. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  574. uint32_t err_code = NRF_SUCCESS;
  575. uint32_t sd_err_code = 0;
  576. sd_err_code = sd_ant_stack_reset();
  577. err_code = ant_stack_reset_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  578. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  579. return err_code;
  580. }
  581. uint32_t conn_ant_rx_scan_mode_start(uint8_t const * const p_rx_buf,
  582. uint32_t rx_buf_len,
  583. uint8_t * const p_tx_buf,
  584. uint32_t * const p_tx_buf_len)
  585. {
  586. SER_ASSERT_NOT_NULL(p_rx_buf);
  587. SER_ASSERT_NOT_NULL(p_tx_buf);
  588. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  589. uint8_t sync_channel_packets_only;
  590. uint32_t err_code = NRF_SUCCESS;
  591. uint32_t sd_err_code = 0;
  592. err_code = ant_rx_scan_mode_start_req_dec(p_rx_buf, rx_buf_len, &sync_channel_packets_only);
  593. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  594. sd_err_code = sd_ant_rx_scan_mode_start(sync_channel_packets_only);
  595. err_code = ant_rx_scan_mode_start_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  596. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  597. return err_code;
  598. }
  599. uint32_t conn_ant_id_list_add(uint8_t const * const p_rx_buf,
  600. uint32_t rx_buf_len,
  601. uint8_t * const p_tx_buf,
  602. uint32_t * const p_tx_buf_len)
  603. {
  604. SER_ASSERT_NOT_NULL(p_rx_buf);
  605. SER_ASSERT_NOT_NULL(p_tx_buf);
  606. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  607. uint8_t channel;
  608. uint8_t dev_id[ANT_ID_SIZE];
  609. uint8_t * p_dev_id = dev_id;
  610. uint8_t list_index;
  611. uint32_t err_code = NRF_SUCCESS;
  612. uint32_t sd_err_code = 0;
  613. err_code = ant_id_list_add_req_dec(p_rx_buf, rx_buf_len, &channel, &p_dev_id, &list_index);
  614. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  615. sd_err_code = sd_ant_id_list_add(channel, p_dev_id, list_index);
  616. err_code = ant_id_list_add_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  617. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  618. return err_code;
  619. }
  620. uint32_t conn_ant_id_list_config(uint8_t const * const p_rx_buf,
  621. uint32_t rx_buf_len,
  622. uint8_t * const p_tx_buf,
  623. uint32_t * const p_tx_buf_len)
  624. {
  625. SER_ASSERT_NOT_NULL(p_rx_buf);
  626. SER_ASSERT_NOT_NULL(p_tx_buf);
  627. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  628. uint8_t channel;
  629. uint8_t id_list_size;
  630. uint8_t inc_exc_flag;
  631. uint32_t err_code = NRF_SUCCESS;
  632. uint32_t sd_err_code = 0;
  633. err_code = ant_id_list_config_req_dec(p_rx_buf, rx_buf_len, &channel, &id_list_size, &inc_exc_flag);
  634. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  635. sd_err_code = sd_ant_id_list_config(channel, id_list_size, inc_exc_flag);
  636. err_code = ant_id_list_config_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  637. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  638. return err_code;
  639. }
  640. uint32_t conn_ant_channel_status_get(uint8_t const * const p_rx_buf,
  641. uint32_t rx_buf_len,
  642. uint8_t * const p_tx_buf,
  643. uint32_t * const p_tx_buf_len)
  644. {
  645. SER_ASSERT_NOT_NULL(p_rx_buf);
  646. SER_ASSERT_NOT_NULL(p_tx_buf);
  647. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  648. uint8_t status;
  649. uint8_t channel;
  650. uint8_t * p_status = &status;
  651. uint32_t err_code = NRF_SUCCESS;
  652. uint32_t sd_err_code = 0;
  653. err_code = ant_channel_status_get_req_dec(p_rx_buf, rx_buf_len, &channel);
  654. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  655. sd_err_code = sd_ant_channel_status_get(channel, p_status);
  656. err_code = ant_channel_status_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, p_status);
  657. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  658. return err_code;
  659. }
  660. uint32_t conn_ant_cw_test_mode_init(uint8_t const * const p_rx_buf,
  661. uint32_t rx_buf_len,
  662. uint8_t * const p_tx_buf,
  663. uint32_t * const p_tx_buf_len)
  664. {
  665. SER_ASSERT_NOT_NULL(p_rx_buf);
  666. SER_ASSERT_NOT_NULL(p_tx_buf);
  667. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  668. uint32_t err_code = NRF_SUCCESS;
  669. uint32_t sd_err_code = 0;
  670. sd_err_code = sd_ant_cw_test_mode_init();
  671. err_code = ant_cw_test_mode_init_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  672. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  673. return err_code;
  674. }
  675. uint32_t conn_ant_cw_test_mode(uint8_t const * const p_rx_buf,
  676. uint32_t rx_buf_len,
  677. uint8_t * const p_tx_buf,
  678. uint32_t * const p_tx_buf_len)
  679. {
  680. SER_ASSERT_NOT_NULL(p_rx_buf);
  681. SER_ASSERT_NOT_NULL(p_tx_buf);
  682. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  683. uint8_t radio_freq;
  684. uint8_t tx_power;
  685. uint8_t custom_tx_power;
  686. uint8_t mode;
  687. uint32_t err_code = NRF_SUCCESS;
  688. uint32_t sd_err_code = 0;
  689. err_code = ant_cw_test_mode_req_dec(p_rx_buf, rx_buf_len, &radio_freq, &tx_power, &custom_tx_power, &mode);
  690. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  691. sd_err_code = sd_ant_cw_test_mode(radio_freq, tx_power, custom_tx_power, mode);
  692. err_code = ant_cw_test_mode_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  693. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  694. return err_code;
  695. }
  696. uint32_t conn_ant_version_get(uint8_t const * const p_rx_buf,
  697. uint32_t rx_buf_len,
  698. uint8_t * const p_tx_buf,
  699. uint32_t * const p_tx_buf_len)
  700. {
  701. SER_ASSERT_NOT_NULL(p_rx_buf);
  702. SER_ASSERT_NOT_NULL(p_tx_buf);
  703. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  704. uint8_t version[MESG_BUFFER_SIZE];
  705. memset(version, 0, sizeof(version));
  706. uint32_t err_code = NRF_SUCCESS;
  707. uint32_t sd_err_code = 0;
  708. sd_err_code = sd_ant_version_get(version);
  709. err_code = ant_version_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, version);
  710. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  711. return err_code;
  712. }
  713. uint32_t conn_ant_capabilities_get(uint8_t const * const p_rx_buf,
  714. uint32_t rx_buf_len,
  715. uint8_t * const p_tx_buf,
  716. uint32_t * const p_tx_buf_len)
  717. {
  718. SER_ASSERT_NOT_NULL(p_rx_buf);
  719. SER_ASSERT_NOT_NULL(p_tx_buf);
  720. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  721. uint8_t capabilities[MESG_CAPABILITIES_SIZE];
  722. memset(capabilities, 0, sizeof(capabilities));
  723. uint32_t err_code = NRF_SUCCESS;
  724. uint32_t sd_err_code = 0;
  725. sd_err_code = sd_ant_capabilities_get(capabilities);
  726. err_code = ant_capabilities_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, capabilities);
  727. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  728. return err_code;
  729. }
  730. uint32_t conn_ant_crypto_channel_enable(uint8_t const * const p_rx_buf,
  731. uint32_t rx_buf_len,
  732. uint8_t * const p_tx_buf,
  733. uint32_t * const p_tx_buf_len)
  734. {
  735. SER_ASSERT_NOT_NULL(p_rx_buf);
  736. SER_ASSERT_NOT_NULL(p_tx_buf);
  737. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  738. uint8_t channel;
  739. uint8_t enable;
  740. uint8_t key_num;
  741. uint8_t decimation_rate;
  742. uint32_t err_code = NRF_SUCCESS;
  743. uint32_t sd_err_code = 0;
  744. err_code = ant_crypto_channel_enable_req_dec(p_rx_buf, rx_buf_len, &channel, &enable, &key_num, &decimation_rate);
  745. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  746. sd_err_code = sd_ant_crypto_channel_enable(channel, enable, key_num, decimation_rate);
  747. err_code = ant_crypto_channel_enable_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  748. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  749. return err_code;
  750. }
  751. uint32_t conn_ant_adv_burst_config_set(uint8_t const * const p_rx_buf,
  752. uint32_t rx_buf_len,
  753. uint8_t * const p_tx_buf,
  754. uint32_t * const p_tx_buf_len)
  755. {
  756. SER_ASSERT_NOT_NULL(p_rx_buf);
  757. SER_ASSERT_NOT_NULL(p_tx_buf);
  758. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  759. uint8_t size;
  760. uint8_t config[ANT_ADV_BURST_CFG_SIZE_MAX];
  761. uint32_t err_code = NRF_SUCCESS;
  762. uint32_t sd_err_code = 0;
  763. err_code = ant_adv_burst_config_set_req_dec(p_rx_buf, rx_buf_len, config, &size);
  764. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  765. sd_err_code = sd_ant_adv_burst_config_set(config, size);
  766. err_code = ant_adv_burst_config_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  767. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  768. return err_code;
  769. }
  770. uint32_t conn_ant_crypto_key_set(uint8_t const * const p_rx_buf,
  771. uint32_t rx_buf_len,
  772. uint8_t * const p_tx_buf,
  773. uint32_t * const p_tx_buf_len)
  774. {
  775. SER_ASSERT_NOT_NULL(p_rx_buf);
  776. SER_ASSERT_NOT_NULL(p_tx_buf);
  777. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  778. uint8_t key_num;
  779. uint8_t key[SIZE_OF_ENCRYPTED_KEY];
  780. uint8_t * p_key = key;
  781. uint32_t err_code = NRF_SUCCESS;
  782. uint32_t sd_err_code = 0;
  783. err_code = ant_crypto_key_set_req_dec(p_rx_buf, rx_buf_len, &key_num, &p_key);
  784. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  785. sd_err_code = sd_ant_crypto_key_set(key_num, p_key);
  786. err_code = ant_crypto_key_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  787. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  788. return err_code;
  789. }
  790. uint32_t conn_ant_crypto_info_set(uint8_t const * const p_rx_buf,
  791. uint32_t rx_buf_len,
  792. uint8_t * const p_tx_buf,
  793. uint32_t * const p_tx_buf_len)
  794. {
  795. SER_ASSERT_NOT_NULL(p_rx_buf);
  796. SER_ASSERT_NOT_NULL(p_tx_buf);
  797. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  798. uint8_t type;
  799. uint8_t info[ANT_CRYPTO_INFO_SIZE];
  800. uint8_t * p_info = info;
  801. uint32_t err_code = NRF_SUCCESS;
  802. uint32_t sd_err_code = 0;
  803. err_code = ant_crypto_info_set_req_dec(p_rx_buf, rx_buf_len, &type, &p_info);
  804. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  805. sd_err_code = sd_ant_crypto_info_set(type, p_info);
  806. err_code = ant_crypto_info_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  807. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  808. return err_code;
  809. }
  810. uint32_t conn_ant_crypto_info_get(uint8_t const * const p_rx_buf,
  811. uint32_t rx_buf_len,
  812. uint8_t * const p_tx_buf,
  813. uint32_t * const p_tx_buf_len)
  814. {
  815. SER_ASSERT_NOT_NULL(p_rx_buf);
  816. SER_ASSERT_NOT_NULL(p_tx_buf);
  817. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  818. uint8_t type;
  819. uint8_t info[ANT_CRYPTO_INFO_MAX_SIZE];
  820. memset(info, 0, sizeof(info));
  821. uint32_t err_code = NRF_SUCCESS;
  822. uint32_t sd_err_code = 0;
  823. err_code = ant_crypto_info_get_req_dec(p_rx_buf, rx_buf_len, &type);
  824. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  825. sd_err_code = sd_ant_crypto_info_get(type, info);
  826. err_code = ant_crypto_info_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, type, info);
  827. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  828. return err_code;
  829. }
  830. uint32_t conn_ant_coex_config_set(uint8_t const * const p_rx_buf,
  831. uint32_t rx_buf_len,
  832. uint8_t * const p_tx_buf,
  833. uint32_t * const p_tx_buf_len)
  834. {
  835. SER_ASSERT_NOT_NULL(p_rx_buf);
  836. SER_ASSERT_NOT_NULL(p_tx_buf);
  837. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  838. uint8_t channel;
  839. uint8_t coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1];
  840. uint8_t adv_coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1];
  841. ANT_BUFFER_PTR coex_config =
  842. {
  843. .ucBufferSize = 0,
  844. .pucBuffer = coex_config_buffer
  845. };
  846. ANT_BUFFER_PTR adv_coex_config =
  847. {
  848. .ucBufferSize = 0,
  849. .pucBuffer = adv_coex_config_buffer
  850. };
  851. uint32_t err_code = NRF_SUCCESS;
  852. uint32_t sd_err_code = 0;
  853. err_code = ant_coex_config_set_req_dec(p_rx_buf, rx_buf_len, &channel, &coex_config, &adv_coex_config);
  854. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  855. if (coex_config.ucBufferSize == 0 && adv_coex_config.ucBufferSize == 0)
  856. {
  857. sd_err_code = sd_ant_coex_config_set(channel, NULL, NULL);
  858. }
  859. else if (coex_config.ucBufferSize == 0)
  860. {
  861. sd_err_code = sd_ant_coex_config_set(channel, NULL, &adv_coex_config);
  862. }
  863. else if (adv_coex_config.ucBufferSize == 0)
  864. {
  865. sd_err_code = sd_ant_coex_config_set(channel, &coex_config, NULL);
  866. }
  867. else
  868. {
  869. sd_err_code = sd_ant_coex_config_set(channel, &coex_config, &adv_coex_config);
  870. }
  871. err_code = ant_coex_config_set_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
  872. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  873. return err_code;
  874. }
  875. uint32_t conn_ant_coex_config_get(uint8_t const * const p_rx_buf,
  876. uint32_t rx_buf_len,
  877. uint8_t * const p_tx_buf,
  878. uint32_t * const p_tx_buf_len)
  879. {
  880. SER_ASSERT_NOT_NULL(p_rx_buf);
  881. SER_ASSERT_NOT_NULL(p_tx_buf);
  882. SER_ASSERT_NOT_NULL(p_tx_buf_len);
  883. uint8_t channel;
  884. uint8_t coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1];
  885. uint8_t adv_coex_config_buffer[(MESG_BUFFER_SIZE / 2) - 1];
  886. ANT_BUFFER_PTR coex_config =
  887. {
  888. .ucBufferSize = sizeof(coex_config_buffer),
  889. .pucBuffer = coex_config_buffer
  890. };
  891. ANT_BUFFER_PTR adv_coex_config =
  892. {
  893. .ucBufferSize = sizeof(adv_coex_config_buffer),
  894. .pucBuffer = adv_coex_config_buffer
  895. };
  896. uint32_t err_code = NRF_SUCCESS;
  897. uint32_t sd_err_code = 0;
  898. err_code = ant_coex_config_get_req_dec(p_rx_buf, rx_buf_len, &channel);
  899. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  900. sd_err_code = sd_ant_coex_config_get(channel, &coex_config, &adv_coex_config);
  901. err_code = ant_coex_config_get_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len, &coex_config, &adv_coex_config);
  902. SER_ASSERT(err_code == NRF_SUCCESS, err_code);
  903. return err_code;
  904. }