hidh_conn.c 37 KB

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