Lines Matching +full:cmdq +full:- +full:sync
5 /*-
6 * SPDX-License-Identifier: BSD-2-Clause
100 "%s: %s - got HCI event=%#x, length=%d\n",
101 __func__, NG_NODE_NAME(unit->node), hdr->event, hdr->length);
106 switch (hdr->event) {
223 NG_HCI_BUFF_ACL_AVAIL(unit->buffer, count);
226 "%s: %s - sending ACL data packets, count=%d\n",
227 __func__, NG_NODE_NAME(unit->node), count);
231 NG_HCI_STAT_ACL_SENT(unit->stat, count);
232 NG_HCI_BUFF_ACL_USE(unit->buffer, count);
236 NG_HCI_BUFF_SCO_AVAIL(unit->buffer, count);
239 "%s: %s - sending SCO data packets, count=%d\n",
240 __func__, NG_NODE_NAME(unit->node), count);
244 NG_HCI_STAT_SCO_SENT(unit->stat, count);
245 NG_HCI_BUFF_SCO_USE(unit->buffer, count);
270 LIST_FOREACH(con, &unit->con_list, next) {
271 reallink_type = (con->link_type == NG_HCI_LINK_SCO)?
276 if (NG_BT_ITEMQ_LEN(&con->conq) == 0)
279 if (con->pending < min_pending) {
281 min_pending = con->pending;
290 * Count the number of packets we have sent and then sync
294 for (sent = 0; limit > 0; limit --, total_sent ++, sent ++) {
295 NG_BT_ITEMQ_DEQUEUE(&winner->conq, item);
300 "%s: %s - sending data packet, handle=%d, len=%d\n",
301 __func__, NG_NODE_NAME(unit->node),
302 winner->con_handle, NGI_M(item)->m_pkthdr.len);
305 v = (unit->drv != NULL && NG_HOOK_IS_VALID(unit->drv));
306 if (!v || (unit->state & NG_HCI_UNIT_READY) !=
309 "%s: %s - could not send data. Hook \"%s\" is %svalid, state=%#x\n",
310 __func__, NG_NODE_NAME(unit->node),
312 unit->state);
317 v = NGI_M(item)->m_pkthdr.len;
323 NG_FWD_ITEM_HOOK(error, item, unit->drv);
328 "%s: %s - could not send data packet, handle=%d, error=%d\n",
329 __func__, NG_NODE_NAME(unit->node),
330 winner->con_handle, error);
334 winner->pending ++;
335 NG_HCI_STAT_BYTES_SENT(unit->stat, v);
339 * Sync connection queue for the winner
359 hook = (con->link_type != NG_HCI_LINK_SCO)? unit->acl : unit->sco;
368 state = (ng_hci_sync_con_queue_ep *)(msg->data);
369 state->con_handle = con->con_handle;
370 state->completed = completed;
372 NG_SEND_MSG_HOOK(error, unit->node, msg, hook, 0);
393 num_reports = ep->num_reports;
397 for (; num_reports > 0; num_reports --) {
422 bcopy(&bdaddr, &n->bdaddr, sizeof(n->bdaddr));
423 n->addrtype = (addr_type)? NG_HCI_LINK_LE_RANDOM :
427 getmicrotime(&n->updated);
443 n->extinq_size = (length_data < NG_HCI_EXTINQ_MAX)?
447 event = m_pullup(event, n->extinq_size);
452 m_copydata(event, 0, n->extinq_size, n->extinq_data);
453 m_adj(event, n->extinq_size);
461 n->page_scan_mode = *mtod(event, char *);
485 link_type = (ep->address_type)? NG_HCI_LINK_LE_RANDOM :
490 * 1) con->link_type == link_type
491 * 2) con->state == NG_HCI_CON_W4_CONN_COMPLETE
492 * 3) con->bdaddr == ep->address
494 LIST_FOREACH(con, &unit->con_list, next)
495 if (con->link_type == link_type &&
496 con->state == NG_HCI_CON_W4_CONN_COMPLETE &&
497 bcmp(&con->bdaddr, &ep->address, sizeof(bdaddr_t)) == 0)
518 if (ep->status != 0)
527 con->state = NG_HCI_CON_W4_LP_CON_RSP;
530 bcopy(&ep->address, &con->bdaddr, sizeof(con->bdaddr));
546 con->con_handle = NG_HCI_CON_HANDLE(le16toh(ep->handle));
547 con->encryption_mode = NG_HCI_ENCRYPTION_MODE_NONE;
549 ng_hci_lp_con_cfm(con, ep->status);
552 if (ep->status != 0)
555 con->state = NG_HCI_CON_OPEN;
592 switch(lep->subevent_code){
630 for (; ep->num_responses > 0; ep->num_responses --) {
645 getmicrotime(&n->updated);
647 bcopy(&bdaddr, &n->bdaddr, sizeof(n->bdaddr));
648 n->addrtype = NG_HCI_LINK_ACL;
652 n->page_scan_rep_mode = *mtod(event, u_int8_t *);
658 n->page_scan_mode = *mtod(event, u_int8_t *);
665 m_copydata(event, 0, sizeof(n->clock_offset),
666 (caddr_t) &n->clock_offset);
667 n->clock_offset = le16toh(n->clock_offset);
692 * 1) con->link_type == ep->link_type
693 * 2) con->state == NG_HCI_CON_W4_CONN_COMPLETE
694 * 3) con->bdaddr == ep->bdaddr
697 LIST_FOREACH(con, &unit->con_list, next)
698 if (con->link_type == ep->link_type &&
699 con->state == NG_HCI_CON_W4_CONN_COMPLETE &&
700 bcmp(&con->bdaddr, &ep->bdaddr, sizeof(bdaddr_t)) == 0)
720 if (ep->status != 0)
723 con = ng_hci_new_con(unit, ep->link_type);
729 bcopy(&ep->bdaddr, &con->bdaddr, sizeof(con->bdaddr));
738 con->con_handle = NG_HCI_CON_HANDLE(le16toh(ep->con_handle));
739 con->encryption_mode = ep->encryption_mode;
741 ng_hci_lp_con_cfm(con, ep->status);
744 if (ep->status != 0)
747 con->state = NG_HCI_CON_OPEN;
755 if (ep->link_type == NG_HCI_LINK_ACL) {
764 m->m_pkthdr.len = m->m_len = sizeof(*lp);
767 lp->hdr.type = NG_HCI_CMD_PKT;
768 lp->hdr.opcode = htole16(NG_HCI_OPCODE(
771 lp->hdr.length = sizeof(lp->cp);
773 lp->cp.con_handle = ep->con_handle;
775 lp->cp.settings = 0;
776 if ((unit->features[0] & NG_HCI_LMP_SWITCH) &&
777 unit->role_switch)
778 lp->cp.settings |= 0x1;
779 if (unit->features[0] & NG_HCI_LMP_HOLD_MODE)
780 lp->cp.settings |= 0x2;
781 if (unit->features[0] & NG_HCI_LMP_SNIFF_MODE)
782 lp->cp.settings |= 0x4;
783 if (unit->features[1] & NG_HCI_LMP_PARK_MODE)
784 lp->cp.settings |= 0x8;
786 lp->cp.settings &= unit->link_policy_mask;
787 lp->cp.settings = htole16(lp->cp.settings);
789 NG_BT_MBUFQ_ENQUEUE(&unit->cmdq, m);
790 if (!(unit->state & NG_HCI_UNIT_COMMAND_PENDING))
818 * 1) con->link_type == ep->link_type
820 * 2) con->state == NG_HCI_CON_W4_LP_CON_RSP ||
821 * con->state == NG_HCI_CON_W4_CONN_COMPL
823 * 3) con->bdaddr == ep->bdaddr
857 LIST_FOREACH(con, &unit->con_list, next)
858 if (con->link_type == ep->link_type &&
859 (con->state == NG_HCI_CON_W4_LP_CON_RSP ||
860 con->state == NG_HCI_CON_W4_CONN_COMPLETE) &&
861 bcmp(&con->bdaddr, &ep->bdaddr, sizeof(bdaddr_t)) == 0)
865 con = ng_hci_new_con(unit, ep->link_type);
867 bcopy(&ep->bdaddr, &con->bdaddr, sizeof(con->bdaddr));
869 con->state = NG_HCI_CON_W4_LP_CON_RSP;
872 error = ng_hci_lp_con_ind(con, ep->uclass);
903 * Do we have to send notification if ep->status != 0?
905 * ONLY if ep->status == 0.
908 if (ep->status == 0) {
909 h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle));
912 error = ng_hci_lp_discon_ind(con, ep->reason);
915 if (con->flags & NG_HCI_CON_TIMEOUT_PENDING)
921 "%s: %s - invalid connection handle=%d\n",
922 __func__, NG_NODE_NAME(unit->node), h);
946 h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle));
949 if (ep->status == 0) {
952 "%s: %s - invalid connection handle=%d\n",
953 __func__, NG_NODE_NAME(unit->node), h);
955 } else if (con->link_type == NG_HCI_LINK_SCO) {
957 "%s: %s - invalid link type=%d\n",
958 __func__, NG_NODE_NAME(unit->node),
959 con->link_type);
961 } else if (ep->encryption_enable)
963 con->encryption_mode = NG_HCI_ENCRYPTION_MODE_P2P;
965 con->encryption_mode = NG_HCI_ENCRYPTION_MODE_NONE;
968 "%s: %s - failed to change encryption mode, status=%d\n",
969 __func__, NG_NODE_NAME(unit->node), ep->status);
972 ng_hci_lp_enc_change(con, con->encryption_mode);
995 if (ep->status == 0) {
997 h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle));
1001 "%s: %s - invalid connection handle=%d\n",
1002 __func__, NG_NODE_NAME(unit->node), h);
1008 n = ng_hci_get_neighbor(unit, &con->bdaddr, NG_HCI_LINK_ACL);
1016 bcopy(&con->bdaddr, &n->bdaddr, sizeof(n->bdaddr));
1017 n->addrtype = NG_HCI_LINK_ACL;
1019 getmicrotime(&n->updated);
1021 bcopy(ep->features, n->features, sizeof(n->features));
1024 "%s: %s - failed to read remote unit features, status=%d\n",
1025 __func__, NG_NODE_NAME(unit->node), ep->status);
1048 h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle));
1052 "%s: %s - invalid connection handle=%d\n",
1053 __func__, NG_NODE_NAME(unit->node), h);
1055 } else if (con->link_type != NG_HCI_LINK_ACL) {
1057 "%s: %s - invalid link type=%d, handle=%d\n",
1058 __func__, NG_NODE_NAME(unit->node), con->link_type, h);
1060 } else if (con->state != NG_HCI_CON_OPEN) {
1062 "%s: %s - invalid connection state=%d, handle=%d\n",
1063 __func__, NG_NODE_NAME(unit->node),
1064 con->state, h);
1067 error = ng_hci_lp_qos_cfm(con, ep->status);
1079 "%s: %s - hardware error %#x\n",
1080 __func__, NG_NODE_NAME(unit->node), *mtod(event, u_int8_t *));
1100 if (ep->status == 0) {
1102 con = ng_hci_con_by_bdaddr(unit, &ep->bdaddr, NG_HCI_LINK_ACL);
1104 con->role = ep->role;
1107 "%s: %s - ACL connection does not exist, bdaddr=%x:%x:%x:%x:%x:%x\n",
1108 __func__, NG_NODE_NAME(unit->node),
1109 ep->bdaddr.b[5], ep->bdaddr.b[4],
1110 ep->bdaddr.b[3], ep->bdaddr.b[2],
1111 ep->bdaddr.b[1], ep->bdaddr.b[0]);
1114 "%s: %s - failed to change role, status=%d, bdaddr=%x:%x:%x:%x:%x:%x\n",
1115 __func__, NG_NODE_NAME(unit->node), ep->status,
1116 ep->bdaddr.b[5], ep->bdaddr.b[4], ep->bdaddr.b[3],
1117 ep->bdaddr.b[2], ep->bdaddr.b[1], ep->bdaddr.b[0]);
1139 for (; ep->num_con_handles > 0; ep->num_con_handles --) {
1153 con->pending -= p;
1154 if (con->pending < 0) {
1156 "%s: %s - pending packet counter is out of sync! " \
1157 "handle=%d, pending=%d, ncp=%d\n", __func__, NG_NODE_NAME(unit->node),
1158 con->con_handle, con->pending, p);
1160 con->pending = 0;
1164 if (con->link_type != NG_HCI_LINK_SCO)
1165 NG_HCI_BUFF_ACL_FREE(unit->buffer, p);
1167 NG_HCI_BUFF_SCO_FREE(unit->buffer, p);
1170 "%s: %s - invalid connection handle=%d\n",
1171 __func__, NG_NODE_NAME(unit->node), h);
1196 if (ep->status == 0) {
1197 u_int16_t h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle));
1202 "%s: %s - invalid connection handle=%d\n",
1203 __func__, NG_NODE_NAME(unit->node), h);
1205 } else if (con->link_type != NG_HCI_LINK_ACL) {
1207 "%s: %s - invalid link type=%d\n",
1208 __func__, NG_NODE_NAME(unit->node),
1209 con->link_type);
1212 con->mode = ep->unit_mode;
1215 "%s: %s - failed to change mode, status=%d\n",
1216 __func__, NG_NODE_NAME(unit->node), ep->status);
1228 "%s: %s - %s data buffer overflow\n",
1229 __func__, NG_NODE_NAME(unit->node),
1252 if (ep->status == 0) {
1253 u_int16_t h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle));
1258 "%s: %s - invalid connection handle=%d\n",
1259 __func__, NG_NODE_NAME(unit->node), h);
1265 n = ng_hci_get_neighbor(unit, &con->bdaddr, NG_HCI_LINK_ACL);
1273 bcopy(&con->bdaddr, &n->bdaddr, sizeof(n->bdaddr));
1274 n->addrtype = NG_HCI_LINK_ACL;
1276 getmicrotime(&n->updated);
1278 n->clock_offset = le16toh(ep->clock_offset);
1281 "%s: %s - failed to Read Remote Clock Offset, status=%d\n",
1282 __func__, NG_NODE_NAME(unit->node), ep->status);
1305 h = NG_HCI_CON_HANDLE(le16toh(ep->con_handle));
1309 "%s: %s - invalid connection handle=%d\n",
1310 __func__, NG_NODE_NAME(unit->node), h);
1312 } else if (con->link_type != NG_HCI_LINK_ACL) {
1314 "%s: %s - invalid link type=%d\n",
1315 __func__, NG_NODE_NAME(unit->node), con->link_type);
1317 } else if (con->state != NG_HCI_CON_OPEN) {
1319 "%s: %s - invalid connection state=%d, handle=%d\n",
1320 __func__, NG_NODE_NAME(unit->node), con->state, h);
1345 n = ng_hci_get_neighbor(unit, &ep->bdaddr, NG_HCI_LINK_ACL);
1353 bcopy(&ep->bdaddr, &n->bdaddr, sizeof(n->bdaddr));
1354 n->addrtype = NG_HCI_LINK_ACL;
1356 getmicrotime(&n->updated);
1358 n->page_scan_mode = ep->page_scan_mode;
1380 n = ng_hci_get_neighbor(unit, &ep->bdaddr, NG_HCI_LINK_ACL);
1388 bcopy(&ep->bdaddr, &n->bdaddr, sizeof(n->bdaddr));
1389 n->addrtype = NG_HCI_LINK_ACL;
1391 getmicrotime(&n->updated);
1393 n->page_scan_rep_mode = ep->page_scan_rep_mode;