ssize_t ar6000_htc_raw_read(AR_SOFTC_T *ar, HTC_RAW_STREAM_ID StreamID, char __user *buffer, size_t length) { int readPtr; raw_htc_buffer *busy; if (arRawStream2EndpointID(ar,StreamID) == 0) { AR_DEBUG_PRINTF("StreamID(%d) not connected! \n", StreamID); return -EFAULT; } if (down_interruptible(&ar->raw_htc_read_sem[StreamID])) { return -ERESTARTSYS; } busy = get_filled_buffer(ar,StreamID); while (!ar->read_buffer_available[StreamID]) { up(&ar->raw_htc_read_sem[StreamID]); /* Wait for the data */ AR_DEBUG2_PRINTF("Sleeping StreamID(%d) read process\n", StreamID); if (wait_event_interruptible(ar->raw_htc_read_queue[StreamID], ar->read_buffer_available[StreamID])) { return -EINTR; } if (down_interruptible(&ar->raw_htc_read_sem[StreamID])) { return -ERESTARTSYS; } busy = get_filled_buffer(ar,StreamID); } /* Read the data */ readPtr = busy->currPtr; if (length > busy->length - HTC_HEADER_LEN) { length = busy->length - HTC_HEADER_LEN; } if (copy_to_user(buffer, &busy->data[readPtr], length)) { up(&ar->raw_htc_read_sem[StreamID]); return -EFAULT; } busy->currPtr += length; //AR_DEBUG_PRINTF("raw read ioctl: currPTR : 0x%X 0x%X \n", busy->currPtr,busy->length); if (busy->currPtr == busy->length) { busy->currPtr = 0; busy->length = 0; HTC_PACKET_RESET_RX(&busy->HTCPacket); //AR_DEBUG_PRINTF("raw read ioctl: ep for packet:%d \n", busy->HTCPacket.Endpoint); HTCAddReceivePkt(ar->arHtcTarget, &busy->HTCPacket); } ar->read_buffer_available[StreamID] = FALSE; up(&ar->raw_htc_read_sem[StreamID]); return length; }
void CAR6KMini::ReceiveWMIDataPacket(HTC_PACKET *pHTCPacket) // // This function processes data from an HTC_BUFFER_RECEIVED indication // not on the WMI_CONTROL_MBOX endpoint. // { ndis_mini_buf_t *pb = (ndis_mini_buf_t *)pHTCPacket->pPktContext; NDIS_STATUS Status; NDIS_PACKET *pPacket; NDIS_BUFFER *pBuffer; PBYTE pData; ULONG cbData; BOOL doDix = FALSE; USHORT etherType; SNAP_HEADER *pSnapHdr; MAC_ADDRESS *pDestAddr,*tempAddr,*pSrcAddr; BOOL mcForUs = FALSE; BOOL bisAPUnicast = FALSE; A_UINT8 userPriority=0; STATION *Station = NULL; UINT32 *magic; A_UINT16 powState = 0; A_UINT8 buf[512]; BYTE stationaddr[ETHERNET_MAC_ADDRESS_LENGTH]; NDIS_DEBUG_PRINTF(ATH_LOG_TRC | ATH_DEBUG_RECV, "AR6K: +ReceiveWMIDataPacket"); if (pHTCPacket->Status != A_OK) { NDIS_DEBUG_PRINTF(ATH_LOG_ERR, "AR6K: ERROR - ReceiveWMIPacket Error in receiving : Status = %x\n", pHTCPacket->Status); HTC_PACKET_RESET_RX(pHTCPacket); HTCAddReceivePkt(m_pHTCTarget, pHTCPacket); goto done; } // evInfo->actualLength is the length of the pb->data including // 2 bytes: WMI_DATA_HEADER [optional - only if HTC header is 46 00] // 14 bytes: 802.3 MAC header // 8 bytes: SNAP header (with EthType as last 2 bytes) // N bytes: payload (e.g. IP packet) pData = pHTCPacket->pBuffer; cbData = pHTCPacket->ActualLength; if(AP_NETWORK == m_networkType) { powState = (((WMI_DATA_HDR *)pData)->info >> WMI_DATA_HDR_PS_SHIFT) & WMI_DATA_HDR_PS_MASK; }
int ar6000_htc_raw_open(AR_SOFTC_T *ar) { A_STATUS status; int streamID, endPt, count2; raw_htc_buffer *buffer; HTC_SERVICE_ID servicepriority; AR_RAW_HTC_T *arRaw = ar->arRawHtc; if (!arRaw) { arRaw = ar->arRawHtc = A_MALLOC(sizeof(AR_RAW_HTC_T)); if (arRaw) { A_MEMZERO(arRaw, sizeof(AR_RAW_HTC_T)); } } A_ASSERT(ar->arHtcTarget != NULL); if (!arRaw) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Faile to allocate memory for HTC RAW interface\n")); return -ENOMEM; } /* wait for target */ status = HTCWaitTarget(ar->arHtcTarget); if (A_FAILED(status)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HTCWaitTarget failed (%d)\n", status)); return -ENODEV; } for (endPt = 0; endPt < ENDPOINT_MAX; endPt++) { arRaw->arEp2RawMapping[endPt] = HTC_RAW_STREAM_NOT_MAPPED; } for (streamID = HTC_RAW_STREAM_0; streamID < HTC_RAW_STREAM_NUM_MAX; streamID++) { /* Initialize the data structures */ init_MUTEX(&arRaw->raw_htc_read_sem[streamID]); init_MUTEX(&arRaw->raw_htc_write_sem[streamID]); init_waitqueue_head(&arRaw->raw_htc_read_queue[streamID]); init_waitqueue_head(&arRaw->raw_htc_write_queue[streamID]); /* try to connect to the raw service */ status = ar6000_connect_raw_service(ar,streamID); if (A_FAILED(status)) { break; } if (arRawStream2EndpointID(ar,streamID) == 0) { break; } for (count2 = 0; count2 < RAW_HTC_READ_BUFFERS_NUM; count2 ++) { /* Initialize the receive buffers */ buffer = &arRaw->raw_htc_write_buffer[streamID][count2]; memset(buffer, 0, sizeof(raw_htc_buffer)); buffer = &arRaw->raw_htc_read_buffer[streamID][count2]; memset(buffer, 0, sizeof(raw_htc_buffer)); SET_HTC_PACKET_INFO_RX_REFILL(&buffer->HTCPacket, buffer, buffer->data, HTC_RAW_BUFFER_SIZE, arRawStream2EndpointID(ar,streamID)); /* Queue buffers to HTC for receive */ if ((status = HTCAddReceivePkt(ar->arHtcTarget, &buffer->HTCPacket)) != A_OK) { BMIInit(); return -EIO; } } for (count2 = 0; count2 < RAW_HTC_WRITE_BUFFERS_NUM; count2 ++) { /* Initialize the receive buffers */ buffer = &arRaw->raw_htc_write_buffer[streamID][count2]; memset(buffer, 0, sizeof(raw_htc_buffer)); } arRaw->read_buffer_available[streamID] = FALSE; arRaw->write_buffer_available[streamID] = TRUE; } if (A_FAILED(status)) { return -EIO; } AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("HTC RAW, number of streams the target supports: %d \n", streamID)); servicepriority = HTC_RAW_STREAMS_SVC; /* only 1 */ /* set callbacks and priority list */ HTCSetCreditDistribution(ar->arHtcTarget, ar, NULL, /* use default */ NULL, /* use default */ &servicepriority, 1); /* Start the HTC component */ if ((status = HTCStart(ar->arHtcTarget)) != A_OK) { BMIInit(); return -EIO; } (ar)->arRawIfInit = TRUE; return 0; }
/* Start HTC, enable interrupts and let the target know host has finished setup */ A_STATUS HTCStart(HTC_HANDLE HTCHandle) { HTC_TARGET *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); HTC_PACKET *pPacket; A_STATUS status; AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCStart Enter\n")); printk("HTCStart Enter\n"); /* make sure interrupts are disabled at the chip level, * this function can be called again from a reboot of the target without shutting down HTC */ DevDisableInterrupts(&target->Device); /* make sure state is cleared again */ target->HTCStateFlags = 0; /* now that we are starting, push control receive buffers into the * HTC control endpoint */ while (1) { pPacket = HTC_ALLOC_CONTROL_RX(target); if (NULL == pPacket) { break; } HTCAddReceivePkt((HTC_HANDLE)target,pPacket); } do { AR_DEBUG_ASSERT(target->InitCredits != NULL); AR_DEBUG_ASSERT(target->EpCreditDistributionListHead != NULL); AR_DEBUG_ASSERT(target->EpCreditDistributionListHead->pNext != NULL); /* call init credits callback to do the distribution , * NOTE: the first entry in the distribution list is ENDPOINT_0, so * we pass the start of the list after this one. */ target->InitCredits(target->pCredDistContext, target->EpCreditDistributionListHead->pNext, target->TargetCredits); if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_TRC)) { DumpCreditDistStates(target); } /* the caller is done connecting to services, so we can indicate to the * target that the setup phase is complete */ status = HTCSendSetupComplete(target); if (A_FAILED(status)) { break; } /* unmask interrupts */ status = DevUnmaskInterrupts(&target->Device); if (A_FAILED(status)) { HTCStop(target); } } while (FALSE); AR_DEBUG_PRINTF(ATH_DEBUG_TRC, ("HTCStart Exit\n")); printk("HTCStart Exit\n"); return status; }