/* * Called by UART driver to send out next character. * * Interrupts disabled when nmgr_uart_tx_char/nmgr_uart_rx_char are called. */ static int nmgr_uart_tx_char(void *arg) { struct nmgr_uart_state *nus = (struct nmgr_uart_state *)arg; struct os_mbuf *m; uint8_t ch; if (!nus->nus_tx) { /* * Out of data. Return -1 makes UART stop asking for more. */ return -1; } while (nus->nus_tx->om_len == nus->nus_tx_off) { /* * If no active mbuf, move to next one. */ m = SLIST_NEXT(nus->nus_tx, om_next); os_mbuf_free(nus->nus_tx); nus->nus_tx = m; nus->nus_tx_off = 0; if (!nus->nus_tx) { return -1; } } os_mbuf_copydata(nus->nus_tx, nus->nus_tx_off++, 1, &ch); return ch; }
int ble_l2cap_sig_init_cmd(uint8_t op, uint8_t id, uint8_t payload_len, struct os_mbuf **out_om, void **out_payload_buf) { struct ble_l2cap_sig_hdr hdr; struct os_mbuf *txom; void *v; int rc; *out_om = NULL; *out_payload_buf = NULL; txom = ble_hs_mbuf_l2cap_pkt(); if (txom == NULL) { rc = BLE_HS_ENOMEM; goto err; } v = os_mbuf_extend(txom, BLE_L2CAP_SIG_HDR_SZ + payload_len); if (v == NULL) { rc = BLE_HS_ENOMEM; goto err; } hdr.op = op; hdr.identifier = id; hdr.length = TOFROMLE16(payload_len); ble_l2cap_sig_hdr_write(v, BLE_L2CAP_SIG_HDR_SZ, &hdr); *out_om = txom; *out_payload_buf = (uint8_t *)v + BLE_L2CAP_SIG_HDR_SZ; return 0; err: os_mbuf_free(txom); return rc; }