/* Map iana names to OpenSSL names so users can provide IANA names as well as OpenSSL cipher names */ static char *mapCipherNames(char *ciphers) { WebsBuf buf; CipherMap *cp; char *cipher, *next, *str; if (!ciphers || *ciphers == 0) { return 0; } bufCreate(&buf, 0, 0); ciphers = sclone(ciphers); for (next = ciphers; (cipher = stok(next, ":, \t", &next)) != 0; ) { for (cp = cipherMap; cp->name; cp++) { if (smatch(cp->name, cipher)) { bufPut(&buf, "%s:", cp->ossName); break; } } if (cp->name == 0) { bufPut(&buf, "%s:", cipher); } } wfree(ciphers); str = sclone(bufStart(&buf)); bufFree(&buf); return str; }
/*********************************************************************************** * @fn halUartBufferedWrite * * @brief Write data buffered to UART. Data is written into a buffer, and the * buffer is emptied by UART TX interrupt ISR * * @param uint8* buf - buffer with data to write * uint16 length - number of bytes to write * * @return number of bytes written */ uint16 halUartBufferedWrite(const uint8* buf, uint16 length) { uint16 n; n= 0; while ( n < length ) { uint8 i; i= bufPut(&rbTxBuf,buf+n,length-n); if (i==0) { halMcuWaitMs(5); i+= bufPut(&rbTxBuf,buf+n,length-n); if (i==0) // Assuming that there is no connection; give up break; } n+= i; } return n; // (bufPut(&rbTxBuf,buf,length)); }
/*********************************************************************************** * @fn usbOutProcess * * @brief Handle traffic flow from USB to RF. * * @param none * * @return none */ static void usbOutProcess(void) { uint8 length, nToSend; // If new packet is ready in USB FIFO halIntOff(); oldEndpoint = USBFW_GET_SELECTED_ENDPOINT(); USBFW_SELECT_ENDPOINT(4); if (USBFW_OUT_ENDPOINT_DISARMED() ) { // Get length of USB packet, this operation must not be interrupted. length = USBFW_GET_OUT_ENDPOINT_COUNT_LOW(); length+= (int)(USBFW_GET_OUT_ENDPOINT_COUNT_HIGH()) >> 8; // Calculate number of bytes available in RF buffer; and the number // of bytes we may transfer in this operation. nToSend= MIN(BUF_SIZE - bufNumBytes(&rbRxBuf), length); // Space available in UART RX buffer ? if (nToSend>0) { // Read from USB FIFO usbfwReadFifo(&USBF4, nToSend, buffer); // Write to radio TX buffer bufPut(&rbRxBuf,buffer,nToSend); // If entire USB packet is read from buffer if (length == nToSend) { USBFW_SELECT_ENDPOINT(4); USBFW_ARM_OUT_ENDPOINT(); } } } USBFW_SELECT_ENDPOINT(oldEndpoint); halIntOn(); }
void zb_put_out_queue() { zb_uint8_t len; zb_sniffer_err_e not_enough_space; zb_sniffer_hdr_t hdr; ZB_MEMSET(&hdr, 0, ZB_SNIFFER_HDR_SIZE); not_enough_space = bufIsFull(&rbTxBuf) ? ZB_SNIFFER_OUT_BUF_OVERFLOW : ZB_SNIFFER_OK; if (!not_enough_space) { zb_uint8_t i; zb_bool_t accept_frame = ZB_TRUE; zb_uint8_t buf[ZB_SNIFFER_BUF_SIZE]; /* zb_uint16_t fcf; */ zb_uint8_t crc; len = RFD; /* Check the reserved 7th bit of length field */ if (ZB_SNIFFER_CHECK_MSB(len)) { accept_frame = ZB_FALSE; } /* Max packet length - 127 b, ignore 7th byte to prevent buffer overflow */ len &= 0x7F; buf[0] = len; if (len >= ZB_SNIFFER_BUF_SIZE) { /* Packet length is larger than buffer size; don't change buffer size to value less than 128 b */ not_enough_space = ZB_SNIFFER_TOO_BIG_LEN; } if (!not_enough_space) { /* Read packet payload */ for (i = 1; i<=len; i++) { buf[i] = RFD; } /* Include length byte */ len++; /* Check FCF reserved bits with source & destination addressing modes */ /* fcf = *((zb_uint16_t *)&buf[1]); */ /* Auto CRC is enabled: check CRC OK bit */ crc = buf[len - 1]; accept_frame &= (ZB_SNIFFER_CHECK_MSB(crc)) ? ZB_TRUE : ZB_FALSE; /* accept_frame &= check_fcf(fcf); */ if (accept_frame) { if (bufHasEnoughSpace(&rbTxBuf, len + sizeof(hdr))) { hdr.len = len + ZB_SNIFFER_HDR_SIZE; hdr.type = ZB_SNIFFER_OK; hdr.tail = 0; bufPut(&rbTxBuf, (zb_uint8_t *)(&hdr), sizeof(hdr)); bufPut(&rbTxBuf, buf, len); } else { /* There is no space in output buffer for the whole packet */ not_enough_space = ZB_SNIFFER_OUT_BUF_OVERFLOW; } } } } if (not_enough_space) { if (not_enough_space == ZB_SNIFFER_TOO_BIG_LEN) { RFST = 0xED; /* flush rxfifo */ RFST = 0xE3; /* rx on */ } else if (not_enough_space == ZB_SNIFFER_OUT_BUF_OVERFLOW) { bufFlush(&rbTxBuf); } /* Tell about problem happened to the host */ hdr.len = sizeof(zb_sniffer_hdr_t); hdr.type = not_enough_space; hdr.tail = 0; /* Header with ZB_MAC_TRANSPORT_TYPE_TRACE signals about error */ bufPut(&rbTxBuf, (zb_uint8_t *)(&hdr), sizeof(hdr)); } }