int navilink_write_device(NavilinkDevice* device, uint8_t packet_type, const uint8_t* payload, size_t payload_length) { assert(device != NULL); uint8_t* buff = (void*)(&device->buffer[0]); memset(buff, 0, NAVILINK_MAX_PACKET_SIZE); int bytes = navilink_create_packet(buff, packet_type, payload, payload_length); if (bytes < 0) { navilink_set_current_error(device, bytes, NULL); return -1; } #if (__DEBUG_CMD) printf("WRITE:"); DumpHex(buff, bytes); #endif enum sp_return result = sp_blocking_write(device->serial_port, &device->buffer[0], bytes, 1000); if (result < 0) { goto manage_serial_error; } result = sp_drain(device->serial_port); if (result < 0) { goto manage_serial_error; } return 0; manage_serial_error: CATCH_LIBSERIAL_ERROR(device); return -1; }
/** Display some Memory-Mapped-IO memory. @param[in] Address The starting address to display. @param[in] Size The length of memory to display. **/ SHELL_STATUS DisplayMmioMemory( IN CONST VOID *Address, IN CONST UINTN Size ) { EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRbIo; EFI_STATUS Status; VOID *Buffer; SHELL_STATUS ShellStatus; ShellStatus = SHELL_SUCCESS; Status = gBS->LocateProtocol(&gEfiPciRootBridgeIoProtocolGuid, NULL, (VOID**)&PciRbIo); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle, L"dmem"); return (SHELL_NOT_FOUND); } Buffer = AllocateZeroPool(Size); if (Buffer == NULL) { return SHELL_OUT_OF_RESOURCES; } Status = PciRbIo->Mem.Read(PciRbIo, EfiPciWidthUint8, (UINT64)(UINTN)Address, Size, Buffer); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_ER), gShellDebug1HiiHandle, L"dmem"); ShellStatus = SHELL_NOT_FOUND; } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size); DumpHex(2, (UINTN)Address, Size, Buffer); } FreePool(Buffer); return (ShellStatus); }
int navilink_read_device(NavilinkDevice* device, NavilinkPacket* packet) { assert(device != NULL); uint8_t* buff = (void*)(&device->buffer[0]); memset(buff, 0, NAVILINK_MAX_PACKET_SIZE); enum sp_return result = sp_blocking_read(device->serial_port, buff, 4, 1000); if (result < 0) { goto manage_serial_error; } if (buff[0] != NAVILINK_PACK_START1 && buff[1] != NAVILINK_PACK_START2) { navilink_set_current_error(device, NAVILINK_ERROR_INVALID_START_BYTE, NULL); return -1; } uint16_t packet_length = 0; memcpy(&packet_length, &buff[2], 2); packet_length = _le16_to_host(packet_length); result = sp_blocking_read(device->serial_port, &buff[4], packet_length + 4, 1000); if (result < 0) { goto manage_serial_error; } #if (__DEBUG_CMD) printf("READ:"); DumpHex(buff, packet_length + 8); #endif return navilink_read_packet(packet, device->buffer); manage_serial_error: CATCH_LIBSERIAL_ERROR(device); return -1; }
EFI_DEVICE_PATH * DevicePathInstance ( IN OUT EFI_DEVICE_PATH **DevicePath, OUT UINTN *Size ) { EFI_DEVICE_PATH *Start, *Next, *DevPath; UINTN Count; DevPath = *DevicePath; Start = DevPath; if (!DevPath) { return NULL; } // // Check for end of device path type // for (Count = 0; ; Count++) { Next = NextDevicePathNode(DevPath); if (IsDevicePathEndType(DevPath)) { break; } if (Count > 01000) { // // BugBug: Debug code to catch bogus device paths // DEBUG((D_ERROR, "DevicePathInstance: DevicePath %x Size %d", *DevicePath, ((UINT8 *) DevPath) - ((UINT8 *) Start) )); DumpHex (0, 0, ((UINT8 *) DevPath) - ((UINT8 *) Start), Start); break; } DevPath = Next; } ASSERT (DevicePathSubType(DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE || DevicePathSubType(DevPath) == END_INSTANCE_DEVICE_PATH_SUBTYPE); // // Set next position // if (DevicePathSubType(DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) { Next = NULL; } *DevicePath = Next; // // Return size and start of device path instance // *Size = ((UINT8 *) DevPath) - ((UINT8 *) Start); return Start; }
static int file_process( void* p, uint8_t* file_data, int data_size, FilePosition position, bool upload) { FileContext* context; Packet *pkt = (Packet *)p; void *ssnptr = pkt->ssnptr; /* if both disabled, return immediately*/ if ((!file_type_id_enabled) && (!file_signature_enabled)) return 0; #if defined(DEBUG_MSGS) && !defined (REG_TEST) if (DEBUG_FILE & GetDebugLevel()) #endif #if defined(DEBUG_MSGS) || defined (REG_TEST) DumpHex(stdout, file_data, data_size); DEBUG_WRAP(DebugMessage(DEBUG_FILE, "stream pointer %p\n", ssnptr ););
BOOL UpdateSearchDataDlg(HWND hwndDlg, int sourceId, BOOL fBigEndian, BYTE *searchData, int *searchLen) { int idx; int searchType; // get the searchType from the datatype dropdown idx = (int)SendDlgItemMessage(hwndDlg, IDC_COMBO_DATATYPE, CB_GETCURSEL, 0, 0); searchType = (int)SendDlgItemMessage(hwndDlg, IDC_COMBO_DATATYPE, CB_GETITEMDATA, idx, 0); if(UpdateSearchData(GetDlgItem(hwndDlg, sourceId), searchType, fBigEndian, searchData, searchLen)) { DumpHex(GetDlgItem(hwndDlg, IDC_EDIT_PREVIEW), searchData, *searchLen); return TRUE; } else { SetDlgItemText(hwndDlg, IDC_EDIT_PREVIEW, TEXT("error")); return FALSE; } }
CTEST(dumphex, int) { const char *expectedStr = "01 00 00 00"; char *answerBuf = DumpHex(&structVal.intVal, sizeof(structVal.intVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); }
CTEST(dumphex, float) { const char *expectedStr = "00 00 80 3f"; char *answerBuf = DumpHex(&structVal.floatVal, sizeof(structVal.floatVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); }
/** Query all structures Data from SMBIOS table and Display the information to users as required display option. @param[in] QueryType Structure type to view. @param[in] QueryHandle Structure handle to view. @param[in] Option Display option: none,outline,normal,detail. @param[in] RandomView Support for -h parameter. @retval EFI_SUCCESS print is successful. @retval EFI_BAD_BUFFER_SIZE structure is out of the range of SMBIOS table. **/ EFI_STATUS SMBios64View ( IN UINT8 QueryType, IN UINT16 QueryHandle, IN UINT8 Option, IN BOOLEAN RandomView ) { UINT16 Handle; UINT8 *Buffer; UINT16 Length; UINTN Index; SMBIOS_STRUCTURE_POINTER SmbiosStruct; SMBIOS_TABLE_3_0_ENTRY_POINT *SMBiosTable; SMBiosTable = NULL; LibSmbios64BitGetEPS (&SMBiosTable); if (SMBiosTable == NULL) { ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_CANNOT_ACCESS_TABLE), gShellDebug1HiiHandle); return EFI_BAD_BUFFER_SIZE; } if (CompareMem (SMBiosTable->AnchorString, "_SM3_", 5) == 0) { // // Have got SMBIOS table // Smbios64BitPrintEPSInfo (SMBiosTable, Option); SmbiosMajorVersion = SMBiosTable->MajorVersion; SmbiosMinorVersion = SMBiosTable->MinorVersion; ShellPrintEx(-1,-1,L"=========================================================\n"); ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERY_STRUCT_COND), gShellDebug1HiiHandle); if (QueryType == STRUCTURE_TYPE_RANDOM) { ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE_RANDOM), gShellDebug1HiiHandle); } else { ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYTYPE), gShellDebug1HiiHandle, QueryType); } if (RandomView) { ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE_RANDOM), gShellDebug1HiiHandle); } else { ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_QUERYHANDLE), gShellDebug1HiiHandle, QueryHandle); } ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_SHOWTYPE), gShellDebug1HiiHandle); ShellPrintEx(-1,-1,GetShowTypeString (gShowType)); ShellPrintEx(-1,-1,L"\n\n"); /* // // Get internal commands, such as change options. // Status = WaitEnter (); if (EFI_ERROR (Status)) { if (Status == EFI_ABORTED) { return EFI_SUCCESS; } return Status; } */ // // Searching and display structure info // Handle = QueryHandle; for (Index = 0; Index < mNumberOfSmbios64BitStructures; Index++) { // // if reach the end of table, break.. // if (Handle == INVALID_HANDLE) { break; } // // handle then point to the next! // if (LibGetSmbios64BitStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) { break; } SmbiosStruct.Raw = Buffer; // // if QueryType==Random, print this structure. // if QueryType!=Random, but Hdr->Type==QueryType, also print it. // only if QueryType != Random and Hdr->Type != QueryType, skiped it. // if (QueryType != STRUCTURE_TYPE_RANDOM && SmbiosStruct.Hdr->Type != QueryType) { continue; } ShellPrintEx(-1,-1,L"\n=========================================================\n"); ShellPrintHiiEx(-1,-1,NULL, STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_TYPE_HANDLE_DUMP_STRUCT), gShellDebug1HiiHandle, SmbiosStruct.Hdr->Type, SmbiosStruct.Hdr->Handle ); ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_INDEX_LENGTH), gShellDebug1HiiHandle, Index, Length); // // Addr of structure in structure in table // ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, (UINTN) Buffer); DumpHex (0, 0, Length, Buffer); /* // // Get internal commands, such as change options. // Status = WaitEnter (); if (EFI_ERROR (Status)) { if (Status == EFI_ABORTED) { return EFI_SUCCESS; } return Status; } */ if (gShowType != SHOW_NONE) { // // Print structure information // SmbiosPrintStructure (&SmbiosStruct, gShowType); ShellPrintEx(-1,-1,L"\n"); /* // // Get internal commands, such as change options. // Status = WaitEnter (); if (EFI_ERROR (Status)) { if (Status == EFI_ABORTED) { return EFI_SUCCESS; } return Status; } */ } if (!RandomView) { break; } // // Support Execution Interrupt. // if (ShellGetExecutionBreakFlag ()) { return EFI_ABORTED; } } ShellPrintEx(-1,-1,L"\n=========================================================\n"); return EFI_SUCCESS; } return EFI_BAD_BUFFER_SIZE; }
free(answerBuf); } CTEST(dumphex, int) { const char *expectedStr = "01 00 00 00"; char *answerBuf = DumpHex(&structVal.intVal, sizeof(structVal.intVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); } CTEST(dumphex, float) { const char *expectedStr = "00 00 80 3f"; char *answerBuf = DumpHex(&structVal.floatVal, sizeof(structVal.floatVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); } CTEST(dumphex, double) { const char *expectedStr = "00 00 00 00 00 00 f0 3f"; char *answerBuf = DumpHex(&structVal.doubleVal, sizeof(structVal.doubleVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); } // YOUR UNIT TEST HERE CTEST(dumphex, struct) { const char *expectedStr = "48 65 6c 6c 6f 20 77 6f 72 6c 64"; char * answerBuf = DumpHex(&structVal.structVal, sizeof(structVal.structVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); }
VOID SEnvHardwareDevicePathEntry ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) /*++ Routine Description: Arguments: DevicePath - The device path Returns: --*/ { PCI_DEVICE_PATH *PciDevicePath; PCCARD_DEVICE_PATH *PcCardDevicePath; MEMMAP_DEVICE_PATH *MemMapDevicePath; CONTROLLER_DEVICE_PATH *ControllerDevicePath; VENDOR_DEVICE_PATH *VendorDevicePath; if (DevicePathType (DevicePath) != HW_PCI_DP) { return ; } // // Process hardware device path entry // switch (DevicePathSubType (DevicePath)) { case HW_PCI_DP: PciDevicePath = (PCI_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_FUNCTION_DEVICE), HiiEnvHandle, PciDevicePath->Function, PciDevicePath->Device ); break; case HW_PCCARD_DP: PcCardDevicePath = (PCCARD_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_FUNCTION_NUMBER), HiiEnvHandle, PcCardDevicePath->FunctionNumber ); break; case HW_MEMMAP_DP: MemMapDevicePath = (MEMMAP_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_MEMORY_TYPE), HiiEnvHandle, MemMapDevicePath->MemoryType, MemMapDevicePath->StartingAddress, MemMapDevicePath->EndingAddress ); break; case HW_CONTROLLER_DP: ControllerDevicePath = (CONTROLLER_DEVICE_PATH *) DevicePath; PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_CONTROLLER_NUMBER), HiiEnvHandle, ControllerDevicePath->Controller); break; case HW_VENDOR_DP: VendorDevicePath = (VENDOR_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_GUID), HiiEnvHandle, &VendorDevicePath->Guid ); if (DevicePathNodeLength (DevicePath) > sizeof (VENDOR_DEVICE_PATH)) { Print (L"\n"); DumpHex ( 7, 0, DevicePathNodeLength (DevicePath) - sizeof (VENDOR_DEVICE_PATH), VendorDevicePath + 1 ); } break; } // // End processing // }
VOID SEnvMediaDevicePathEntry ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) /*++ Routine Description: Arguments: DevicePath - The device path Returns: --*/ { HARDDRIVE_DEVICE_PATH *HardDriveDevicePath; CDROM_DEVICE_PATH *CDDevicePath; VENDOR_DEVICE_PATH *VendorDevicePath; FILEPATH_DEVICE_PATH *FilePath; MEDIA_PROTOCOL_DEVICE_PATH *MediaProtocol; MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset; if (DevicePathType (DevicePath) != MEDIA_DEVICE_PATH) { return ; } // // Process media device path entry // switch (DevicePathSubType (DevicePath)) { case MEDIA_HARDDRIVE_DP: HardDriveDevicePath = (HARDDRIVE_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_PARTITION_START_SIZE), HiiEnvHandle, HardDriveDevicePath->PartitionNumber, HardDriveDevicePath->PartitionStart, HardDriveDevicePath->PartitionSize ); break; case MEDIA_CDROM_DP: CDDevicePath = (CDROM_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_BOOTENTRY_START_SIZE), HiiEnvHandle, CDDevicePath->BootEntry, CDDevicePath->PartitionStart, CDDevicePath->PartitionSize ); break; case MEDIA_VENDOR_DP: VendorDevicePath = (VENDOR_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_GUID_G), HiiEnvHandle, &VendorDevicePath->Guid ); if (DevicePathNodeLength (DevicePath) > sizeof (VENDOR_DEVICE_PATH)) { Print (L"\n"); DumpHex ( 7, 0, DevicePathNodeLength (DevicePath) - sizeof (VENDOR_DEVICE_PATH), VendorDevicePath + 1 ); } break; case MEDIA_FILEPATH_DP: FilePath = (FILEPATH_DEVICE_PATH *) DevicePath; PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_FILE), HiiEnvHandle, FilePath->PathName); break; case MEDIA_PROTOCOL_DP: MediaProtocol = (MEDIA_PROTOCOL_DEVICE_PATH *) DevicePath; PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_PROTOCOL_2), HiiEnvHandle, &MediaProtocol->Protocol); break; case MEDIA_RELATIVE_OFFSET_RANGE_DP: Offset = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *) DevicePath; PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_OFFSET), HiiEnvHandle, Offset->StartingOffset, Offset->EndingOffset); }; // // End processing // }
EFI_STATUS InitializeComp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Command entry point. Compares the contents of two files. Arguments: ImageHandle The image handle. SystemTable The system table. Returns: EFI_SUCCESS - The command completed successfully EFI_INVALID_PARAMETER - Input command arguments error EFI_OUT_OF_RESOURCES - Out of memory Other - Misc error --*/ { CHAR16 **Argv; UINTN Argc; EFI_LIST_ENTRY File1List; EFI_LIST_ENTRY File2List; SHELL_FILE_ARG *File1Arg; SHELL_FILE_ARG *File2Arg; UINTN Size; UINTN ReadSize; UINT8 *File1Buffer; UINT8 *File2Buffer; UINTN NotTheSameCount; EFI_STATUS Status; UINTN Index; UINTN Count; UINTN Address; CHAR16 *ScanFile; CHAR16 *Useful; SHELL_ARG_LIST *Item; SHELL_VAR_CHECK_CODE RetCode; SHELL_VAR_CHECK_PACKAGE ChkPck; // // Local variable initializations // File1Arg = NULL; File2Arg = NULL; ReadSize = 0; File1Buffer = NULL; File2Buffer = NULL; Address = 0; InitializeListHead (&File1List); InitializeListHead (&File2List); ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); // // We are not being installed as an internal command driver, initialize // as an nshell app and run // EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Enable tab key which can pause the output // EnableOutputTabPause(); // // Register our string package with HII and return the handle to it. // If previously registered we will simply receive the handle // Status = LibInitializeStrings (&HiiCompHandle, STRING_ARRAY_NAME, &EfiCompGuid); if (EFI_ERROR (Status)) { return Status; } if (!EFI_PROPER_VERSION (0, 99)) { PrintToken ( STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT), HiiCompHandle, L"comp", EFI_VERSION_0_99 ); Status = EFI_UNSUPPORTED; goto Done; } Argv = SI->Argv; Argc = SI->Argc; RetCode = LibCheckVariables (SI, CompCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiCompHandle, L"comp", Useful); break; case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiCompHandle, L"comp", Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Done; } // // Out put help. // if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiCompHandle, L"comp"); Status = EFI_INVALID_PARAMETER; } else { PrintToken (STRING_TOKEN (STR_HELPINFO_COMP_VERBOSEHELP), HiiCompHandle); Status = EFI_SUCCESS; } goto Done; } // // Parse command line arguments // for (Index = 1; Index < Argc; Index += 1) { if (StrLen (Argv[Index]) == 0) { PrintToken (STRING_TOKEN (STR_COMP_ZERO_LENGTH_ARG), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } } // // verify number of arguments // if (ChkPck.ValueCount < 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiCompHandle, L"comp"); Status = EFI_INVALID_PARAMETER; goto Done; } else if (ChkPck.ValueCount > 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiCompHandle, L"comp"); Status = EFI_INVALID_PARAMETER; goto Done; } // // multiple files // Item = ChkPck.VarList; ScanFile = Item->VarStr; while (*ScanFile) { if ('*' == *ScanFile || '?' == *ScanFile) { break; } ScanFile++; } if (*ScanFile) { PrintToken (STRING_TOKEN (STR_COMP_FIRST_MULT_FILES), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } // // validate first file // Status = ShellFileMetaArg (Item->VarStr, &File1List); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, Item->VarStr, Status); goto Done; } // // empty list // if (IsListEmpty (&File1List)) { Status = EFI_NOT_FOUND; PrintToken (STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, Item->VarStr, Status); goto Done; } File1Arg = CR ( File1List.Flink, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE ); // // Open error // if (EFI_ERROR (File1Arg->Status) || !File1Arg->Handle) { PrintToken ( STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, File1Arg->FullName, File1Arg->Status ); Status = File1Arg->Status; goto Done; } // // directory // if (File1Arg->Info && (File1Arg->Info->Attribute & EFI_FILE_DIRECTORY)) { PrintToken (STRING_TOKEN (STR_COMP_FIRST_DIR), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } Item = Item->Next; // // multiple files // ScanFile = Item->VarStr; while (*ScanFile) { if ('*' == *ScanFile || '?' == *ScanFile) { break; } ScanFile++; } if (*ScanFile) { PrintToken (STRING_TOKEN (STR_COMP_SECOND_MULT_FILES), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } // // Validate second file // Status = ShellFileMetaArg (Item->VarStr, &File2List); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, Item->VarStr, Status); goto Done; } // // empty list // if (IsListEmpty (&File2List)) { Status = EFI_NOT_FOUND; PrintToken (STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, Item->VarStr, Status); goto Done; } File2Arg = CR ( File2List.Flink, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE ); // // open error // if (EFI_ERROR (File2Arg->Status) || !File2Arg->Handle) { PrintToken ( STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, File2Arg->FullName, File2Arg->Status ); Status = File2Arg->Status; goto Done; } // // directory // if (File2Arg->Info && (File2Arg->Info->Attribute & EFI_FILE_DIRECTORY)) { PrintToken (STRING_TOKEN (STR_COMP_SECOND_DIR), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } // // Allocate buffers for both files // File1Buffer = AllocatePool (BLOCK_SIZE); File2Buffer = AllocatePool (BLOCK_SIZE); if (!File1Buffer || !File2Buffer) { PrintToken (STRING_TOKEN (STR_COMP_OUT_OF_MEM), HiiCompHandle); Status = EFI_OUT_OF_RESOURCES; goto Done; } // // Compare files // PrintToken (STRING_TOKEN (STR_COMP_COMPARE), HiiCompHandle, File1Arg->FullName, File2Arg->FullName); // // Set positions to head // Status = File1Arg->Handle->SetPosition (File1Arg->Handle, 0); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_COMP_SET_FILE_ERROR), HiiCompHandle, File1Arg->FullName, Status); goto Done; } Status = File2Arg->Handle->SetPosition (File2Arg->Handle, 0); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_COMP_SET_FILE_ERROR), HiiCompHandle, File2Arg->FullName, Status); goto Done; } // // Read blocks one by one from both files and compare each pair of blocks // Size = BLOCK_SIZE; NotTheSameCount = 0; while (Size > 0 && NotTheSameCount < 10) { // // Break the execution? // if (GetExecutionBreak ()) { goto Done; } // // Read a block from first file // Size = BLOCK_SIZE; Status = File1Arg->Handle->Read ( File1Arg->Handle, &Size, File1Buffer ); if (EFI_ERROR (Status)) { PrintToken ( STRING_TOKEN (STR_COMP_READ_FILE_ERROR), HiiCompHandle, File1Arg->FullName, Status ); NotTheSameCount++; break; } // // Read a block from second file // ReadSize = BLOCK_SIZE; Status = File2Arg->Handle->Read ( File2Arg->Handle, &ReadSize, File2Buffer ); if (EFI_ERROR (Status)) { PrintToken ( STRING_TOKEN (STR_COMP_READ_FILE_ERROR), HiiCompHandle, File2Arg->FullName, Status ); NotTheSameCount++; break; } if (ReadSize != Size) { PrintToken ( STRING_TOKEN (STR_COMP_MISMATCH), HiiCompHandle, NotTheSameCount + 1 ); NotTheSameCount++; break; } // // Diff the buffer // for (Index = 0; (Index < Size) && (NotTheSameCount < 10); Index++) { if (File1Buffer[Index] != File2Buffer[Index]) { for (Count = 1; Count < 0x20 && (Index + Count) < Size; Count++) { if (File1Buffer[Index + Count] == File2Buffer[Index + Count]) { break; } } PrintToken (STRING_TOKEN (STR_COMP_DIFFERENCE_FILE1), HiiCompHandle, NotTheSameCount + 1, File1Arg->FullName); DumpHex (1, Address + Index, Count, &File1Buffer[Index]); PrintToken (STRING_TOKEN (STR_COMP_FILE2), HiiCompHandle, File2Arg->FullName); DumpHex (1, Address + Index, Count, &File2Buffer[Index]); Print (L"\n"); NotTheSameCount++; Index += Count - 1; } } Address += Size; } // // Results // if (!NotTheSameCount) { PrintToken (STRING_TOKEN (STR_COMP_NO_DIFFERENCE), HiiCompHandle); } else { PrintToken (STRING_TOKEN (STR_COMP_DIFFERENCE), HiiCompHandle); Status = EFI_ABORTED; } Done: if (File1Buffer) { FreePool (File1Buffer); } if (File2Buffer) { FreePool (File2Buffer); } ShellFreeFileList (&File1List); ShellFreeFileList (&File2List); LibCheckVarFreeVarList (&ChkPck); LibUnInitializeStrings (); // // Shell command always succeeds // return Status; }
void Loop(void) { char *tp; int sc; Init(); for (;;) { fprintf(stdout, "\n%s cmd: ", Redir); Buf[0] = '\0'; if (fgets(Buf, BUFSIZE, stdin) == NULL) continue; if ((tp = strtok(Buf, " ,.\t\n\r")) == NULL) continue; fputc('\n', stdout); switch (*tp) { case 'g': case 'G': DisplayControlSignals(); break; case 'r': case 'R': DumpReg(); break; case 'm': case 'M': if ((tp = strtok(NULL, " ,.\t\n\r")) == NULL) { DumpMemHex(0, MEMSIZE); } else { sc = (int) strtoul(tp, (char **) NULL, 10); if ((tp = strtok(NULL, " ,.\t\n\r")) == NULL) { DumpMemHex(sc, MEMSIZE); } else { DumpMemHex(sc, (int) strtoul(tp, (char **) NULL, 10)); } } break; case 's': case 'S': if ((tp = strtok(NULL, " ,.\t\n\r")) == NULL) sc = 1; else sc = (int) strtoul(tp, (char **) NULL, 10); while (sc-- > 0 && !Halt) Step(); fprintf(stdout, "%s step\n", Redir); break; case 'c': case 'C': while (!Halt) Step(); fprintf(stdout, "%s cont\n", Redir); break; case 'h': case 'H': fprintf(stdout, "%s %s\n", Redir, Halt ? "true" : "false"); break; case 'p': case 'P': rewind(FP); sc = 0; while (!feof(FP)) { if (fgets(Buf, BUFSIZE, FP)) fprintf(stdout, "%s % 5d %s", Redir, sc++, Buf); } break; case 'i': case 'I': fprintf(stdout, "%s %d\n", Redir, MEMSIZE); break; case 'd': case 'D': if ((tp = strtok(NULL, " ,.\t\n\r")) == NULL) { fprintf(stdout, "%s invalid cmd\n", Redir); break; } sc = (int) strtoul(tp, (char **) NULL, 10); if ((tp = strtok(NULL, " ,.\t\n\r")) == NULL) { fprintf(stdout, "%sinvalid cmd\n", Redir); break; } DumpHex(sc, (int) strtoul(tp, (char **) NULL, 10)); break; case 'x': case 'X': case 'q': case 'Q': fprintf(stdout, "%s quit\n", Redir); if (Redir == (char *) RedirPrefix) { fprintf(stdout, "%s%s\n", Redir, Redir); } return; default: fprintf(stdout, "%s invalid cmd\n", Redir); break; } if (Redir == (char *) RedirPrefix) { fprintf(stdout, "%s%s\n", Redir, Redir); } } }
int parse_request(unsigned char *preq, int len) { int rc = 0 ; int n ; int nelem ; unsigned char *pdesc ; int i ; int tableid ; int offset ; int index[9] ; int count ; int userid ; unsigned char username[11] ; unsigned char passwd[21] ; int pktsize ; int maxpkt ; int baud ; if (preq) { n = *preq ; pdesc = &wrongcode[0] ; if ((n >= REQ_IDENT) && (n <= REQ_WAIT)) { if ((pdesc = dsclookup(n)) != NULL) { switch(n) { case REQ_IDENT: TRACE("Request: %s\n", pdesc) ; break ; case REQ_READ: case REQ_PREADI1: case REQ_PREADI2: case REQ_PREADI3: case REQ_PREADI4: case REQ_PREADI5: case REQ_PREADI6: case REQ_PREADI7: case REQ_PREADI8: case REQ_PREADI9: nelem = n - REQ_READ ; TRACE("Request: %s\n", pdesc) ; tableid = preq[1] ; tableid = (tableid<<8) + preq[2] ; for (i=0; i < nelem; i++) { index[i] = preq[3+i*2] ; index[i] = (index[i]<<8) + preq[3+ i*2 + 1] ; if (i == 0) TRACE("Index=") ; TRACE("%d ", index[i]) ; } if (nelem > 0) { count = preq[3+nelem*2] ; count = (count<<8) + preq[3+nelem*2 + 1] ; TRACE("Tableid=%d Count=%d\n", tableid, count) ; } else { TRACE("Tableid=%d\n", tableid) ; } break ; case REQ_PREAD_DFLT: nelem = 0 ; TRACE("Request: %s\n", pdesc) ; break ; case REQ_PREAD_OFF: nelem = 0 ; TRACE("Request: %s\n", pdesc) ; tableid = preq[1] ; tableid = (tableid<<8) + preq[2] ; offset = preq[3] ; offset = (offset<<8) + preq[4] ; offset = (offset<<8) + preq[5] ; TRACE("\tTableID=%d, Offset=%d\n", tableid, offset) ; break ; case REQ_WRITE: case REQ_PWRITEI1: case REQ_PWRITEI2: case REQ_PWRITEI3: case REQ_PWRITEI4: case REQ_PWRITEI5: case REQ_PWRITEI6: case REQ_PWRITEI7: case REQ_PWRITEI8: case REQ_PWRITEI9: nelem = n - REQ_WRITE ; TRACE("Request: %s\n", pdesc) ; tableid = preq[1] ; tableid = (tableid<<8) + preq[2] ; for (i=0; i < nelem; i++) { index[i] = preq[3+i*2] ; index[i] = (index[i]<<8) + preq[3+ i*2 + 1] ; if (i == 0) TRACE("Index=") ; TRACE("%d ", index[i]) ; } count = preq[3+nelem*2] ; count = (count<<8) + preq[3+nelem*2 + 1] ; TRACE("Count=%d\n", count) ; DumpHex(&preq[3+nelem*2 + 2], count) ; break ; case REQ_PWRITE_OFF: nelem = 0 ; TRACE("Request: %s\n", pdesc) ; tableid = preq[1] ; tableid = (tableid<<8) + preq[2] ; offset = preq[3] ; offset = (offset<<8) + preq[4] ; offset = (offset<<8) + preq[5] ; count = preq[6] ; count = (count<<8) + preq[7] ; TRACE("\tTableID=%d, Offset=%d Count=%d\n", tableid, offset, count) ; DumpHex(&preq[8], count) ; break ; case REQ_LOGON: TRACE("Request: %s\n", pdesc) ; userid = preq[1] ; userid = (userid<<8) + preq[2] ; memcpy(&username[0], &preq[3], 10) ; username[10] = '\0' ; TRACE("\tUserID=%d, UserName=%s\n", userid, username) ; break ; case REQ_SECURITY: TRACE("Request: %s\n", pdesc) ; memcpy(&passwd[0], &preq[1], 20) ; passwd[20] = '\0' ; TRACE("\tPasswd=%s\n", passwd) ; break ; case REQ_LOGOFF: TRACE("Request: %s\n", pdesc) ; break ; case REQ_NEGOTIATE: case REQ_NEGBR1: case REQ_NEGBR2: case REQ_NEGBR3: case REQ_NEGBR4: case REQ_NEGBR5: case REQ_NEGBR6: case REQ_NEGBR7: case REQ_NEGBR8: case REQ_NEGBR9: case REQ_NEGBR10: case REQ_NEGBR11: nelem = n - REQ_NEGOTIATE ; TRACE("Request: %s\n", pdesc) ; pktsize = preq[1] ; pktsize = (pktsize << 8) + preq[2] ; maxpkt = preq[2] ; baud = preq[3] ; TRACE("\tpktsize=%d, maxpkt=%d, baud=%d\n", pktsize, maxpkt, baud) ; break ; case REQ_WAIT: TRACE("Request: %s\n", pdesc) ; TRACE("\tSeconds=%d\n", preq[1]) ; break ; case REQ_TERMINATE: TRACE("Request: %s\n", pdesc) ; break ; } } } else pdesc = &wrongcode[0] ; } return rc ; }
VOID SEnvMessagingDevicePathEntry ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath ) /*++ Routine Description: Arguments: DevicePath - The device path Returns: --*/ { ATAPI_DEVICE_PATH *AtapiDevicePath; SCSI_DEVICE_PATH *ScsiDevicePath; FIBRECHANNEL_DEVICE_PATH *FibreChannelDevicePath; F1394_DEVICE_PATH *F1394DevicePath; USB_DEVICE_PATH *UsbDevicePath; USB_CLASS_DEVICE_PATH *UsbClassDevicePath; I2O_DEVICE_PATH *I2ODevicePath; MAC_ADDR_DEVICE_PATH *MacAddrDevicePath; IPv4_DEVICE_PATH *IPv4DevicePath; IPv6_DEVICE_PATH *IPv6DevicePath; INFINIBAND_DEVICE_PATH *InfinibandDevicePath; UART_DEVICE_PATH *UartDevicePath; VENDOR_DEVICE_PATH *VendorDevicePath; UINTN HwAddressSize; UINTN Index; CHAR8 Parity; if (DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) { return ; } // // Process messaging device path entry // switch (DevicePathSubType (DevicePath)) { case MSG_ATAPI_DP: AtapiDevicePath = (ATAPI_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_ATAPI), HiiEnvHandle, AtapiDevicePath->PrimarySecondary ? L"Secondary" : L"Primary", AtapiDevicePath->SlaveMaster ? L"Slave" : L"Master", AtapiDevicePath->Lun ); break; case MSG_SCSI_DP: ScsiDevicePath = (SCSI_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_PUN_LUN), HiiEnvHandle, ScsiDevicePath->Pun, ScsiDevicePath->Lun ); break; case MSG_FIBRECHANNEL_DP: FibreChannelDevicePath = (FIBRECHANNEL_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_FIBRE_CHANNEL), HiiEnvHandle, FibreChannelDevicePath->WWN, FibreChannelDevicePath->Lun ); break; case MSG_1394_DP: F1394DevicePath = (F1394_DEVICE_PATH *) DevicePath; PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_GUID_2), HiiEnvHandle, F1394DevicePath->Guid); break; case MSG_USB_DP: UsbDevicePath = (USB_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_USB), HiiEnvHandle, UsbDevicePath->ParentPortNumber, UsbDevicePath->InterfaceNumber ); break; case MSG_USB_CLASS_DP: UsbClassDevicePath = (USB_CLASS_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_USB_CLASS), HiiEnvHandle, UsbClassDevicePath->VendorId, UsbClassDevicePath->ProductId ); PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_DEVICE), HiiEnvHandle, UsbClassDevicePath->DeviceClass, UsbClassDevicePath->DeviceSubClass, UsbClassDevicePath->DeviceProtocol ); break; case MSG_I2O_DP: I2ODevicePath = (I2O_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_I20), HiiEnvHandle, I2ODevicePath->Tid ); break; case MSG_MAC_ADDR_DP: MacAddrDevicePath = (MAC_ADDR_DEVICE_PATH *) DevicePath; HwAddressSize = sizeof (EFI_MAC_ADDRESS); if (MacAddrDevicePath->IfType == 0x01 || MacAddrDevicePath->IfType == 0x00) { HwAddressSize = 6; } PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_MAC), HiiEnvHandle); for (Index = 0; Index < HwAddressSize; Index++) { PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_ONE_VAR_X), HiiEnvHandle, MacAddrDevicePath->MacAddress.Addr[Index]); } Print (L")"); break; case MSG_IPv4_DP: IPv4DevicePath = (IPv4_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_LOCAL), HiiEnvHandle, IPv4DevicePath->LocalIpAddress.Addr[0], IPv4DevicePath->LocalIpAddress.Addr[1], IPv4DevicePath->LocalIpAddress.Addr[2], IPv4DevicePath->LocalIpAddress.Addr[3], IPv4DevicePath->LocalPort ); PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_REMOVE_IP), HiiEnvHandle, IPv4DevicePath->RemoteIpAddress.Addr[0], IPv4DevicePath->RemoteIpAddress.Addr[1], IPv4DevicePath->RemoteIpAddress.Addr[2], IPv4DevicePath->RemoteIpAddress.Addr[3], IPv4DevicePath->RemotePort ); PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_PROTOCOL), HiiEnvHandle, IPv4DevicePath->Protocol ); PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_SOURCE), HiiEnvHandle, IPv4DevicePath->StaticIpAddress ? L"Static" : L"DHCP" ); break; case MSG_IPv6_DP: IPv6DevicePath = (IPv6_DEVICE_PATH *) DevicePath; PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_NOT_AVAIL), HiiEnvHandle); break; case MSG_INFINIBAND_DP: InfinibandDevicePath = (INFINIBAND_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_MODE_GUID), HiiEnvHandle, InfinibandDevicePath->ServiceId, InfinibandDevicePath->TargetPortId ); PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_DEVICE_ID), HiiEnvHandle, InfinibandDevicePath->DeviceId ); break; case MSG_UART_DP: UartDevicePath = (UART_DEVICE_PATH *) DevicePath; switch (UartDevicePath->Parity) { case 0: Parity = 'D'; break; case 1: Parity = 'N'; break; case 2: Parity = 'E'; break; case 3: Parity = 'O'; break; case 4: Parity = 'M'; break; case 5: Parity = 'S'; break; default: Parity = 'x'; break; } if (UartDevicePath->BaudRate == 0) { PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_UART_DEFAULT), HiiEnvHandle, Parity); } else { PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_UART_D_C), HiiEnvHandle, UartDevicePath->BaudRate, Parity); } if (UartDevicePath->DataBits == 0) { Print (L" D"); } else { PrintToken (STRING_TOKEN (STR_SHELLENV_DPROT_ONE_VAR_D), HiiEnvHandle, UartDevicePath->DataBits); } switch (UartDevicePath->StopBits) { case 0: Print (L" D)"); break; case 1: Print (L" 1)"); break; case 2: Print (L" 1.5)"); break; case 3: Print (L" 2)"); break; default: Print (L" x)"); break; } break; case MSG_VENDOR_DP: VendorDevicePath = (VENDOR_DEVICE_PATH *) DevicePath; PrintToken ( STRING_TOKEN (STR_SHELLENV_DPROT_GUID_G), HiiEnvHandle, &VendorDevicePath->Guid ); if (DevicePathNodeLength (DevicePath) > sizeof (VENDOR_DEVICE_PATH)) { Print (L"\n"); DumpHex ( 7, 0, DevicePathNodeLength (DevicePath) - sizeof (VENDOR_DEVICE_PATH), VendorDevicePath + 1 ); } break; } // // End processing // }
CTEST(dumphex, double) { const char *expectedStr = "00 00 00 00 00 00 f0 3f"; char *answerBuf = DumpHex(&structVal.doubleVal, sizeof(structVal.doubleVal)); ASSERT_STR( expectedStr, answerBuf ); free(answerBuf); }
static int ReadData(int socket_fd, uint8_t *buffer, uint32_t length, unsigned long timeout_ms) { ssize_t numread; unsigned total = 0; fd_set socket_fd_set; do { struct timeval tv = {.tv_sec = timeout_ms / 1000, .tv_usec = (timeout_ms % 1000)*1000}; FD_ZERO(&socket_fd_set); FD_SET(socket_fd,&socket_fd_set); const int select_result = select(socket_fd+1,&socket_fd_set,NULL,NULL,&tv); if(select_result <= 0) return -1; else if(select_result == 0) return 0; numread = read(socket_fd, buffer + total, length - total); if (!numread) return 0; else if (numread > 0) total += numread; else if (errno != EINTR && errno != EAGAIN) return -1; } while (total < length); if (total < length) return 0; return 1; } static int ReadResponse(int socket_fd, CSMessageHeader *hdr, int timeout_ms) { const int rc = ReadData(socket_fd,(uint8_t *)hdr,sizeof(*hdr),timeout_ms); if(rc > 0){ hdr->length = ntohl(hdr->length); hdr->version = ntohs(hdr->version); hdr->type = ntohs(hdr->type); } return rc; } static void ConnectToUnixSocket(const char * const name, int * const psock) { struct sockaddr_un sunaddr; int sock = -1; int rval; memset(&sunaddr, 0, sizeof(sunaddr)); rval = snprintf(sunaddr.sun_path, sizeof(sunaddr.sun_path), "%s", name); if (rval < 0 || (size_t)rval >= sizeof(sunaddr.sun_path)) { fprintf(stderr, "Socket name '%s' is too long\n", name); exit(-1); } sunaddr.sun_family = AF_UNIX; /* open the socket */ if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { fprintf(stderr, "Error opening socket: %s\n", strerror(errno)); exit(-1); } if (connect(sock, (struct sockaddr *) &sunaddr, sizeof(sunaddr)) == -1) { fprintf(stderr, "Unable to connect to UNIX socket at %s: %s\n", name, strerror(errno)); close(sock); exit(-1); } *psock = sock; } int main(int argc, char *argv[]) { int rval; char socket_fn[PATH_MAX]; int socket_fd; CSMessage *message; const unsigned long type = 1361; const char *sep; ssize_t len; PrintMode mode = PRINT_MODE_FAST; unsigned int timeout_ms = 0; if (argc != 4 || !*argv[1] || !*argv[2] || !*argv[3]) { DisplayUsage(argv[0]); exit(-1); } else if (argc > 2) { int idx = 2; if((strlen(TIMEOUT_KEYWORD) == strlen(argv[idx])) && (strcmp(TIMEOUT_KEYWORD,argv[idx]) == 0)) { mode = PRINT_MODE_FAST; idx ++; } if (argc > idx) { timeout_ms = atoi(argv[idx]); } } len = strlen(argv[1]); if (len && argv[1][len - 1] == '/') sep = ""; else sep = "/"; snprintf(socket_fn, sizeof(socket_fn), "%s%s%s", argv[1], sep, CONTROL_FILE); ConnectToUnixSocket(socket_fn, &socket_fd); message = malloc(sizeof *message); if (message == NULL) { fprintf(stderr, "%s: could not allocate message.\n",argv[0]); exit(-1); } message->hdr.version = htons(CS_HEADER_VERSION); message->hdr.type = htons((uint16_t)type); message->hdr.length = 0; if ((rval = SendMessage(socket_fd, message)) < 0) { fprintf(stderr, "Failed to send the message: %s\n", strerror(errno)); close(socket_fd); exit(-1); } else if (!rval) { fprintf(stderr, "Server closed the socket\n"); close(socket_fd); exit(-1); } if ((rval = ReadResponse(socket_fd, &message->hdr,timeout_ms)) < 0) { fprintf(stderr, "Failed to read the response: %s\n", strerror(errno)); close(socket_fd); exit(-1); } else if (!rval) { fprintf(stderr, "Server closed the socket before sending a response\n"); close(socket_fd); exit(-1); } if (message->hdr.version != CS_HEADER_VERSION) { printf("%s: bad response version\n",argv[0]); close(socket_fd); exit(-1); } if (message->hdr.type != 9) { printf("%s: bad response type:%d, expected %d",argv[0],message->hdr.type,9); close(socket_fd); exit(-1); } if (message->hdr.length) { if (message->hdr.length < sizeof(message->msg_hdr)) { printf("%s: response message is too small\n",argv[0]); close(socket_fd); exit(-1); } if (message->hdr.length > sizeof(message->msg)) { printf("%s: response message is too large\n",argv[0]); close(socket_fd); exit(-1); } if ((rval = ReadData(socket_fd, (uint8_t *)message+sizeof(message->hdr), message->hdr.length, timeout_ms)) < 0) { fprintf(stderr, "Failed to read the response data: %s\n", strerror(errno)); close(socket_fd); exit(-1); } else if (!rval) { fprintf(stderr, "Server closed the socket before sending the response data\n"); close(socket_fd); exit(-1); } message->msg_hdr.code = ntohl(message->msg_hdr.code); message->msg_hdr.length = ntohs(message->msg_hdr.length); if (mode == PRINT_MODE_DETAIL) { fprintf(stdout, "Response %04X with code %d and length %u\n", message->hdr.type, message->msg_hdr.code, message->msg_hdr.length); DumpHex(stdout, message->msg, message->msg_hdr.length); } else if (mode == PRINT_MODE_FAST) { if (message->msg_hdr.length == message->hdr.length - sizeof(message->msg_hdr)) { message->msg[message->msg_hdr.length-1] = 0; fprintf(stdout, "Response %04X with code %d (%s)\n", message->hdr.type, message->msg_hdr.code, message->msg); } else fprintf(stdout, "Response %04X with code %d\n", message->hdr.type, message->msg_hdr.code); } } else { if (mode == PRINT_MODE_DETAIL) printf("Response %04X without data\n", message->hdr.type); else printf("Response %04X\n", message->hdr.type); } return 0; }
/** Dump PCD info. @param[in] TokenSpace PCD Token Space. @param[in] TokenNumber PCD Token Number. @param[in] PcdInfo Pointer to PCD info. **/ static VOID DumpPcdInfo ( IN CONST EFI_GUID *TokenSpace, IN UINTN TokenNumber, IN EFI_PCD_INFO *PcdInfo ) { CHAR16 *RetString; UINT8 Uint8; UINT16 Uint16; UINT32 Uint32; UINT64 Uint64; BOOLEAN Boolean; VOID *PcdData; RetString = NULL; if (PcdInfo->PcdName != NULL) { Print (L"%a\n", PcdInfo->PcdName); } else { if (TokenSpace == NULL) { Print (L"Default Token Space\n"); } else { Print (L"%g\n", TokenSpace); } } RetString = GetPcdTypeString (TokenSpace, PcdInfo->PcdType); switch (PcdInfo->PcdType) { case EFI_PCD_TYPE_8: if (TokenSpace == NULL) { Uint8 = mPcd->Get8 (TokenNumber); } else { Uint8 = mPiPcd->Get8 (TokenSpace, TokenNumber); } Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint8); break; case EFI_PCD_TYPE_16: if (TokenSpace == NULL) { Uint16 = mPcd->Get16 (TokenNumber); } else { Uint16 = mPiPcd->Get16 (TokenSpace, TokenNumber); } Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint16); break; case EFI_PCD_TYPE_32: if (TokenSpace == NULL) { Uint32 = mPcd->Get32 (TokenNumber); } else { Uint32 = mPiPcd->Get32 (TokenSpace, TokenNumber); } Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint32); break; case EFI_PCD_TYPE_64: if (TokenSpace == NULL) { Uint64 = mPcd->Get64 (TokenNumber); } else { Uint64 = mPiPcd->Get64 (TokenSpace, TokenNumber); } Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%lx\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint64); break; case EFI_PCD_TYPE_BOOL: if (TokenSpace == NULL) { Boolean = mPcd->GetBool (TokenNumber); } else { Boolean = mPiPcd->GetBool (TokenSpace, TokenNumber); } Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = %a\n", TokenNumber, RetString, PcdInfo->PcdSize, Boolean ? "TRUE" : "FALSE"); break; case EFI_PCD_TYPE_PTR: if (TokenSpace == NULL) { PcdData = mPcd->GetPtr (TokenNumber); } else { PcdData = mPiPcd->GetPtr (TokenSpace, TokenNumber); } Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize); DumpHex (2, 0, PcdInfo->PcdSize, PcdData); break; default: return; } if (RetString != NULL) { FreePool (RetString); } Print (L"\n"); }
/** Function for 'dmem' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunDmem ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; VOID *Address; UINT64 Size; CONST CHAR16 *Temp1; UINT64 AcpiTableAddress; UINT64 Acpi20TableAddress; UINT64 SalTableAddress; UINT64 SmbiosTableAddress; UINT64 MpsTableAddress; UINTN TableWalker; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; Address = NULL; Size = 0; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"dmem", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) > 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"dmem"); ShellStatus = SHELL_INVALID_PARAMETER; } else { Temp1 = ShellCommandLineGetRawValue(Package, 1); if (Temp1 == NULL) { Address = gST; Size = sizeof (*gST); } else { if (!ShellIsHexOrDecimalNumber(Temp1, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp1, (UINT64*)&Address, TRUE, FALSE))) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); ShellStatus = SHELL_INVALID_PARAMETER; } Temp1 = ShellCommandLineGetRawValue(Package, 2); if (Temp1 == NULL) { Size = 512; } else { if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp1, &Size, TRUE, FALSE))) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"dmem", Temp1); ShellStatus = SHELL_INVALID_PARAMETER; } } } } if (ShellStatus == SHELL_SUCCESS) { if (!ShellCommandLineGetFlag(Package, L"-mmio")) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size); DumpHex(2, (UINTN)Address, (UINTN)Size, Address); if (Address == (VOID*)gST) { Acpi20TableAddress = 0; AcpiTableAddress = 0; SalTableAddress = 0; SmbiosTableAddress = 0; MpsTableAddress = 0; for (TableWalker = 0 ; TableWalker < gST->NumberOfTableEntries ; TableWalker++) { if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi20TableGuid)) { Acpi20TableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable; continue; } if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiAcpi10TableGuid)) { AcpiTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable; continue; } if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSalSystemTableGuid)) { SalTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable; continue; } if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSmbiosTableGuid)) { SmbiosTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable; continue; } if (CompareGuid (&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiSmbios3TableGuid)) { SmbiosTableAddress = (UINT64) (UINTN) gST->ConfigurationTable[TableWalker].VendorTable; continue; } if (CompareGuid(&gST->ConfigurationTable[TableWalker].VendorGuid, &gEfiMpsTableGuid)) { MpsTableAddress = (UINT64)(UINTN)gST->ConfigurationTable[TableWalker].VendorTable; continue; } } ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_SYSTEM_TABLE), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, gST->Hdr.HeaderSize, gST->Hdr.Revision, (UINT64)(UINTN)gST->ConIn, (UINT64)(UINTN)gST->ConOut, (UINT64)(UINTN)gST->StdErr, (UINT64)(UINTN)gST->RuntimeServices, (UINT64)(UINTN)gST->BootServices, SalTableAddress, AcpiTableAddress, Acpi20TableAddress, MpsTableAddress, SmbiosTableAddress ); } } else { ShellStatus = DisplayMmioMemory(Address, (UINTN)Size); } } ShellCommandLineFreeVarList (Package); } return (ShellStatus); }
int main(int argc, char *argv[]) { int rval; char socket_fn[PATH_MAX]; int socket_fd; char *p; CSMessage *message; unsigned long type; const char *sep; ssize_t len; PrintMode mode = PRINT_MODE_DETAIL; const char *extra; unsigned int extra_len = 0; if (argc < 3 || argc > 5 || !*argv[1] || !*argv[2]) { DisplayUsage(argv[0]); exit(-1); } else if (argc > 3) { int idx = 3; if((strlen(PRINT_MODE_FAST_KEYWORD) == strlen(argv[idx])) && (strcmp(PRINT_MODE_FAST_KEYWORD,argv[idx]) == 0)) { mode = PRINT_MODE_FAST; idx ++; } if (argc > idx) { extra = argv[idx]; extra_len = strlen(extra) + 1; } } type = strtoul(argv[2], &p, 0); if (*p || type > CS_TYPE_MAX) { DisplayUsage(argv[0]); exit(-1); } len = strlen(argv[1]); if (len && argv[1][len - 1] == '/') sep = ""; else sep = "/"; snprintf(socket_fn, sizeof(socket_fn), "%s%s%s", argv[1], sep, CONTROL_FILE); ConnectToUnixSocket(socket_fn, &socket_fd); if (extra_len > sizeof(message->msg)) { fprintf(stderr, "snort_control: message is too long.\n"); exit(-1); } message = malloc(sizeof *message); if (message == NULL) { fprintf(stderr, "snort_control: could not allocate message.\n"); exit(-1); } message->hdr.version = htons(CS_HEADER_VERSION); message->hdr.type = htons((uint16_t)type); message->hdr.length = 0; if (extra_len) { message->hdr.length = htonl(extra_len + sizeof(message->msg_hdr)); message->msg_hdr.code = 0; message->msg_hdr.length = htons(extra_len); memcpy(message->msg, extra, extra_len); } if ((rval = SendMessage(socket_fd, message, extra_len)) < 0) { fprintf(stderr, "Failed to send the message: %s\n", strerror(errno)); close(socket_fd); exit(-1); } else if (!rval) { fprintf(stderr, "Server closed the socket\n"); close(socket_fd); exit(-1); } do { /* Reusing the same CSMessage to capture the response */ if ((rval = ReadResponse(socket_fd, &message->hdr)) < 0) { fprintf(stderr, "Failed to read the response: %s\n", strerror(errno)); close(socket_fd); exit(-1); } else if (!rval) { fprintf(stderr, "Server closed the socket before sending a response\n"); close(socket_fd); exit(-1); } if (message->hdr.version != CS_HEADER_VERSION) { printf("snort_control: bad response version\n"); close(socket_fd); exit(-1); } if (message->hdr.length) { if (message->hdr.length < sizeof(message->msg_hdr)) { printf("snort_control: response message is too small\n"); close(socket_fd); exit(-1); } if (message->hdr.length > sizeof(message->msg)) { printf("snort_control: response message is too large\n"); close(socket_fd); exit(-1); } if ((rval = ReadData(socket_fd, (uint8_t *)message+sizeof(message->hdr), message->hdr.length)) < 0) { fprintf(stderr, "Failed to read the response data: %s\n", strerror(errno)); close(socket_fd); exit(-1); } else if (!rval) { fprintf(stderr, "Server closed the socket before sending the response data\n"); close(socket_fd); exit(-1); } message->msg_hdr.code = ntohl(message->msg_hdr.code); message->msg_hdr.length = ntohs(message->msg_hdr.length); if (mode == PRINT_MODE_DETAIL) { fprintf(stdout, "Response %04X with code %d and length %u\n", message->hdr.type, message->msg_hdr.code, message->msg_hdr.length); DumpHex(stdout, message->msg, message->msg_hdr.length); } else if (mode == PRINT_MODE_FAST) { if (message->msg_hdr.length == message->hdr.length - sizeof(message->msg_hdr)) { message->msg[message->msg_hdr.length-1] = 0; fprintf(stdout, "Response %04X with code %d (%s)\n", message->hdr.type, message->msg_hdr.code, message->msg); } else fprintf(stdout, "Response %04X with code %d\n", message->hdr.type, message->msg_hdr.code); } } else { if (mode == PRINT_MODE_DETAIL) printf("Response %04X without data\n", message->hdr.type); else printf("Response %04X\n", message->hdr.type); } } while (message->hdr.type == CS_HEADER_DATA); return 0; }
int parse_response(unsigned char *prsp, int len, int mrc) // mrc -- matching request code(zero means N/A) { int rc = 0 ; int n ; int nelem ; unsigned char *pdesc ; unsigned char *pdmrc ; int i ; int count ; int pktsize ; int maxpkt ; int baud ; if (prsp) { n = *prsp ; pdesc = &wrongcode[0] ; if ((n >= RSP_OK) && (n <= RSPNOK_ISSS)) { if ((pdesc = dsclookup(n)) != NULL) { if ((mrc < REQ_IDENT) || (mrc > REQ_WAIT) || ((pdmrc = dsclookup(mrc)) == NULL)) pdmrc = "Unmatched request" ; VTRACE("Response to: %s -- ", pdmrc) ; switch(n) { case RSP_OK: switch(mrc) { case REQ_IDENT: VTRACE("IDENT\n\tstd=%d, ver=%d, rev=%d\n", prsp[1], prsp[2], prsp[3]) ; break ; case REQ_READ: case REQ_PREADI1: case REQ_PREADI2: case REQ_PREADI3: case REQ_PREADI4: case REQ_PREADI5: case REQ_PREADI6: case REQ_PREADI7: case REQ_PREADI8: case REQ_PREADI9: nelem = mrc - REQ_READ ; if (nelem == 0) VTRACE("Full Read\n") ; else VTRACE("Partial Read_%d\n", nelem) ; count = prsp[1] ; count = (count<<8) + prsp[2] ; VTRACE("\tcount=%d\n", count) ; if (verbose) DumpHex(&prsp[3], count) ; rc = count ; break ; case REQ_PREAD_DFLT: nelem = 0 ; count = prsp[1] ; count = (count<<8) + prsp[2] ; VTRACE("Default Read\n") ; VTRACE("\tcount=%d\n", count) ; if (verbose) DumpHex(&prsp[3], count) ; rc = count ; break ; case REQ_PREAD_OFF: nelem = 0 ; count = prsp[1] ; count = (count<<8) + prsp[2] ; VTRACE("Partial Read_Offset\n") ; VTRACE("\tcount=%d\n", count) ; if (verbose) DumpHex(&prsp[3], count) ; rc = count ; break ; case REQ_WRITE: case REQ_PWRITEI1: case REQ_PWRITEI2: case REQ_PWRITEI3: case REQ_PWRITEI4: case REQ_PWRITEI5: case REQ_PWRITEI6: case REQ_PWRITEI7: case REQ_PWRITEI8: case REQ_PWRITEI9: nelem = mrc - REQ_WRITE ; if (nelem == 0) TRACE("Full Write\n") ; else TRACE("Partial Write_%d\n", nelem) ; break ; case REQ_PWRITE_OFF: TRACE("Partial Write_Offset\n") ; break ; case REQ_LOGON: break ; case REQ_SECURITY: break ; case REQ_LOGOFF: break ; case REQ_NEGOTIATE: case REQ_NEGBR1: case REQ_NEGBR2: case REQ_NEGBR3: case REQ_NEGBR4: case REQ_NEGBR5: case REQ_NEGBR6: case REQ_NEGBR7: case REQ_NEGBR8: case REQ_NEGBR9: case REQ_NEGBR10: case REQ_NEGBR11: nelem = mrc - REQ_NEGOTIATE ; TRACE("Negotiate_%d\n", nelem) ; pktsize = prsp[1] ; pktsize = (pktsize << 8) + prsp[2] ; maxpkt = prsp[2] ; baud = prsp[3] ; TRACE("\tpktsize=%d, maxpkt=%d, baud=%d\n", pktsize, maxpkt, baud) ; break ; case REQ_WAIT: TRACE("Wait\n") ; break ; case REQ_TERMINATE: TRACE("Terminate\n") ; break ; } break ; case RSPNOK_ERR: case RSPNOK_SNS: case RSPNOK_ISC: case RSPNOK_ONP: case RSPNOK_IAR: case RSPNOK_BSY: case RSPNOK_DNR: case RSPNOK_DLK: case RSPNOK_RNO: case RSPNOK_ISSS: TRACE("NOK Response: %s\n", pdesc) ; break ; } } } } return rc ; }
void DumpInfo(int thingToDump) { #ifndef _XBOX uint32 i; switch(thingToDump) { case DUMP_COLORS: DebuggerAppendMsg("----Colors----\nPrim Color:\t%08X\nEnv Color:\t%08X\n" "Fill Color:\t%08X\nFog Color:\t%08X\n" "Prim Depth:\t%f\nPrim LOD Frac:\t%08X\n", GetPrimitiveColor(), GetEnvColor(), gRDP.fillColor, CRender::GetRender()->GetFogColor(), GetPrimitiveDepth(), GetLODFrac()); break; case DUMP_CUR_MUX: CRender::GetRender()->m_pColorCombiner->DisplayMuxString(); break; case DUMP_LIGHT: DebuggerAppendMsg("----Light Colors----\nNumber of Lights: %d\n",GetNumLights()); for( i=0; i<GetNumLights()+2; i++) { DebuggerAppendMsg("Light %d:\t%08X, (%d,%d,%d)\n", i, gRSPn64lights[i].dwRGBA,gRSPn64lights[i].x,gRSPn64lights[i].y,gRSPn64lights[i].z ); } break; case DUMP_TEXTURE_AT: { int txt = GetInputHex(); if( txt < 8 ) DumpTexture(txt); } break; case DUMP_CUR_TEXTURE_RGBA: DumpTexture(gRSP.curTile, TXT_RGBA); break; case DUMP_CUR_1_TEXTURE_RGBA: DumpTexture((1+gRSP.curTile)%7, TXT_RGBA); break; case DUMP_CUR_TEXTURE_RGB: DumpTexture(gRSP.curTile, TXT_RGB); break; case DUMP_CUR_1_TEXTURE_RGB: DumpTexture((1+gRSP.curTile)%7, TXT_RGB); break; case DUMP_CUR_TEXTURE_TO_FILE: DumpTextureToFile(0,TXT_RGB); DumpTextureToFile(0,TXT_ALPHA); DumpTextureToFile(0,TXT_RGBA); break; case DUMP_CUR_1_TEXTURE_TO_FILE: DumpTextureToFile(1,TXT_RGB); DumpTextureToFile(1,TXT_ALPHA); DumpTextureToFile(1,TXT_RGBA); break; case DUMP_CUR_TEXTURE_ALPHA: DumpTexture(0, TXT_ALPHA); break; case DUMP_CUR_1_TEXTURE_ALPHA: DumpTexture(1, TXT_ALPHA); break; case DUMP_TLUT: DumpTlut(g_wRDPTlut); break; case DUMP_OBJ_TLUT: DumpTlut((uint16*)(g_pRDRAMu8+gObjTlutAddr)); break; case DUMP_TILE_AT: { int tile =GetInputHex(); if( tile < 8 ) DumpTileInfo(tile); } break; case DUMP_VERTEXES: DumpVertexArray(); break; case DUMP_VI_REGS: DumpVIRegisters(); break; case DUMP_SIMPLE_MUX: CRender::GetRender()->m_pColorCombiner->DisplaySimpleMuxString(); break; case DUMP_OTHER_MODE: DumpOtherMode(); break; case DUMP_FRAME_BUFFER: CRender::GetRender()->DrawFrameBuffer(true); break; case DUMP_CONTENT_AT: { uint32 addr=GetInputHex(); if( addr < g_dwRamSize ) { DumpHex(addr, min(32, g_dwRamSize-addr)); } } break; case DUMP_DLIST_AT: { uint32 addr=GetInputHex(); addr &= (g_dwRamSize-1); DumpDlistAt(addr); } break; case DUMP_MATRIX_AT: { uint32 addr=GetInputHex(); addr &= (g_dwRamSize-1); DumpMatrixAt(addr); } break; case DUMP_NEXT_TEX: CachedTexIndex++; if( CachedTexIndex >= gTextureManager.GetNumOfCachedTexture() ) { CachedTexIndex = 0; } DumpCachedTexture(CachedTexIndex); break; case DUMP_PREV_TEX: CachedTexIndex--; if( CachedTexIndex < 0 || CachedTexIndex >= gTextureManager.GetNumOfCachedTexture() ) CachedTexIndex = 0; DumpCachedTexture(CachedTexIndex); break; case DUMP_CACHED_TEX: DumpCachedTexture(CachedTexIndex); break; case DUMP_TEXBUFFER_AT: { int bufno = GetInputHex(); if( bufno < 20 ) DumpRenderTexture(bufno); } break; case DUMP_COMBINED_MATRIX: DumpMatrix2(gRSPworldProject,"Combined Matrix"); break; case DUMP_WORLD_TOP_MATRIX: DumpMatrix2(gRSP.modelviewMtxs[gRSP.modelViewMtxTop],"World Top Matrix"); break; case DUMP_WORLD_MATRIX_AT: { int mtxno = GetInputHex(); if( mtxno < 4 ) DumpMatrix2(gRSP.modelviewMtxs[0],"World Matrix #"); } break; case DUMP_PROJECTION_MATRIX: DumpMatrix2(gRSP.projectionMtxs[gRSP.projectionMtxTop],"Projection Top Matrix"); break; } #endif }
/** Display blocks to the screen. @param[in] DevPath The device path to get the blocks from. @param[in] Lba The Lba number to start from. @param[in] BlockCount How many blocks to display. @retval SHELL_SUCCESS The display was successful. **/ SHELL_STATUS EFIAPI DisplayTheBlocks( IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath, IN CONST UINT64 Lba, IN CONST UINT8 BlockCount ) { EFI_BLOCK_IO_PROTOCOL *BlockIo; EFI_HANDLE BlockIoHandle; EFI_STATUS Status; SHELL_STATUS ShellStatus; UINT8 *Buffer; UINTN BufferSize; ShellStatus = SHELL_SUCCESS; Status = gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid, (EFI_DEVICE_PATH_PROTOCOL **)&DevPath, &BlockIoHandle); if (EFI_ERROR(Status)) { return (SHELL_NOT_FOUND); } Status = gBS->OpenProtocol(BlockIoHandle, &gEfiBlockIoProtocolGuid, (VOID**)&BlockIo, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (EFI_ERROR(Status)) { return (SHELL_NOT_FOUND); } BufferSize = BlockIo->Media->BlockSize * BlockCount; if (BufferSize > 0) { Buffer = AllocateZeroPool(BufferSize); } else { ShellPrintEx(-1,-1,L" BlockSize: 0x%08x, BlockCount: 0x%08x\r\n", BlockIo->Media->BlockSize, BlockCount); Buffer = NULL; } Status = BlockIo->ReadBlocks(BlockIo, BlockIo->Media->MediaId, Lba, BufferSize, Buffer); if (!EFI_ERROR(Status) && Buffer != NULL) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_DBLK_HEADER), gShellDebug1HiiHandle, Lba, BufferSize, BlockIo ); DumpHex(2,0,BufferSize,Buffer); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_READ_FAIL), gShellDebug1HiiHandle, L"BlockIo", Status); ShellStatus = SHELL_DEVICE_ERROR; } if (Buffer != NULL) { FreePool(Buffer); } gBS->CloseProtocol(BlockIoHandle, &gEfiBlockIoProtocolGuid, gImageHandle, NULL); return (ShellStatus); }
EFI_DEVICE_PATH_PROTOCOL * DevicePathInstance ( IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, OUT UINTN *Size ) /*++ Routine Description: Function retrieves the next device path instance from a device path data structure. Arguments: DevicePath - A pointer to a device path data structure. Size - A pointer to the size of a device path instance in bytes. Returns: This function returns a pointer to the current device path instance. In addition, it returns the size in bytes of the current device path instance in Size, and a pointer to the next device path instance in DevicePath. If there are no more device path instances in DevicePath, then DevicePath will be set to NULL. --*/ { EFI_DEVICE_PATH_PROTOCOL *Start, *Next, *DevPath; UINTN Count; DevPath = *DevicePath; Start = DevPath; if (!DevPath) { return NULL; } // // Check for end of device path type // for (Count = 0; ; Count++) { Next = NextDevicePathNode(DevPath); if (IsDevicePathEndType(DevPath)) { break; } if (Count > 01000) { // // BugBug: Debug code to catch bogus device paths // DEBUG((EFI_D_ERROR, "DevicePathInstance: DevicePath %x Size %d", *DevicePath, ((UINT8 *) DevPath) - ((UINT8 *) Start) )); DumpHex (0, 0, ((UINT8 *) DevPath) - ((UINT8 *) Start), Start); break; } DevPath = Next; } ASSERT (DevicePathSubType(DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE || DevicePathSubType(DevPath) == END_INSTANCE_DEVICE_PATH_SUBTYPE); // // Set next position // if (DevicePathSubType(DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) { Next = NULL; } *DevicePath = Next; // // Return size and start of device path instance // *Size = ((UINT8 *) DevPath) - ((UINT8 *) Start) + sizeof(EFI_DEVICE_PATH_PROTOCOL); return Start; }