IOReturn WLCard::sendFrame(UInt8* data, UInt32 repeat) { WLFrame *frameDescriptor; UInt8 aData[2364]; IOByteCount pktsize; WLLogInfo("WLCard::sendFrame()\n"); memcpy(aData, data, sizeof(WLFrame)); frameDescriptor = (WLFrame*)aData; switch(frameDescriptor->frameControl & 0x0c) { case 0x08: WLLogInfo("WLCard:: send Data Packet\n"); case 0x00: WLLogInfo("WLCard:: send Management Packet\n"); pktsize = frameDescriptor->dataLen; WLLogInfo("WLCard:: data len: %u\n", (int)pktsize); if ((pktsize + sizeof(WLFrame)) > 2364) return kIOReturnBadArgument; frameDescriptor->dataLen=OSSwapHostToLittleInt16(frameDescriptor->dataLen); break; case 0x04: WLLogInfo("WLCard:: send Control Packet\n"); pktsize = 0; frameDescriptor->dataLen = 0; break; default: WLLogErr("WARNING! WLCard: sendFrame: Unknown Packettype: 0x%x\n",frameDescriptor->frameControl); return kIOReturnBadArgument; } frameDescriptor->txControl=OSSwapHostToLittleInt16(0x08 | _TX_RETRYSTRAT_SET(3)| _TX_CFPOLL_SET(1) | _TX_TXEX_SET(1) | _TX_TXOK_SET(1) | _TX_MACPORT_SET(0)); //frameDescriptor->txControl=OSSwapHostToLittleInt16(0x08); frameDescriptor->rate = 0x6e; //11 MBit/s frameDescriptor->tx_rate = 0x6e; //11 MBit/s memcpy(aData + 0x3C, data + sizeof(WLFrame), pktsize); if (_sendFrame(aData, pktsize + 0x3C) != kIOReturnSuccess) { WLLogCrit("WLCard::sendFrame() transmittion failed\n"); return kIOReturnError; } if ((repeat != 0)&&(_timedSendSource != NULL)) { _timedSendSource->cancelTimeout(); _dataSize = pktsize + 0x3C; memcpy(_data, aData, _dataSize); _timeout = repeat; _failures = 0; _timedSendSource->setTimeoutMS(_timeout); } WLLogInfo("WLCard::sendFrame(): sendFrame returning with success.\n"); return kIOReturnSuccess; }
void WebsocketClient::sendMessage(String str) { _sendFrame(WSFrameType::text, (uint8_t*) str.c_str(), str.length() + 1); }
void WebsocketClient::sendMessage(char* msg, uint16_t length) { _sendFrame(WSFrameType::text, (uint8_t*) msg, length); }
void WebsocketClient::sendBinary(uint8_t* msg, uint16_t length) { _sendFrame(WSFrameType::binary, msg, length); }