hidh_conn.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2002-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * This file contains HID HOST internal definitions
  21. *
  22. ******************************************************************************/
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include "common/bt_target.h"
  27. #include "osi/allocator.h"
  28. #include "stack/bt_types.h"
  29. #include "stack/l2cdefs.h"
  30. #include "stack/l2c_api.h"
  31. #include "stack/btu.h"
  32. #include "stack/btm_api.h"
  33. #include "btm_int.h"
  34. #include "stack/hiddefs.h"
  35. #include "stack/hidh_api.h"
  36. #include "hid_int.h"
  37. #include "osi/osi.h"
  38. #if (HID_HOST_INCLUDED == TRUE)
  39. static UINT8 find_conn_by_cid (UINT16 cid);
  40. static void hidh_conn_retry (UINT8 dhandle);
  41. /********************************************************************************/
  42. /* L O C A L F U N C T I O N P R O T O T Y P E S */
  43. /********************************************************************************/
  44. static void hidh_l2cif_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid,
  45. UINT16 psm, UINT8 l2cap_id);
  46. static void hidh_l2cif_connect_cfm (UINT16 l2cap_cid, UINT16 result);
  47. static void hidh_l2cif_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg);
  48. static void hidh_l2cif_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg);
  49. static void hidh_l2cif_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed);
  50. static void hidh_l2cif_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg);
  51. static void hidh_l2cif_disconnect_cfm (UINT16 l2cap_cid, UINT16 result);
  52. static void hidh_l2cif_cong_ind (UINT16 l2cap_cid, BOOLEAN congested);
  53. static const tL2CAP_APPL_INFO hst_reg_info = {
  54. hidh_l2cif_connect_ind,
  55. hidh_l2cif_connect_cfm,
  56. NULL,
  57. hidh_l2cif_config_ind,
  58. hidh_l2cif_config_cfm,
  59. hidh_l2cif_disconnect_ind,
  60. hidh_l2cif_disconnect_cfm,
  61. NULL,
  62. hidh_l2cif_data_ind,
  63. hidh_l2cif_cong_ind,
  64. NULL /* tL2CA_TX_COMPLETE_CB */
  65. };
  66. /*******************************************************************************
  67. **
  68. ** Function hidh_l2cif_reg
  69. **
  70. ** Description This function initializes the SDP unit.
  71. **
  72. ** Returns void
  73. **
  74. *******************************************************************************/
  75. tHID_STATUS hidh_conn_reg (void)
  76. {
  77. int xx;
  78. /* Initialize the L2CAP configuration. We only care about MTU and flush */
  79. memset(&hh_cb.l2cap_cfg, 0, sizeof(tL2CAP_CFG_INFO));
  80. hh_cb.l2cap_cfg.mtu_present = TRUE;
  81. hh_cb.l2cap_cfg.mtu = HID_HOST_MTU;
  82. hh_cb.l2cap_cfg.flush_to_present = TRUE;
  83. hh_cb.l2cap_cfg.flush_to = HID_HOST_FLUSH_TO;
  84. /* Now, register with L2CAP */
  85. if (!L2CA_Register (HID_PSM_CONTROL, (tL2CAP_APPL_INFO *) &hst_reg_info)) {
  86. HIDH_TRACE_ERROR ("HID-Host Control Registration failed");
  87. return (HID_ERR_L2CAP_FAILED) ;
  88. }
  89. if (!L2CA_Register (HID_PSM_INTERRUPT, (tL2CAP_APPL_INFO *) &hst_reg_info)) {
  90. L2CA_Deregister( HID_PSM_CONTROL ) ;
  91. HIDH_TRACE_ERROR ("HID-Host Interrupt Registration failed");
  92. return (HID_ERR_L2CAP_FAILED) ;
  93. }
  94. for (xx = 0; xx < HID_HOST_MAX_DEVICES; xx++) {
  95. hh_cb.devices[xx].in_use = FALSE ;
  96. hh_cb.devices[xx].delay_remove = FALSE;
  97. hh_cb.devices[xx].conn.conn_state = HID_CONN_STATE_UNUSED;
  98. }
  99. return (HID_SUCCESS);
  100. }
  101. /*******************************************************************************
  102. **
  103. ** Function hidh_conn_disconnect
  104. **
  105. ** Description This function disconnects a connection.
  106. **
  107. ** Returns TRUE if disconnect started, FALSE if already disconnected
  108. **
  109. *******************************************************************************/
  110. tHID_STATUS hidh_conn_disconnect (UINT8 dhandle)
  111. {
  112. tHID_CONN *p_hcon = &hh_cb.devices[dhandle].conn;
  113. HIDH_TRACE_EVENT ("HID-Host disconnect");
  114. if ((p_hcon->ctrl_cid != 0) || (p_hcon->intr_cid != 0)) {
  115. /* Set l2cap idle timeout to 0 (so ACL link is disconnected
  116. * immediately after last channel is closed) */
  117. L2CA_SetIdleTimeoutByBdAddr(hh_cb.devices[dhandle].addr, 0, BT_TRANSPORT_BR_EDR);
  118. /* Disconnect both interrupt and control channels */
  119. if (p_hcon->intr_cid) {
  120. p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING_INTR;
  121. L2CA_DisconnectReq (p_hcon->intr_cid);
  122. } else if (p_hcon->ctrl_cid) {
  123. p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING_CTRL;
  124. L2CA_DisconnectReq (p_hcon->ctrl_cid);
  125. }
  126. } else {
  127. p_hcon->conn_state = HID_CONN_STATE_UNUSED;
  128. }
  129. return (HID_SUCCESS);
  130. }
  131. /*******************************************************************************
  132. **
  133. ** Function hidh_sec_check_complete_term
  134. **
  135. ** Description HID security check complete callback function.
  136. **
  137. ** Returns Send L2CA_ConnectRsp OK if secutiry check succeed; otherwise
  138. ** send security block L2C connection response.
  139. **
  140. *******************************************************************************/
  141. void hidh_sec_check_complete_term (BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_data, UINT8 res)
  142. {
  143. tHID_HOST_DEV_CTB *p_dev = (tHID_HOST_DEV_CTB *) p_ref_data;
  144. UNUSED(bd_addr);
  145. UNUSED (transport);
  146. if ( res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) {
  147. p_dev->conn.disc_reason = HID_SUCCESS; /* Authentication passed. Reset disc_reason (from HID_ERR_AUTH_FAILED) */
  148. p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_INTR;
  149. /* Send response to the L2CAP layer. */
  150. L2CA_ConnectRsp (p_dev->addr, p_dev->conn.ctrl_id, p_dev->conn.ctrl_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
  151. /* Send a Configuration Request. */
  152. L2CA_ConfigReq (p_dev->conn.ctrl_cid, &hh_cb.l2cap_cfg);
  153. }
  154. /* security check fail */
  155. else if (res != BTM_SUCCESS) {
  156. p_dev->conn.disc_reason = HID_ERR_AUTH_FAILED; /* Save reason for disconnecting */
  157. p_dev->conn.conn_state = HID_CONN_STATE_UNUSED;
  158. L2CA_ConnectRsp (p_dev->addr, p_dev->conn.ctrl_id, p_dev->conn.ctrl_cid, L2CAP_CONN_SECURITY_BLOCK, L2CAP_CONN_OK);
  159. }
  160. }
  161. /*******************************************************************************
  162. **
  163. ** Function hidh_l2cif_connect_ind
  164. **
  165. ** Description This function handles an inbound connection indication
  166. ** from L2CAP. This is the case where we are acting as a
  167. ** server.
  168. **
  169. ** Returns void
  170. **
  171. *******************************************************************************/
  172. static void hidh_l2cif_connect_ind (BD_ADDR bd_addr, UINT16 l2cap_cid, UINT16 psm, UINT8 l2cap_id)
  173. {
  174. tHID_CONN *p_hcon;
  175. BOOLEAN bAccept = TRUE;
  176. UINT8 i = HID_HOST_MAX_DEVICES;
  177. tHID_HOST_DEV_CTB *p_dev;
  178. HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP conn ind, PSM: 0x%04x CID 0x%x", psm, l2cap_cid);
  179. /* always add incoming connection device into HID database by default */
  180. if (HID_HostAddDev(bd_addr, HID_SEC_REQUIRED, &i) != HID_SUCCESS) {
  181. L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_SECURITY_BLOCK, 0);
  182. return;
  183. }
  184. p_hcon = &hh_cb.devices[i].conn;
  185. p_dev = &hh_cb.devices[i];
  186. /* Check we are in the correct state for this */
  187. if (psm == HID_PSM_INTERRUPT) {
  188. if (p_hcon->ctrl_cid == 0) {
  189. HIDH_TRACE_WARNING ("HID-Host Rcvd INTR L2CAP conn ind, but no CTL channel");
  190. bAccept = FALSE;
  191. }
  192. if (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR) {
  193. HIDH_TRACE_WARNING ("HID-Host Rcvd INTR L2CAP conn ind, wrong state: %d",
  194. p_hcon->conn_state);
  195. bAccept = FALSE;
  196. }
  197. } else { /* CTRL channel */
  198. #if defined(HID_HOST_ACPT_NEW_CONN) && (HID_HOST_ACPT_NEW_CONN == TRUE)
  199. p_hcon->ctrl_cid = p_hcon->intr_cid = 0;
  200. p_hcon->conn_state = HID_CONN_STATE_UNUSED;
  201. #else
  202. if (p_hcon->conn_state != HID_CONN_STATE_UNUSED) {
  203. HIDH_TRACE_WARNING ("HID-Host - Rcvd CTL L2CAP conn ind, wrong state: %d",
  204. p_hcon->conn_state);
  205. bAccept = FALSE;
  206. }
  207. #endif
  208. }
  209. if (!bAccept) {
  210. L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_RESOURCES, 0);
  211. return;
  212. }
  213. if (psm == HID_PSM_CONTROL) {
  214. p_hcon->conn_flags = 0;
  215. p_hcon->ctrl_cid = l2cap_cid;
  216. p_hcon->ctrl_id = l2cap_id;
  217. p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* In case disconnection occurs before security is completed, then set CLOSE_EVT reason code to 'connection failure' */
  218. p_hcon->conn_state = HID_CONN_STATE_SECURITY;
  219. if (btm_sec_mx_access_request (p_dev->addr, HID_PSM_CONTROL,
  220. FALSE, BTM_SEC_PROTO_HID,
  221. (p_dev->attr_mask & HID_SEC_REQUIRED) ? HID_SEC_CHN : HID_NOSEC_CHN,
  222. &hidh_sec_check_complete_term, p_dev) == BTM_CMD_STARTED) {
  223. L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_PENDING, L2CAP_CONN_OK);
  224. }
  225. return;
  226. }
  227. /* Transition to the next appropriate state, configuration */
  228. p_hcon->conn_state = HID_CONN_STATE_CONFIG;
  229. p_hcon->intr_cid = l2cap_cid;
  230. /* Send response to the L2CAP layer. */
  231. L2CA_ConnectRsp (bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);
  232. /* Send a Configuration Request. */
  233. L2CA_ConfigReq (l2cap_cid, &hh_cb.l2cap_cfg);
  234. HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP conn ind, sent config req, PSM: 0x%04x CID 0x%x",
  235. psm, l2cap_cid);
  236. }
  237. /*******************************************************************************
  238. **
  239. ** Function hidh_proc_repage_timeout
  240. **
  241. ** Description This function handles timeout (to page device).
  242. **
  243. ** Returns void
  244. **
  245. *******************************************************************************/
  246. void hidh_proc_repage_timeout (TIMER_LIST_ENT *p_tle)
  247. {
  248. hidh_conn_initiate( (UINT8) p_tle->param ) ;
  249. hh_cb.devices[p_tle->param].conn_tries++;
  250. hh_cb.callback( (UINT8) p_tle->param, hh_cb.devices[p_tle->param].addr,
  251. HID_HDEV_EVT_RETRYING, hh_cb.devices[p_tle->param].conn_tries, NULL ) ;
  252. }
  253. /*******************************************************************************
  254. **
  255. ** Function hidh_sec_check_complete_orig
  256. **
  257. ** Description This function checks to see if security procedures are being
  258. ** carried out or not..
  259. **
  260. ** Returns void
  261. **
  262. *******************************************************************************/
  263. void hidh_sec_check_complete_orig (BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_data, UINT8 res)
  264. {
  265. tHID_HOST_DEV_CTB *p_dev = (tHID_HOST_DEV_CTB *) p_ref_data;
  266. UINT8 dhandle;
  267. UNUSED(bd_addr);
  268. UNUSED (transport);
  269. dhandle = ((UINT32)p_dev - (UINT32) & (hh_cb.devices[0])) / sizeof(tHID_HOST_DEV_CTB);
  270. if ( res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) {
  271. HIDH_TRACE_EVENT ("HID-Host Originator security pass.");
  272. p_dev->conn.disc_reason = HID_SUCCESS; /* Authentication passed. Reset disc_reason (from HID_ERR_AUTH_FAILED) */
  273. /* Transition to the next appropriate state, configuration */
  274. p_dev->conn.conn_state = HID_CONN_STATE_CONFIG;
  275. L2CA_ConfigReq (p_dev->conn.ctrl_cid, &hh_cb.l2cap_cfg);
  276. HIDH_TRACE_EVENT ("HID-Host Got Control conn cnf, sent cfg req, CID: 0x%x", p_dev->conn.ctrl_cid);
  277. }
  278. if ( res != BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY ) {
  279. #if (HID_HOST_MAX_CONN_RETRY > 0)
  280. if ( res == BTM_DEVICE_TIMEOUT ) {
  281. if ( p_dev->conn_tries <= HID_HOST_MAX_CONN_RETRY ) {
  282. hidh_conn_retry (dhandle);
  283. return;
  284. }
  285. }
  286. #endif
  287. p_dev->conn.disc_reason = HID_ERR_AUTH_FAILED; /* Save reason for disconnecting */
  288. hidh_conn_disconnect(dhandle);
  289. }
  290. }
  291. /*******************************************************************************
  292. **
  293. ** Function hidh_l2cif_connect_cfm
  294. **
  295. ** Description This function handles the connect confirm events
  296. ** from L2CAP. This is the case when we are acting as a
  297. ** client and have sent a connect request.
  298. **
  299. ** Returns void
  300. **
  301. *******************************************************************************/
  302. static void hidh_l2cif_connect_cfm (UINT16 l2cap_cid, UINT16 result)
  303. {
  304. UINT8 dhandle;
  305. tHID_CONN *p_hcon = NULL;
  306. UINT32 reason;
  307. tHID_HOST_DEV_CTB *p_dev = NULL;
  308. /* Find CCB based on CID, and verify we are in a state to accept this message */
  309. if ( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES ) {
  310. p_dev = &hh_cb.devices[dhandle];
  311. p_hcon = &hh_cb.devices[dhandle].conn;
  312. }
  313. if ((p_hcon == NULL) || (!(p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG)) ||
  314. ((l2cap_cid == p_hcon->ctrl_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_CTRL) &&
  315. (p_hcon->conn_state != HID_CONN_STATE_DISCONNECTING_INTR)) ||
  316. ((l2cap_cid == p_hcon->intr_cid) && (p_hcon->conn_state != HID_CONN_STATE_CONNECTING_INTR) &&
  317. (p_hcon->conn_state != HID_CONN_STATE_DISCONNECTING_CTRL))) {
  318. HIDH_TRACE_WARNING("HID-Host Rcvd unexpected conn cnf, CID 0x%x ", l2cap_cid);
  319. return;
  320. }
  321. if (result != L2CAP_CONN_OK) {
  322. if (l2cap_cid == p_hcon->ctrl_cid) {
  323. p_hcon->ctrl_cid = 0;
  324. } else {
  325. p_hcon->intr_cid = 0;
  326. }
  327. hidh_conn_disconnect(dhandle);
  328. #if (HID_HOST_MAX_CONN_RETRY > 0)
  329. if ( (hh_cb.devices[dhandle].conn_tries <= HID_HOST_MAX_CONN_RETRY) &&
  330. (result == HCI_ERR_CONNECTION_TOUT || result == HCI_ERR_UNSPECIFIED ||
  331. result == HCI_ERR_PAGE_TIMEOUT) ) {
  332. hidh_conn_retry(dhandle);
  333. } else
  334. #endif
  335. {
  336. reason = HID_L2CAP_CONN_FAIL | (UINT32) result ;
  337. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
  338. }
  339. return;
  340. }
  341. /* receive Control Channel connect confirmation */
  342. if (l2cap_cid == p_hcon->ctrl_cid) {
  343. /* check security requirement */
  344. p_hcon->conn_state = HID_CONN_STATE_SECURITY;
  345. p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* In case disconnection occurs before security is completed, then set CLOSE_EVT reason code to "connection failure" */
  346. btm_sec_mx_access_request (p_dev->addr, HID_PSM_CONTROL,
  347. TRUE, BTM_SEC_PROTO_HID,
  348. (p_dev->attr_mask & HID_SEC_REQUIRED) ? HID_SEC_CHN : HID_NOSEC_CHN,
  349. &hidh_sec_check_complete_orig, p_dev);
  350. } else {
  351. p_hcon->conn_state = HID_CONN_STATE_CONFIG;
  352. /* Send a Configuration Request. */
  353. L2CA_ConfigReq (l2cap_cid, &hh_cb.l2cap_cfg);
  354. HIDH_TRACE_EVENT ("HID-Host got Interrupt conn cnf, sent cfg req, CID: 0x%x", l2cap_cid);
  355. }
  356. return;
  357. }
  358. /*******************************************************************************
  359. **
  360. ** Function hidh_l2cif_config_ind
  361. **
  362. ** Description This function processes the L2CAP configuration indication
  363. ** event.
  364. **
  365. ** Returns void
  366. **
  367. *******************************************************************************/
  368. static void hidh_l2cif_config_ind (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
  369. {
  370. UINT8 dhandle;
  371. tHID_CONN *p_hcon = NULL;
  372. UINT32 reason;
  373. /* Find CCB based on CID */
  374. if ( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES ) {
  375. p_hcon = &hh_cb.devices[dhandle].conn;
  376. }
  377. if (p_hcon == NULL) {
  378. HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
  379. return;
  380. }
  381. HIDH_TRACE_EVENT ("HID-Host Rcvd cfg ind, sent cfg cfm, CID: 0x%x", l2cap_cid);
  382. /* Remember the remote MTU size */
  383. if ((!p_cfg->mtu_present) || (p_cfg->mtu > HID_HOST_MTU)) {
  384. p_hcon->rem_mtu_size = HID_HOST_MTU;
  385. } else {
  386. p_hcon->rem_mtu_size = p_cfg->mtu;
  387. }
  388. /* For now, always accept configuration from the other side */
  389. p_cfg->flush_to_present = FALSE;
  390. p_cfg->mtu_present = FALSE;
  391. p_cfg->result = L2CAP_CFG_OK;
  392. L2CA_ConfigRsp (l2cap_cid, p_cfg);
  393. if (l2cap_cid == p_hcon->ctrl_cid) {
  394. p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_CTRL_CFG_DONE;
  395. if ((p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG) &&
  396. (p_hcon->conn_flags & HID_CONN_FLAGS_MY_CTRL_CFG_DONE)) {
  397. /* Connect interrupt channel */
  398. p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* Reset initial reason for CLOSE_EVT: Connection Attempt was made but failed */
  399. if ((p_hcon->intr_cid = L2CA_ConnectReq (HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr)) == 0) {
  400. HIDH_TRACE_WARNING ("HID-Host INTR Originate failed");
  401. reason = HID_L2CAP_REQ_FAIL ;
  402. p_hcon->conn_state = HID_CONN_STATE_UNUSED;
  403. hidh_conn_disconnect (dhandle);
  404. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
  405. return;
  406. } else {
  407. /* Transition to the next appropriate state, waiting for connection confirm on interrupt channel. */
  408. p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
  409. }
  410. }
  411. } else {
  412. p_hcon->conn_flags |= HID_CONN_FLAGS_HIS_INTR_CFG_DONE;
  413. }
  414. /* If all configuration is complete, change state and tell management we are up */
  415. if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED)
  416. && (p_hcon->conn_state == HID_CONN_STATE_CONFIG)) {
  417. p_hcon->conn_state = HID_CONN_STATE_CONNECTED;
  418. /* Reset disconnect reason to success, as connection successful */
  419. p_hcon->disc_reason = HID_SUCCESS;
  420. hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
  421. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ;
  422. }
  423. }
  424. /*******************************************************************************
  425. **
  426. ** Function hidh_l2cif_config_cfm
  427. **
  428. ** Description This function processes the L2CAP configuration confirmation
  429. ** event.
  430. **
  431. ** Returns void
  432. **
  433. *******************************************************************************/
  434. static void hidh_l2cif_config_cfm (UINT16 l2cap_cid, tL2CAP_CFG_INFO *p_cfg)
  435. {
  436. UINT8 dhandle;
  437. tHID_CONN *p_hcon = NULL;
  438. UINT32 reason;
  439. HIDH_TRACE_EVENT ("HID-Host Rcvd cfg cfm, CID: 0x%x Result: %d", l2cap_cid, p_cfg->result);
  440. /* Find CCB based on CID */
  441. if ( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES ) {
  442. p_hcon = &hh_cb.devices[dhandle].conn;
  443. }
  444. if (p_hcon == NULL) {
  445. HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
  446. return;
  447. }
  448. /* If configuration failed, disconnect the channel(s) */
  449. if (p_cfg->result != L2CAP_CFG_OK) {
  450. hidh_conn_disconnect (dhandle);
  451. reason = HID_L2CAP_CFG_FAIL | (UINT32) p_cfg->result ;
  452. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
  453. return;
  454. }
  455. if (l2cap_cid == p_hcon->ctrl_cid) {
  456. p_hcon->conn_flags |= HID_CONN_FLAGS_MY_CTRL_CFG_DONE;
  457. if ((p_hcon->conn_flags & HID_CONN_FLAGS_IS_ORIG) &&
  458. (p_hcon->conn_flags & HID_CONN_FLAGS_HIS_CTRL_CFG_DONE)) {
  459. /* Connect interrupt channel */
  460. p_hcon->disc_reason = HID_L2CAP_CONN_FAIL; /* Reset initial reason for CLOSE_EVT: Connection Attempt was made but failed */
  461. if ((p_hcon->intr_cid = L2CA_ConnectReq (HID_PSM_INTERRUPT, hh_cb.devices[dhandle].addr)) == 0) {
  462. HIDH_TRACE_WARNING ("HID-Host INTR Originate failed");
  463. reason = HID_L2CAP_REQ_FAIL ;
  464. p_hcon->conn_state = HID_CONN_STATE_UNUSED;
  465. hidh_conn_disconnect (dhandle);
  466. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, reason, NULL ) ;
  467. return;
  468. } else {
  469. /* Transition to the next appropriate state, waiting for connection confirm on interrupt channel. */
  470. p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
  471. }
  472. }
  473. } else {
  474. p_hcon->conn_flags |= HID_CONN_FLAGS_MY_INTR_CFG_DONE;
  475. }
  476. /* If all configuration is complete, change state and tell management we are up */
  477. if (((p_hcon->conn_flags & HID_CONN_FLAGS_ALL_CONFIGURED) == HID_CONN_FLAGS_ALL_CONFIGURED)
  478. && (p_hcon->conn_state == HID_CONN_STATE_CONFIG)) {
  479. p_hcon->conn_state = HID_CONN_STATE_CONNECTED;
  480. /* Reset disconnect reason to success, as connection successful */
  481. p_hcon->disc_reason = HID_SUCCESS;
  482. hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
  483. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ;
  484. }
  485. }
  486. /*******************************************************************************
  487. **
  488. ** Function hidh_l2cif_disconnect_ind
  489. **
  490. ** Description This function handles a disconnect event from L2CAP. If
  491. ** requested to, we ack the disconnect before dropping the CCB
  492. **
  493. ** Returns void
  494. **
  495. *******************************************************************************/
  496. static void hidh_l2cif_disconnect_ind (UINT16 l2cap_cid, BOOLEAN ack_needed)
  497. {
  498. UINT8 dhandle;
  499. tHID_CONN *p_hcon = NULL;
  500. UINT16 disc_res = HCI_SUCCESS;
  501. UINT16 hid_close_evt_reason;
  502. /* Find CCB based on CID */
  503. if ( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES ) {
  504. p_hcon = &hh_cb.devices[dhandle].conn;
  505. }
  506. if (p_hcon == NULL) {
  507. HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid);
  508. return;
  509. }
  510. if (ack_needed) {
  511. L2CA_DisconnectRsp (l2cap_cid);
  512. }
  513. HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);
  514. if (l2cap_cid == p_hcon->ctrl_cid) {
  515. p_hcon->ctrl_cid = 0;
  516. p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING_CTRL;
  517. } else {
  518. p_hcon->intr_cid = 0;
  519. p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING_INTR;
  520. }
  521. if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) {
  522. hh_cb.devices[dhandle].state = HID_DEV_NO_CONN;
  523. p_hcon->conn_state = HID_CONN_STATE_UNUSED;
  524. if ( !ack_needed ) {
  525. disc_res = btm_get_acl_disc_reason_code();
  526. }
  527. #if (HID_HOST_MAX_CONN_RETRY > 0)
  528. if ( (disc_res == HCI_ERR_CONNECTION_TOUT || disc_res == HCI_ERR_UNSPECIFIED) &&
  529. (!(hh_cb.devices[dhandle].attr_mask & HID_RECONN_INIT)) &&
  530. (hh_cb.devices[dhandle].attr_mask & HID_NORMALLY_CONNECTABLE)) {
  531. hh_cb.devices[dhandle].conn_tries = 0;
  532. hh_cb.devices[dhandle].conn.timer_entry.param = (UINT32) dhandle;
  533. btu_start_timer (&(hh_cb.devices[dhandle].conn.timer_entry), BTU_TTYPE_HID_HOST_REPAGE_TO, HID_HOST_REPAGE_WIN);
  534. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, disc_res, NULL);
  535. } else
  536. #endif
  537. {
  538. /* Set reason code for HID_HDEV_EVT_CLOSE */
  539. hid_close_evt_reason = p_hcon->disc_reason;
  540. /* If we got baseband sent HCI_DISCONNECT_COMPLETE_EVT due to security failure, then set reason to HID_ERR_AUTH_FAILED */
  541. if ((disc_res == HCI_ERR_AUTH_FAILURE) ||
  542. (disc_res == HCI_ERR_KEY_MISSING) ||
  543. (disc_res == HCI_ERR_HOST_REJECT_SECURITY) ||
  544. (disc_res == HCI_ERR_PAIRING_NOT_ALLOWED) ||
  545. (disc_res == HCI_ERR_UNIT_KEY_USED) ||
  546. (disc_res == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) ||
  547. (disc_res == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) ||
  548. (disc_res == HCI_ERR_REPEATED_ATTEMPTS)) {
  549. hid_close_evt_reason = HID_ERR_AUTH_FAILED;
  550. }
  551. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, hid_close_evt_reason, NULL ) ;
  552. }
  553. }
  554. }
  555. /*******************************************************************************
  556. **
  557. ** Function hidh_l2cif_disconnect_cfm
  558. **
  559. ** Description This function handles a disconnect confirm event from L2CAP.
  560. **
  561. ** Returns void
  562. **
  563. *******************************************************************************/
  564. static void hidh_l2cif_disconnect_cfm (UINT16 l2cap_cid, UINT16 result)
  565. {
  566. UINT8 dhandle;
  567. tHID_CONN *p_hcon = NULL;
  568. UNUSED(result);
  569. /* Find CCB based on CID */
  570. if ( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES ) {
  571. p_hcon = &hh_cb.devices[dhandle].conn;
  572. }
  573. if (p_hcon == NULL) {
  574. HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP disc cfm, unknown CID: 0x%x", l2cap_cid);
  575. return;
  576. }
  577. HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid);
  578. if (l2cap_cid == p_hcon->ctrl_cid) {
  579. p_hcon->ctrl_cid = 0;
  580. } else {
  581. p_hcon->intr_cid = 0;
  582. if (p_hcon->ctrl_cid) {
  583. HIDH_TRACE_EVENT ("HID-Host Initiating L2CAP Ctrl disconnection");
  584. L2CA_DisconnectReq (p_hcon->ctrl_cid);
  585. }
  586. }
  587. if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) {
  588. hh_cb.devices[dhandle].state = HID_DEV_NO_CONN;
  589. p_hcon->conn_state = HID_CONN_STATE_UNUSED;
  590. // removes the device from list devices that host has to manage
  591. if (hh_cb.devices[dhandle].delay_remove) {
  592. hh_cb.devices[dhandle].in_use = FALSE;
  593. hh_cb.devices[dhandle].delay_remove = FALSE;
  594. hh_cb.devices[dhandle].attr_mask = 0;
  595. }
  596. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, p_hcon->disc_reason, NULL ) ;
  597. }
  598. }
  599. /*******************************************************************************
  600. **
  601. ** Function hidh_l2cif_cong_ind
  602. **
  603. ** Description This function handles a congestion status event from L2CAP.
  604. **
  605. ** Returns void
  606. **
  607. *******************************************************************************/
  608. static void hidh_l2cif_cong_ind (UINT16 l2cap_cid, BOOLEAN congested)
  609. {
  610. UINT8 dhandle;
  611. tHID_CONN *p_hcon = NULL;
  612. /* Find CCB based on CID */
  613. if ( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES ) {
  614. p_hcon = &hh_cb.devices[dhandle].conn;
  615. }
  616. if (p_hcon == NULL) {
  617. HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP congestion status, unknown CID: 0x%x", l2cap_cid);
  618. return;
  619. }
  620. HIDH_TRACE_EVENT ("HID-Host Rcvd L2CAP congestion status, CID: 0x%x Cong: %d", l2cap_cid, congested);
  621. if (congested) {
  622. p_hcon->conn_flags |= HID_CONN_FLAGS_CONGESTED;
  623. } else {
  624. p_hcon->conn_flags &= ~HID_CONN_FLAGS_CONGESTED;
  625. }
  626. }
  627. /*******************************************************************************
  628. **
  629. ** Function hidh_l2cif_data_ind
  630. **
  631. ** Description This function is called when data is received from L2CAP.
  632. ** if we are the originator of the connection, we are the SDP
  633. ** client, and the received message is queued up for the client.
  634. **
  635. ** If we are the destination of the connection, we are the SDP
  636. ** server, so the message is passed to the server processing
  637. ** function.
  638. **
  639. ** Returns void
  640. **
  641. *******************************************************************************/
  642. static void hidh_l2cif_data_ind (UINT16 l2cap_cid, BT_HDR *p_msg)
  643. {
  644. UINT8 *p_data = (UINT8 *)(p_msg + 1) + p_msg->offset;
  645. UINT8 ttype, param, rep_type, evt;
  646. UINT8 dhandle;
  647. tHID_CONN *p_hcon = NULL;
  648. HIDH_TRACE_DEBUG ("HID-Host hidh_l2cif_data_ind [l2cap_cid=0x%04x]", l2cap_cid);
  649. /* Find CCB based on CID */
  650. if ((dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES) {
  651. p_hcon = &hh_cb.devices[dhandle].conn;
  652. }
  653. if (p_hcon == NULL) {
  654. HIDH_TRACE_WARNING ("HID-Host Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid);
  655. osi_free (p_msg);
  656. return;
  657. }
  658. ttype = HID_GET_TRANS_FROM_HDR(*p_data);
  659. param = HID_GET_PARAM_FROM_HDR(*p_data);
  660. rep_type = param & HID_PAR_REP_TYPE_MASK;
  661. p_data++;
  662. /* Get rid of the data type */
  663. p_msg->len--;
  664. p_msg->offset++;
  665. switch (ttype) {
  666. case HID_TRANS_HANDSHAKE:
  667. hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_HANDSHAKE, param, NULL);
  668. osi_free (p_msg);
  669. break;
  670. case HID_TRANS_CONTROL:
  671. switch (param) {
  672. case HID_PAR_CONTROL_VIRTUAL_CABLE_UNPLUG:
  673. hidh_conn_disconnect( dhandle ) ;
  674. /* Device is unplugging from us. Tell USB */
  675. hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_VC_UNPLUG, 0, NULL);
  676. break;
  677. default:
  678. break;
  679. }
  680. osi_free (p_msg);
  681. break;
  682. case HID_TRANS_DATA:
  683. evt = (hh_cb.devices[dhandle].conn.intr_cid == l2cap_cid) ?
  684. HID_HDEV_EVT_INTR_DATA : HID_HDEV_EVT_CTRL_DATA;
  685. hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, evt, rep_type, p_msg);
  686. break;
  687. case HID_TRANS_DATAC:
  688. evt = (hh_cb.devices[dhandle].conn.intr_cid == l2cap_cid) ?
  689. HID_HDEV_EVT_INTR_DATC : HID_HDEV_EVT_CTRL_DATC;
  690. hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, evt, rep_type, p_msg);
  691. break;
  692. default:
  693. osi_free (p_msg);
  694. break;
  695. }
  696. }
  697. /*******************************************************************************
  698. **
  699. ** Function hidh_conn_snd_data
  700. **
  701. ** Description This function is sends out data.
  702. **
  703. ** Returns tHID_STATUS
  704. **
  705. *******************************************************************************/
  706. tHID_STATUS hidh_conn_snd_data (UINT8 dhandle, UINT8 trans_type, UINT8 param,
  707. UINT16 data, UINT8 report_id, BT_HDR *buf)
  708. {
  709. tHID_CONN *p_hcon = &hh_cb.devices[dhandle].conn;
  710. BT_HDR *p_buf;
  711. UINT8 *p_out;
  712. UINT16 bytes_copied;
  713. BOOLEAN seg_req = FALSE;
  714. UINT16 data_size;
  715. UINT16 cid;
  716. UINT16 buf_size;
  717. UINT8 use_data = 0 ;
  718. BOOLEAN blank_datc = FALSE;
  719. if (!BTM_IsAclConnectionUp(hh_cb.devices[dhandle].addr, BT_TRANSPORT_BR_EDR)) {
  720. if (buf) {
  721. osi_free ((void *)buf);
  722. }
  723. return ( HID_ERR_NO_CONNECTION );
  724. }
  725. if (p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) {
  726. if (buf) {
  727. osi_free ((void *)buf);
  728. }
  729. return ( HID_ERR_CONGESTED );
  730. }
  731. switch ( trans_type ) {
  732. case HID_TRANS_CONTROL:
  733. case HID_TRANS_GET_REPORT:
  734. case HID_TRANS_SET_REPORT:
  735. case HID_TRANS_GET_PROTOCOL:
  736. case HID_TRANS_SET_PROTOCOL:
  737. case HID_TRANS_GET_IDLE:
  738. case HID_TRANS_SET_IDLE:
  739. cid = p_hcon->ctrl_cid;
  740. buf_size = HID_CONTROL_BUF_SIZE;
  741. break;
  742. case HID_TRANS_DATA:
  743. cid = p_hcon->intr_cid;
  744. buf_size = HID_INTERRUPT_BUF_SIZE;
  745. break;
  746. default:
  747. return (HID_ERR_INVALID_PARAM) ;
  748. }
  749. if ( trans_type == HID_TRANS_SET_IDLE ) {
  750. use_data = 1;
  751. } else if ( (trans_type == HID_TRANS_GET_REPORT) && (param & 0x08) ) {
  752. use_data = 2;
  753. }
  754. do {
  755. if ( buf == NULL || blank_datc ) {
  756. if ((p_buf = (BT_HDR *)osi_malloc(buf_size)) == NULL) {
  757. return (HID_ERR_NO_RESOURCES);
  758. }
  759. p_buf->offset = L2CAP_MIN_OFFSET;
  760. seg_req = FALSE;
  761. data_size = 0;
  762. bytes_copied = 0;
  763. blank_datc = FALSE;
  764. } else if ( (buf->len > (p_hcon->rem_mtu_size - 1))) {
  765. if ((p_buf = (BT_HDR *)osi_malloc(buf_size)) == NULL) {
  766. return (HID_ERR_NO_RESOURCES);
  767. }
  768. p_buf->offset = L2CAP_MIN_OFFSET;
  769. seg_req = TRUE;
  770. data_size = buf->len;
  771. bytes_copied = p_hcon->rem_mtu_size - 1;
  772. } else {
  773. p_buf = buf ;
  774. p_buf->offset -= 1;
  775. seg_req = FALSE;
  776. data_size = buf->len;
  777. bytes_copied = buf->len;
  778. }
  779. p_out = (UINT8 *)(p_buf + 1) + p_buf->offset;
  780. *p_out++ = HID_BUILD_HDR(trans_type, param);
  781. /* If report ID required for this device */
  782. if ( (trans_type == HID_TRANS_GET_REPORT) && (report_id != 0) ) {
  783. *p_out = report_id;
  784. data_size = bytes_copied = 1;
  785. }
  786. if (seg_req) {
  787. memcpy (p_out, (((UINT8 *)(buf + 1)) + buf->offset), bytes_copied);
  788. buf->offset += bytes_copied;
  789. buf->len -= bytes_copied;
  790. } else if ( use_data == 1) {
  791. *(p_out + bytes_copied) = data & 0xff;
  792. } else if ( use_data == 2 ) {
  793. *(p_out + bytes_copied) = data & 0xff;
  794. *(p_out + bytes_copied + 1) = (data >> 8) & 0xff ;
  795. }
  796. p_buf->len = bytes_copied + 1 + use_data;
  797. data_size -= bytes_copied;
  798. /* Send the buffer through L2CAP */
  799. if (L2CA_DataWrite(cid, p_buf) == L2CAP_DW_FAILED) {
  800. return (HID_ERR_CONGESTED);
  801. }
  802. if (data_size) {
  803. trans_type = HID_TRANS_DATAC;
  804. } else if ( bytes_copied == (p_hcon->rem_mtu_size - 1) ) {
  805. trans_type = HID_TRANS_DATAC;
  806. blank_datc = TRUE;
  807. }
  808. } while ((data_size != 0) || blank_datc ) ;
  809. return (HID_SUCCESS);
  810. }
  811. /*******************************************************************************
  812. **
  813. ** Function hidh_conn_initiate
  814. **
  815. ** Description This function is called by the management to create a connection.
  816. **
  817. ** Returns void
  818. **
  819. *******************************************************************************/
  820. tHID_STATUS hidh_conn_initiate (UINT8 dhandle)
  821. {
  822. UINT8 service_id = BTM_SEC_SERVICE_HIDH_NOSEC_CTRL;
  823. UINT32 mx_chan_id = HID_NOSEC_CHN;
  824. tHID_HOST_DEV_CTB *p_dev = &hh_cb.devices[dhandle];
  825. if ( p_dev->conn.conn_state != HID_CONN_STATE_UNUSED ) {
  826. return ( HID_ERR_CONN_IN_PROCESS );
  827. }
  828. p_dev->conn.ctrl_cid = 0;
  829. p_dev->conn.intr_cid = 0;
  830. p_dev->conn.disc_reason = HID_L2CAP_CONN_FAIL; /* Reset initial reason for CLOSE_EVT: Connection Attempt was made but failed */
  831. /* We are the originator of this connection */
  832. p_dev->conn.conn_flags = HID_CONN_FLAGS_IS_ORIG;
  833. if (p_dev->attr_mask & HID_SEC_REQUIRED) {
  834. service_id = BTM_SEC_SERVICE_HIDH_SEC_CTRL;
  835. mx_chan_id = HID_SEC_CHN;
  836. }
  837. BTM_SetOutService (p_dev->addr, service_id, mx_chan_id);
  838. /* Check if L2CAP started the connection process */
  839. if ((p_dev->conn.ctrl_cid = L2CA_ConnectReq (HID_PSM_CONTROL, p_dev->addr)) == 0) {
  840. HIDH_TRACE_WARNING ("HID-Host Originate failed");
  841. hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE,
  842. HID_ERR_L2CAP_FAILED, NULL ) ;
  843. } else {
  844. /* Transition to the next appropriate state, waiting for connection confirm on control channel. */
  845. p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_CTRL;
  846. }
  847. return ( HID_SUCCESS );
  848. }
  849. /*******************************************************************************
  850. **
  851. ** Function find_conn_by_cid
  852. **
  853. ** Description This function finds a connection control block based on CID
  854. **
  855. ** Returns address of control block, or NULL if not found
  856. **
  857. *******************************************************************************/
  858. static UINT8 find_conn_by_cid (UINT16 cid)
  859. {
  860. UINT8 xx;
  861. for (xx = 0; xx < HID_HOST_MAX_DEVICES; xx++) {
  862. if ((hh_cb.devices[xx].in_use) && (hh_cb.devices[xx].conn.conn_state != HID_CONN_STATE_UNUSED)
  863. && ((hh_cb.devices[xx].conn.ctrl_cid == cid) || (hh_cb.devices[xx].conn.intr_cid == cid))) {
  864. break;
  865. }
  866. }
  867. return (xx);
  868. }
  869. void hidh_conn_dereg( void )
  870. {
  871. L2CA_Deregister (HID_PSM_CONTROL);
  872. L2CA_Deregister (HID_PSM_INTERRUPT);
  873. }
  874. /*******************************************************************************
  875. **
  876. ** Function hidh_conn_retry
  877. **
  878. ** Description This function is called to retry a failed connection.
  879. **
  880. ** Returns void
  881. **
  882. *******************************************************************************/
  883. static void hidh_conn_retry( UINT8 dhandle )
  884. {
  885. tHID_HOST_DEV_CTB *p_dev = &hh_cb.devices[dhandle];
  886. p_dev->conn.conn_state = HID_CONN_STATE_UNUSED;
  887. p_dev->conn.timer_entry.param = (UINT32) dhandle;
  888. #if (HID_HOST_REPAGE_WIN > 0)
  889. btu_start_timer (&(p_dev->conn.timer_entry), BTU_TTYPE_HID_HOST_REPAGE_TO, HID_HOST_REPAGE_WIN);
  890. #else
  891. hidh_proc_repage_timeout( &(p_dev->conn.timer_entry) );
  892. #endif
  893. }
  894. #endif // HID_HOST_INCLUDED