DWORD FileModifyTest(__CMD_PARA_OBJ* pCmdParaObj) { DWORD dwFilePos = 1024; HANDLE hFileObj = NULL; hFileObj = CreateFile("C:\\test.bmp",FILE_ACCESS_WRITE|FILE_OPEN_ALWAYS,0,NULL); _hx_printf("Modify Start!\r\n"); if(hFileObj == NULL || hFileObj == (HANDLE)-1) { _hx_printf("Modify Faild!\r\n"); return S_OK; } //�ƶ��ļ� SetFilePointer(hFileObj,&dwFilePos,&dwFilePos,FILE_FROM_CURRENT); //�ض� SetEndOfFile(hFileObj); CloseFile(hFileObj); _hx_printf("Modify Complete!\r\n"); return S_OK; }
//Use polling mode instead of interrupt mode. void* EHCIPollIntQueue(struct usb_device *dev, struct int_queue *queue) { DWORD dwResult = 0; void* pRet = NULL; int timeout = 0; timeout = get_timer(0); while (TRUE) { if (_ehciQueueIntHandler(queue)) { pRet = queue->first->buffer; _hx_printf("%s: Transmit success with token = %x.\r\n", __func__, queue->first->qh_overlay.qt_token); break; } if (get_timer(timeout) >= 2000 / SYSTEM_TIME_SLICE) //Wait 2 seconds. { _hx_printf("%s: Transmit failed with timeout = %d,token = %X.\r\n", __func__,get_timer(timeout), queue->first->qh_overlay.qt_token); break; } } return pRet; }
static DWORD TimeHandler(__CMD_PARA_OBJ* pCmdParaObj) { BYTE time[6]; __GetTime(&time[0]); _hx_printf(" Current Date: %d-%d-%d(YYYY-MM-DD)\r\n",time[0] + 2000,time[1],time[2]); _hx_printf(" Current Time: %d:%d:%d(HH:MM:SS)\r\n",time[3],time[4],time[5]); return SHELL_CMD_PARSER_SUCCESS; }
static void ping_recv(int s) { char* buf = NULL; int fromlen, len; struct sockaddr_in from; struct ip_hdr *iphdr; struct icmp_echo_hdr *iecho; int ms; BOOL bResult = FALSE; //Allocate a buffer to contain the received data. buf = (char*)KMemAlloc(1500,KMEM_SIZE_TYPE_ANY); if(NULL == buf) { return; } while((len = lwip_recvfrom(s, buf, 1500, 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) { if(len >= (int)(sizeof(struct ip_hdr)+sizeof(struct icmp_echo_hdr))) { ip_addr_t fromaddr; inet_addr_to_ipaddr(&fromaddr, &from.sin_addr); //Get times between sent and receive. ms = sys_now() - ping_time; ms *= SYSTEM_TIME_SLICE; iphdr = (struct ip_hdr *)buf; iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4)); if (((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num)) && iecho->type == ICMP_ER)) { len = len - sizeof(struct ip_hdr) - sizeof(struct icmp_echo_hdr); //Adjust received data's length,since it //includes IP and ICMP headers. _hx_printf(" [%d] Reply from %s,size = %d,time = %d(ms)\r\n",ping_pkt_seq,inet_ntoa(fromaddr),len,ms); ping_succ ++; bResult = TRUE; } else { //printf(" ping : Received invalid replay,drop it.\r\n"); } } } if (!bResult) { _hx_printf(" [%d] Request time out.\r\n",ping_pkt_seq); } if(buf) //Release it. { KMemFree(buf,KMEM_SIZE_TYPE_ANY,0); } }
/* Local helper routine to show out one easy NAT entry. */ static void ShowNatEntry(__EASY_NAT_ENTRY* pEntry) { /* Output as: [x.x.x.x : p1]->[y.y.y.y : p2], pro:17, ms:10, mt:1000 */ _hx_printf("[%s:%d]->", inet_ntoa(pEntry->srcAddr_bef), pEntry->srcPort_bef); _hx_printf("[%s:%d], ", inet_ntoa(pEntry->srcAddr_aft), pEntry->srcPort_aft); _hx_printf("dst[%s:%d], pro:%d, ms:%d, mt:%d\r\n", inet_ntoa(pEntry->dstAddr_bef), pEntry->dstPort_bef, pEntry->protocol, pEntry->ms, pEntry->match_times); }
//Entry point of FileWriteTest. DWORD FileWriteTest(__CMD_PARA_OBJ* pCmdParaObj) { static char s_temp = 'a'; char szFileBuf[512] = {0}; char szInfoBuf[128] = {0}; DWORD secondS = 0; DWORD secondE = 0; DWORD Writed = 0; DWORD WriteCount = 10; DWORD dwFilePos = 0; DWORD i = 0; HANDLE hFileObj = NULL; secondS = System.GetSysTick(NULL); //Get system tick counter. //Convert to second. secondS *= SYSTEM_TIME_SLICE; secondS /= 1000; memset(szFileBuf,s_temp,sizeof(szFileBuf)); s_temp += 1; _hx_printf("Write Start....\r\n"); hFileObj = CreateFile("C:\\wt.dat",FILE_ACCESS_WRITE|FILE_OPEN_ALWAYS,0,NULL); if(hFileObj == NULL || hFileObj == (HANDLE)-1) { _hx_printf("Write Faild!\r\n"); return S_OK; } //�ƶ����ļ�β SetFilePointer(hFileObj,&dwFilePos,&dwFilePos,FILE_FROM_END); // _hx_printf("start write \r\n"); for(i=0;i<WriteCount;i++) { WriteFile(hFileObj,sizeof(szFileBuf),szFileBuf,&Writed); } WriteFile(hFileObj,2,"\r\n",&Writed); //_hx_printf("Close handle\r\n"); CloseFile(hFileObj); secondE = System.GetSysTick(NULL); //Get system tick counter. secondE *= SYSTEM_TIME_SLICE; secondE /= 1000; _hx_printf("Write Complete,Use Time= %d sec\r\n",secondE-secondS); return S_OK; }
DWORD DebugHandler(__CMD_PARA_OBJ* pCmdParaObj) { BUG_ON(TRUE); /* Test BUG macro. */ #if 0 __PROCESS_OBJECT* pProcess1 = NULL; __PROCESS_OBJECT* pProcess2 = NULL; int round = 1000; for(round = 0;round < 20480;round ++) { pProcess1 = ProcessManager.CreateProcess( (__COMMON_OBJECT*)&ProcessManager, 0, PRIORITY_LEVEL_NORMAL, Process1, NULL, NULL, "Process1"); if(NULL == pProcess1) { _hx_printf(" Create Process1 failed.\r\n"); return SHELL_CMD_PARSER_SUCCESS; } _hx_printf(" Create Process1 successfully.\r\n"); pProcess2 = ProcessManager.CreateProcess( (__COMMON_OBJECT*)&ProcessManager, 0, PRIORITY_LEVEL_NORMAL, Process2, NULL, NULL, "Process2"); if(NULL == pProcess2) { _hx_printf(" Create Process2 failed.\r\n"); return SHELL_CMD_PARSER_SUCCESS; } _hx_printf(" Create Process2 successfully.\r\n"); pProcess1->WaitForThisObject((__COMMON_OBJECT*)pProcess1); pProcess2->WaitForThisObject((__COMMON_OBJECT*)pProcess2); ProcessManager.DestroyProcess((__COMMON_OBJECT*)&ProcessManager,(__COMMON_OBJECT*)pProcess1); ProcessManager.DestroyProcess((__COMMON_OBJECT*)&ProcessManager,(__COMMON_OBJECT*)pProcess2); _hx_printf(" Debug round [ %d ]run over.\r\n",round); } #endif return SHELL_CMD_PARSER_SUCCESS; }
/* * A helper routine to register a new initialized R8152 device into * HelloX Kernel. */ static int Register_R8152(struct usb_device *dev, struct ueth_data *ss) { __ETHERNET_INTERFACE* pEthInt = NULL; unsigned char mac_addr[ETH_MAC_LEN]; char eth_name[MAX_ETH_NAME_LEN + 1]; int err = 0; /* Retrieve hardware address of the device. */ err = r8152_read_mac(ss->dev_priv, mac_addr); if (err < 0) { _hx_printf("%s: failed to retrieve MAC addr,err = %d.\r\n", __func__, err); return 0; } /* Construct the default ethernet interface name. */ _hx_sprintf(eth_name, "%s%d", R8152_NAME_BASE, ss->ef_idx); /* Add R8152 corresponding Ethernet interface. */ pEthInt = EthernetManager.AddEthernetInterface( eth_name, mac_addr, ss, __r8152_init, __r8152_send, NULL, //Receive operation is put into receiving thread,since it may lead long time blocking. __r8152_control); if (NULL == pEthInt) { _hx_printf("Failed to add [%s] to network.\r\n", eth_name); return 0; } //Save into USB ethernet private data. ss->thisIf = pEthInt; _hx_printf("Add eth_if[name = %s,mac = %.2X-%.2X-%.2X-%.2X-%.2X-%.2X] successfully.\r\n", eth_name, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); return 1; }
DWORD FileReadTest(__CMD_PARA_OBJ* pCmdParaObj) { char szFileBuf[512] = {0}; char szInfoBuf[128] = {0}; DWORD secondS = 0; DWORD secondE = 0; DWORD ReadRet = 0; DWORD ReadCount = 20480; DWORD dwFilePos = 0; DWORD i = 0; HANDLE hFileObj = NULL; secondS = System.GetSysTick(NULL); //Get system tick counter. //Convert to second. secondS *= SYSTEM_TIME_SLICE; secondS /= 1000; _hx_printf("Raed Start....\r\n"); hFileObj = CreateFile("C:\\wt.dat",FILE_ACCESS_READ|FILE_OPEN_EXISTING,0,NULL); if(hFileObj == NULL || hFileObj == (HANDLE)-1) { _hx_printf("read Faild!\r\n"); return S_OK; } for(i=0;i<ReadCount;i++) { ReadFile(hFileObj,sizeof(szFileBuf),szFileBuf,&ReadRet); if(ReadRet < sizeof(szFileBuf)) { _hx_printf("Raed faild....step=%d\r\n",i); } } //_hx_printf("Close handle\r\n"); CloseFile(hFileObj); secondE = System.GetSysTick(NULL); //Get system tick counter. secondE *= SYSTEM_TIME_SLICE; secondE /= 1000; _hx_printf("Read Complete,Use Time= %d sec",secondE-secondS); return S_OK; }
//Entry point of ping application. void ping_Entry(void *arg) { int s; int timeout = PING_RCV_TIMEO; __PING_PARAM* pParam = (__PING_PARAM*)arg; ping_pkt_seq = 0; //Reset ping sequence number. ping_succ = 0; if((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { PrintLine(" ping : Create raw socket failed,quit."); return; } lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); _hx_printf("\r\n Ping %s with %d bytes packet:\r\n",inet_ntoa(pParam->targetAddr),pParam->size); while (1) { //ping_target = PING_TARGET; //ping gw //IP4_ADDR(&ping_target, 127,0,0,1); //ping loopback. if (ping_send(s, &pParam->targetAddr,pParam->size) == ERR_OK) { //printf(" ping_Entry : Send out packet,addr = %s,size = %d\r\n",inet_ntoa(pParam->targetAddr),pParam->size); ping_time = sys_now(); ping_recv(s); ping_pkt_seq ++; } else { PrintLine(" ping : Send out packet failed."); } //sys_msleep(PING_DELAY); //Try the specified times. pParam->count --; if(0 == pParam->count) { break; } } //Show ping statistics. _hx_printf("\r\n"); _hx_printf(" ping statistics: total send = %d,received = %d,%d loss.\r\n", ping_pkt_seq,ping_succ,(ping_pkt_seq - ping_succ)); //Close socket. lwip_close(s); }
/* Stop a PPPoE session by giving it's name. */ static BOOL StopPPPoEByName(char* instance) { __PPPOE_INSTANCE* pInstance = pppoeManager.pInstanceList; BOOL bResult = FALSE; __KERNEL_THREAD_MESSAGE msg; BUG_ON(NULL == instance); /* Locate the instance object by comparing their name. */ while (pInstance) { if (0 == strcmp(instance, pInstance->session_name)) { break; } pInstance = pInstance->pNext; } if (NULL == pInstance) { _hx_printf(" Can not find the instance you specified.\r\n"); goto __TERMINAL; } /* Trigger stop process by sending message to main thread. */ msg.wCommand = PPPOE_MSG_STOPSESSION; msg.wParam = 0; msg.dwParam = (DWORD)pInstance; bResult = SendMessage(pppoeManager.hMainThread, &msg); __TERMINAL: return bResult; }
/* * Background thread of NAT,timers,NAT entryies, * and other NAT related functions are handled in * this thread. */ static DWORD NatMainThread(LPVOID* pData) { HANDLE hTimer = NULL; __KERNEL_THREAD_MESSAGE msg; /* Create periodic timer of NAT. */ hTimer = SetTimer(NAT_PERIODIC_TIMER_ID, NAT_ENTRY_SCAN_PERIOD, NULL, NULL, TIMER_FLAGS_ALWAYS); if (NULL == hTimer) { _hx_printf("%s: failed to create periodic timer.\r\n", __func__); goto __TERMINAL; } /* Main message loop. */ while (TRUE) { if (GetMessage(&msg)) { switch (msg.wCommand) { case KERNEL_MESSAGE_TIMER: PeriodicTimerHandler(); break; case KERNEL_MESSAGE_TERMINAL: goto __TERMINAL; break; default: break; } } } __TERMINAL: return 0; }
/* Create and initialize a NAT entry. */ static __EASY_NAT_ENTRY* CreateNatEntry(__NAT_MANAGER* pMgr) { __EASY_NAT_ENTRY* pEntry = NULL; BUG_ON(NULL == pMgr); /* * If too many NAT entries exist. Should in critical section,but * now it's OK,since the routine will be called by tcp_ip thread only. */ if (MAX_NAT_ENTRY_NUM < pMgr->stat.entry_num) { _hx_printf("[NAT]: too many NAT entries.\r\n"); goto __TERMINAL; } pMgr->stat.entry_num++; /* Create and initialize it. */ pEntry = (__EASY_NAT_ENTRY*)_hx_malloc(sizeof(__EASY_NAT_ENTRY)); if (NULL == pEntry) { goto __TERMINAL; } memset(pEntry, 0, sizeof(__EASY_NAT_ENTRY)); __TERMINAL: return pEntry; }
/* Show out NAT session table. */ static void ShowNatSession(__NAT_MANAGER* pMgr, size_t ss_num) { size_t top = ss_num; __EASY_NAT_ENTRY* pEntry = NULL; int show_cnt = 0; BUG_ON(NULL == pMgr); if (0 == top) { top = MAX_DWORD_VALUE; } WaitForThisObject(NatManager.lock); pEntry = NatManager.entryList.pNext; while (pEntry != &NatManager.entryList) { top--; ShowNatEntry(pEntry); show_cnt++; if (0 == top) { break; } pEntry = pEntry->pNext; } ReleaseMutex(NatManager.lock); _hx_printf("[%d] NAT entries showed.\r\n", show_cnt); return; }
//System call entry point. BOOL SyscallHandler(LPVOID lpEsp,LPVOID lpParam) { __SYSCALL_PARAM_BLOCK* pspb = (__SYSCALL_PARAM_BLOCK*)lpEsp; SYSCALL_ENTRY pScEntry = NULL; if(NULL == lpEsp || pspb->dwSyscallNum >= SYSCALL_MAX_COUNT) { PrintLine("SyscallHandler error"); return FALSE; } //_hx_printf("call num=%X\r\n",pspb->dwSyscallNum); pScEntry = s_szScCallArray[pspb->dwSyscallNum]; if(pScEntry) { pScEntry(pspb); } else if(!DispatchToModule(lpEsp,NULL)) { _hx_printf("SyscallHandler: Unknown system call[num = 0x%0X] raised.\r\n", pspb->dwSyscallNum); } return TRUE; }
//Delivery a Ethernet Frame to this protocol,a dedicated L3 interface is also provided. BOOL lwipDeliveryFrame(__ETHERNET_BUFFER* pEthBuff, LPVOID pL3Interface) { struct netif* pIf = (struct netif*)pL3Interface; struct pbuf* p, *q; int i = 0; if ((NULL == pEthBuff) | (NULL == pL3Interface)) { BUG(); } //Validate Ethernet buffer object. if (pEthBuff->act_length > pEthBuff->buff_length) { BUG(); } p = pbuf_alloc(PBUF_RAW, pEthBuff->act_length, PBUF_POOL); if (NULL == p) { _hx_printf(" %s:allocate pbuf object failed.\r\n", __func__); return FALSE; } i = 0; for (q = p; q != NULL; q = q->next) { memcpy((u8_t*)q->payload, &pEthBuff->Buffer[i], q->len); i = i + q->len; } //Delivery the packet to IP layer. pIf->input(p, pIf); return TRUE; }
//Implementation of _fat32GetFileAttributes. static DWORD _fat32GetFileAttributes(__COMMON_OBJECT* lpDev, LPCTSTR pszFileName) //Get file's attribute. { __FAT32_FS* pFat32Fs = NULL; CHAR FileName[MAX_FILE_NAME_LEN]; __FAT32_SHORTENTRY ShortEntry; DWORD dwFileAttributes = 0; if((NULL == pszFileName) || (NULL == lpDev)) { goto __TERMINAL; } pFat32Fs = (__FAT32_FS*)(((__DEVICE_OBJECT*)lpDev)->lpDevExtension); //strcpy(FileName,(LPSTR)lpDrcb->lpInputBuffer); StrCpy((CHAR*)pszFileName,FileName); ToCapital(FileName); if(!GetDirEntry(pFat32Fs,&FileName[0],&ShortEntry,NULL,NULL)) { _hx_printf("In _fat32GetFileAttributes: Can not get directory entry.\n%s\n",FileName); goto __TERMINAL; } dwFileAttributes = ShortEntry.FileAttributes; __TERMINAL: return dwFileAttributes; }
//Add one ethernet interface to the network protocol.The state of the //layer3 interface will be returned and be saved into pEthInt object. LPVOID lwipAddEthernetInterface(__ETHERNET_INTERFACE* pEthInt) { static int ifIndex = 0; struct netif* pIf = NULL; ip_addr_t ipAddr, ipMask, ipGw; //Allocate layer 3 interface for this ethernet interface. pIf = (struct netif*)KMemAlloc(sizeof(struct netif), KMEM_SIZE_TYPE_ANY); if (NULL == pIf) { _hx_printf(" Allocate netif failed.\r\n"); return NULL; } memset(pIf, 0, sizeof(struct netif)); pIf->state = pEthInt; //Point to the layer 2 interface. //Initialize name of layer 3 interface,since it only occupies 2 bytes. pIf->name[0] = pEthInt->ethName[0]; pIf->name[1] = pEthInt->ethName[1]; //Convert common network address to IPv4 address. ipAddr.addr = pEthInt->ifState.IpConfig.ipaddr.Address.ipv4_addr; ipMask.addr = pEthInt->ifState.IpConfig.mask.Address.ipv4_addr; ipGw.addr = pEthInt->ifState.IpConfig.mask.Address.ipv4_addr; //Add the netif to lwIP. netif_add(pIf, &ipAddr, &ipMask,&ipGw,pEthInt,_ethernet_if_init, &tcpip_input); if (0 == ifIndex) { netif_set_default(pIf); ifIndex += 1; } return pIf; }
/* Start a PPPoE session by specifying the instance. */ static BOOL StartPPPoE(__PPPOE_INSTANCE* pInstance) { BOOL bResult = FALSE; static int first_time = 0; enum pppAuthType auth = PPPAUTHTYPE_ANY; struct netif* pIf = NULL; BUG_ON(NULL == pInstance); if (pInstance->status != SESSION_IDLE) { goto __TERMINAL; } if (!first_time) /* Should initialize PPP stack of lwIP. */ { pppInit(); //first_time = 1; } /* Convert authentication type to lwIP defined. */ switch (pInstance->authType) { case PPPOE_AUTH_ANY: auth = PPPAUTHTYPE_ANY; break; case PPPOE_AUTH_NONE: auth = PPPAUTHTYPE_NONE; break; case PPPOE_AUTH_PAP: auth = PPPAUTHTYPE_PAP; break; case PPPOE_AUTH_CHAP: auth = PPPAUTHTYPE_CHAP; break; default: BUG(); } /* Set authentication type for the instance. */ pppSetAuth(auth, pInstance->user_name, pInstance->password); /* Locate the lwIP netif. */ pIf = pInstance->pEthInt->Proto_Interface[0].pL3Interface; /* Start PPPoE session. */ pInstance->ppp_session_id = pppOverEthernetOpen(pIf, NULL, NULL, pppoeStatusCallback, NULL); if (pInstance->ppp_session_id < 0) { _hx_printf("Failed to start PPPoE session,err = %d.\r\n", pInstance->ppp_session_id); goto __TERMINAL; } /* Start PPPoE OK. */ pInstance->status = SESSION_RUNNING; bResult = TRUE; __TERMINAL: return bResult; }
/* Just return the base address of device configure space. */ void* pci_map_bar(__PHYSICAL_DEVICE* pdev, DWORD dwOffset, DWORD dwFlags) { int index; void* memaddr_start = NULL; void* memaddr_end = NULL; void* vir_mem = NULL; BUG_ON(dwOffset != PCI_CONFIG_OFFSET_BASE1); for (index = 0; index < MAX_RESOURCE_NUM; index++) { if (pdev->Resource[index].dwResType == RESOURCE_TYPE_MEMORY) { memaddr_start = pdev->Resource[index].Dev_Res.MemoryRegion.lpStartAddr; memaddr_end = pdev->Resource[index].Dev_Res.MemoryRegion.lpEndAddr; break; } } BUG_ON(NULL == memaddr_start); BUG_ON(NULL == memaddr_end); /* * Map the PCI config address space to memory. */ vir_mem = memaddr_start; #ifdef __CFG_SYS_VMM vir_mem = VirtualAlloc(memaddr_start, (char*)memaddr_end - (char*)memaddr_start, VIRTUAL_AREA_ALLOCATE_IO, VIRTUAL_AREA_ACCESS_RW, "E1000_VIR"); if (NULL == vir_mem) { _hx_printf("%s:map PCI addr[start = 0x%X,end = 0x%X] failed.\r\n", __func__, memaddr_start, memaddr_end); } else { BUG_ON(vir_mem != memaddr_start); _hx_printf("%s:Map config space to[0x%X].\r\n", __func__, vir_mem); } #endif return vir_mem; }
static void _wpa_hexdump(int level, const char *title, const u8 *buf, size_t len, int show) { size_t i; if (level < wpa_debug_level) return; _hx_printf("%s - hexdump(len=%lu):", title, (unsigned long) len); if (buf == NULL) { _hx_printf(" [NULL]"); } else if (show) { for (i = 0; i < len; i++) _hx_printf(" %02x", buf[i]); } else { _hx_printf(" [REMOVED]"); } _hx_printf("\n"); }
void lbs_hex(unsigned int grp, const char *prompt, u8 *buf, int len) { int i = 0; _hx_printf(" lbs_hex: prompt = %s,buf = 0x%08X,len = %d.\r\n",prompt,buf,len); if (len ) { for (i = 1; i <= len; i++) { if ((i & 0xf) == 1) { if (i != 1) _hx_printf("\n"); printk("marvell" " %s: ", prompt); } _hx_printf("%02x ", (u8) * buf); buf++; } _hx_printf("\n"); } }
void wpa_printf(int level, char *fmt, ...) { va_list ap; va_start(ap, fmt); if (level >= wpa_debug_level) { //vprintf(fmt, ap); _hx_printf("\n"); } va_end(ap); }
static DWORD Process2(LPVOID pData) { int i = 0; for(i = 0;i < 5;i ++) { _hx_printf(" I'm process 2.\r\n"); DumpProcess(); Sleep(20); } return 0; }
//Scan USB devices in system to find USB Keyboard device. static BOOL ScanUsbKeyboard() { __PHYSICAL_DEVICE* pPhyDev = NULL; struct usb_device* pUsbDev = NULL; struct usb_interface* pUsbInt = NULL; struct usb_endpoint_descriptor* pED = NULL; __IDENTIFIER id = { 0 }; BOOL bResult = FALSE; //Initialize id accordingly. id.dwBusType = BUS_TYPE_USB; id.Bus_ID.USB_Identifier.ucMask = USB_IDENTIFIER_MASK_INTERFACECLASS; id.Bus_ID.USB_Identifier.ucMask |= USB_IDENTIFIER_MASK_INTERFACESUBCLASS; id.Bus_ID.USB_Identifier.ucMask |= USB_IDENTIFIER_MASK_INTERFACEPROTOCOL; id.Bus_ID.USB_Identifier.bInterfaceClass = UM_INTERFACE_CLASS_ID; id.Bus_ID.USB_Identifier.bInterfaceSubClass = UM_INTERFACE_SUBCLASS_ID; id.Bus_ID.USB_Identifier.bInterfaceProtocol = UM_INTERFACE_PROTOCOL_ID; //Try to find the USB mouse device from system. pPhyDev = USBManager.GetUsbDevice(&id, NULL); if (NULL == pPhyDev) { goto __TERMINAL; } //Make farther check according HID spec. pUsbDev = (struct usb_device*)pPhyDev->lpPrivateInfo; if (NULL == pUsbDev) { BUG(); goto __TERMINAL; } pUsbInt = &pUsbDev->config.if_desc[pPhyDev->dwNumber & 0xFFFF]; if (pUsbInt->desc.bNumEndpoints != 1) { goto __TERMINAL; } pED = &pUsbInt->ep_desc[0]; if (!(pED->bEndpointAddress & 0x80)) { goto __TERMINAL; } //Found the USB mouse device. _hx_printf("Found USB keyboard device:mf = [%s].\r\n", pUsbDev->mf); pUsbKeyboardDev = pPhyDev; bResult = TRUE; __TERMINAL: return bResult; }
// //The following routine prints out bug's information. // VOID __BUG(LPSTR lpszFileName,DWORD dwLineNum) { DWORD dwFlags; //Print out fatal error information. _hx_printf("\r\nBUG oencountered.\r\nFile name: %s\r\nCode Lines:%d",lpszFileName,dwLineNum); //Enter infinite loop. __ENTER_CRITICAL_SECTION(NULL,dwFlags); while(TRUE); __LEAVE_CRITICAL_SECTION(NULL,dwFlags); }
/* Entry point of the text mode shell. */ DWORD ShellEntryPoint(LPVOID pData) { StrCpy(DEF_PROMPT_STR,&s_szPrompt[0]); _hx_printf("\r\n"); _hx_printf("%s\r\n",HELLOX_VERSION_INFO); _hx_printf("\r\n"); Shell_Msg_Loop(s_szPrompt,CommandParser,QueryCmdName); /* * When reach here,it means the shell thread will terminate.We will reboot * the system in current version's implementation,since there is no interact * mechanism between user and computer in case of no shell. * NOTE:System clean up operations should be put here if necessary. */ #ifdef __I386__ BIOSReboot(); #endif return 0; }
/* Show out bug information. */ VOID __BUG(LPSTR lpszFileName,DWORD dwLineNum) { DWORD dwFlags; unsigned int processor_id = __CURRENT_PROCESSOR_ID; __KERNEL_THREAD_OBJECT* pKernelThread = __CURRENT_KERNEL_THREAD; /* Show general bug info. */ _hx_printk("\r\nBUG encountered[curr_processor = %d].\r\n",processor_id); _hx_printk("File name : %s\r\nCode Lines : %d\r\n",lpszFileName,dwLineNum); /* Show out specific information according current execution context. */ if (IN_INTERRUPT()) { /* Show interrupt related information. */ _hx_printk("In interrupt context,vector:%d.\r\n", System.ucCurrInt[processor_id]); /* Show out interrupted kernel thread information. */ if (pKernelThread) { _hx_printk("Interrupted kernel thread:%s\r\n", pKernelThread->KernelThreadName); } } else if (IN_SYSINITIALIZATION()) { /* In process of system initialization. */ _hx_printf("In process of system initialization.\r\n"); } else { /* In normal thread context. */ _hx_printf("Current kthread: %s\r\n", __CURRENT_KERNEL_THREAD->KernelThreadName); } /* Current CPU dive into a halt state. */ __DISABLE_LOCAL_INTERRUPT(dwFlags); while (TRUE) { /* Enter halt state to save energy. */ HaltSystem(); } __RESTORE_LOCAL_INTERRUPT(dwFlags); }
int set_lookbackIpAddr(int cfgId) { //int sockfd; struct ifreq ifr; struct ifaliasreq ifra; struct sockaddr_in *sin; /* First get its old IP address */ memset(&ifr, 0, sizeof(ifr)); memset(&sin, 0, sizeof(sin)); strcpy(ifr.ifr_name, "lo0"); /* Then delete it */ memset(&ifra, 0, sizeof(ifra)); strncpy(ifra.ifra_name, "lo0", sizeof(ifra.ifra_name) - 1); ifra.ifra_addr = ifr.ifr_addr; /* if (ioctl(cfgId, SIOCDIFADDR, &ifra) < 0) { exit(4); } */ /* And now assign the new IP address */ sin = (struct sockaddr_in *)&ifra.ifra_addr; sin->sin_family = AF_INET; sin->sin_len = sizeof(struct sockaddr_in); sin->sin_addr.s_addr = bsd_inet_addr("127.0.0.1"); sin = (struct sockaddr_in *)&ifra.ifra_broadaddr; sin->sin_family = AF_INET; sin->sin_len = sizeof(struct sockaddr_in); sin->sin_addr.s_addr = 0xff000000; sin = (struct sockaddr_in *)&ifra.ifra_mask; sin->sin_family = AF_INET; sin->sin_len = sizeof(struct sockaddr_in); sin->sin_addr.s_addr = bsd_inet_addr("255.0.0.0"); if (bsdioctl(cfgId, SIOCAIFADDR, &ifra) < 0) { _hx_printf("%s %d\n", __FUNCTION__, __LINE__); return 0; exit(6); } return 0; }
//Wrapper of Java VM. static DWORD JvmEntryPoint(LPVOID pData) { __CMD_PARA_OBJ* pCmdParaObj = (__CMD_PARA_OBJ*)pData; if (NULL == pData) { _hx_printf(" No parameter specified.\r\n"); return 0; } //Call JVM's main entry. return jvm_main(pCmdParaObj->byParameterNum, pCmdParaObj->Parameter); }