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; }
static void dispatchUnicodeEvent(char c) { UnicodeReport report; static CFAbsoluteTime sDeadline = 0; CFAbsoluteTime delta; bzero(&report, sizeof(report)); if ( c < 'a' || c > 'z' ) return; printf("dispatching unicode event for '%c'\n", c); pthread_mutex_lock(&gMuxtex); delta = sDeadline - CFAbsoluteTimeGetCurrent(); if ( delta > 0 ) usleep(delta*1000000); report.usage = c; OSSwapHostToLittleInt16(report.usage); printReport((uint8_t*)&report, sizeof(report), 0); IOHIDUserDeviceHandleReport(gDevice, (uint8_t*)&report, sizeof(report)); sDeadline = CFAbsoluteTimeGetCurrent() + kKeyboardInterval; pthread_mutex_unlock(&gMuxtex); }
static uint16_t _dispatch_transform_swap_from_host(uint16_t x, int32_t byteOrder) { if (byteOrder == OSLittleEndian) { return OSSwapHostToLittleInt16(x); } return OSSwapHostToBigInt16(x); }
UInt32 Sym8xxSCSIController::Sym8xxReadRegs( volatile UInt8 *chipRegs, UInt32 regOffset, UInt32 regSize ) { if ( regSize == 1 ) { return chipRegs[regOffset]; } if ( regSize == 2 ) { return OSSwapHostToLittleInt16( *(volatile u_int16_t *)&chipRegs[regOffset] ); } else if (regSize == 4 ) { return OSSwapHostToLittleInt32( *(volatile UInt32 *)&chipRegs[regOffset] ); } else { kprintf("SCSI(SymBios875): Sym8xxReadRegs incorrect regSize\n\r" ); return 0; } }
void Sym8xxSCSIController::Sym8xxWriteRegs( volatile UInt8 *chipRegs, UInt32 regOffset, UInt32 regSize, UInt32 regValue ) { if ( regSize == 1 ) { chipRegs[regOffset] = regValue; } else if ( regSize == 2 ) { volatile u_int16_t *p = (volatile u_int16_t *)&chipRegs[regOffset]; *p = OSSwapHostToLittleInt16( regValue ); } else if ( regSize == 4 ) { volatile UInt32 *p = (volatile UInt32 *)&chipRegs[regOffset]; *p = OSSwapHostToLittleInt32( regValue ); } else { kprintf("SCSI(SymBios875): Sym8xxWriteRegs incorrect regSize\n\r" ); } eieio(); }
UInt32 AtherosL1Ethernet::outputPacket(mbuf_t m, void *prm) { u32 buf_len; at_adapter *adapter=&adapter_; u16 next_to_use; u16 tpd_req = 1; TpdDescr *pTpd ; struct at_buffer *buffer_info; if(tpd_avail(&adapter->tpd_ring) < tpd_req) { // no enough descriptor DbgPrint("no enough resource!!\n"); freePacket(m); return kIOReturnOutputDropped; } // init tpd flags struct at_tpd_ring* tpd_ring = &adapter->tpd_ring; pTpd = AT_TPD_DESC(tpd_ring, ((u16)atomic_read(&tpd_ring->next_to_use))); //memset(pTpd, 0, sizeof(TpdDescr)); memset(((u8*)pTpd + sizeof(pTpd->addr)), 0, (sizeof(TpdDescr) - sizeof(pTpd->addr))); //addr don't clear next_to_use = (u16)atomic_read(&tpd_ring->next_to_use); buffer_info = tpd_ring->buffer_info+next_to_use; if (!buffer_info->memDesc) { DbgPrint("Tx buffer is null!!\n"); freePacket(m); return kIOReturnOutputDropped; } if (mbuf_pkthdr_len(m) <= AT_TX_BUF_LEN) buf_len = mbuf_pkthdr_len(m); else { DbgPrint("Tx Packet size is too big, droping\n"); freePacket(m); return kIOReturnOutputDropped; } DbgPrint("outputPacket() length %d next_to_use=%d\n", buf_len, next_to_use); UInt8 *data_ptr = (UInt8 *)buffer_info->memDesc->getBytesNoCopy(); UInt32 pkt_snd_len = 0; mbuf_t cur_buf = m; do { if (mbuf_data(cur_buf)) bcopy(mbuf_data(cur_buf), data_ptr, mbuf_len(cur_buf)); data_ptr += mbuf_len(cur_buf); pkt_snd_len += mbuf_len(cur_buf); } while(((cur_buf = mbuf_next(cur_buf)) != NULL) && ((pkt_snd_len + mbuf_len(cur_buf)) <= buf_len)); buf_len = pkt_snd_len; buffer_info->length = (UInt16)buf_len; pTpd->buf_len= OSSwapHostToLittleInt16((UInt16)buf_len); pTpd->eop = 1; if(++next_to_use == tpd_ring->count) next_to_use = 0; atomic_set(&tpd_ring->next_to_use, next_to_use); // update mailbox at_update_mailbox(adapter); OSSynchronizeIO(); freePacket(m); return kIOReturnOutputSuccess; }
uint16_t tole16(uint16_t x) { return OSSwapHostToLittleInt16(x); }