pax_global_header00006660000000000000000000000064152013317420014510gustar00rootroot0000000000000052 comment=67ff323aead437557d9a7309803aae79cd5b2d56 intel-metee-67ff323/000077500000000000000000000000001520133174200142625ustar00rootroot00000000000000intel-metee-67ff323/.cmake-format.py000066400000000000000000000167531520133174200172740ustar00rootroot00000000000000# SPDX-License-Identifier: Apache-2.0 # ---------------------------------- # Options affecting listfile parsing # ---------------------------------- with section("parse"): # Specify structure for custom cmake functions additional_commands = { 'format_and_lint': { 'kwargs': { 'CC': '*', 'CCDEPENDS': '*', 'CMAKE': '*', 'EXCLUDE': '*', 'JS': '*', 'PY': '*'}}, 'pkg_find': {'kwargs': {'PKG': '*'}}} # Specify variable tags. vartags = [] # Specify property tags. proptags = [] # ----------------------------- # Options affecting formatting. # ----------------------------- with section("format"): # How wide to allow formatted cmake files line_width = 80 # How many spaces to tab for indent tab_size = 2 # If an argument group contains more than this many sub-groups (parg or kwarg # groups) then force it to a vertical layout. max_subgroups_hwrap = 2 # If a positional argument group contains more than this many arguments, then # force it to a vertical layout. max_pargs_hwrap = 6 # If a cmdline positional group consumes more than this many lines without # nesting, then invalidate the layout (and nest) max_rows_cmdline = 2 # If true, separate flow control names from their parentheses with a space separate_ctrl_name_with_space = False # If true, separate function names from parentheses with a space separate_fn_name_with_space = False # If a statement is wrapped to more than one line, than dangle the closing # parenthesis on its own line. dangle_parens = True # If the trailing parenthesis must be 'dangled' on its on line, then align it # to this reference: `prefix`: the start of the statement, `prefix-indent`: # the start of the statement, plus one indentation level, `child`: align to # the column of the arguments dangle_align = 'prefix' # If the statement spelling length (including space and parenthesis) is # smaller than this amount, then force reject nested layouts. min_prefix_chars = 4 # If the statement spelling length (including space and parenthesis) is larger # than the tab width by more than this amount, then force reject un-nested # layouts. max_prefix_chars = 10 # If a candidate layout is wrapped horizontally but it exceeds this many # lines, then reject the layout. max_lines_hwrap = 2 # What style line endings to use in the output. line_ending = 'unix' # Format command names consistently as 'lower' or 'upper' case command_case = 'canonical' # Format keywords consistently as 'lower' or 'upper' case keyword_case = 'unchanged' # A list of command names which should always be wrapped always_wrap = [] # If true, the argument lists which are known to be sortable will be sorted # lexicographicall enable_sort = True # If true, the parsers may infer whether or not an argument list is sortable # (without annotation). autosort = False # By default, if cmake-format cannot successfully fit everything into the # desired linewidth it will apply the last, most aggressive attempt that it # made. If this flag is True, however, cmake-format will print error, exit # with non-zero status code, and write-out nothing require_valid_layout = False # A dictionary mapping layout nodes to a list of wrap decisions. See the # documentation for more information. layout_passes = {} # ------------------------------------------------ # Options affecting comment reflow and formatting. # ------------------------------------------------ with section("markup"): # What character to use for bulleted lists bullet_char = '*' # What character to use as punctuation after numerals in an enumerated list enum_char = '.' # If comment markup is enabled, don't reflow the first comment block in each # listfile. Use this to preserve formatting of your copyright/license # statements. first_comment_is_literal = False # If comment markup is enabled, don't reflow any comment block which matches # this (regex) pattern. Default is `None` (disabled). literal_comment_pattern = None # Regular expression to match preformat fences in comments default= # ``r'^\s*([`~]{3}[`~]*)(.*)$'`` fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$' # Regular expression to match rulers in comments default= # ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'`` ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$' # If a comment line matches starts with this pattern then it is explicitly a # trailing comment for the preceding argument. Default is '#<' explicit_trailing_pattern = '#<' # If a comment line starts with at least this many consecutive hash # characters, then don't lstrip() them off. This allows for lazy hash rulers # where the first hash char is not separated by space hashruler_min_length = 10 # If true, then insert a space between the first hash char and remaining hash # chars in a hash ruler, and normalize its length to fill the column canonicalize_hashrulers = True # enable comment markup parsing and reflow enable_markup = True # ---------------------------- # Options affecting the linter # ---------------------------- with section("lint"): # a list of lint codes to disable disabled_codes = ['E1122', 'C0113'] # regular expression pattern describing valid function names function_pattern = '[0-9a-z_]+' # regular expression pattern describing valid macro names macro_pattern = '[0-9A-Z_]+' # regular expression pattern describing valid names for variables with global # scope global_var_pattern = '[0-9a-zA-Z][0-9a-zA-Z_]+' # regular expression pattern describing valid names for variables with global # scope (but internal semantic) internal_var_pattern = '_[0-9A-Z][0-9A-Z_]+' # regular expression pattern describing valid names for variables with local # scope local_var_pattern = '[0-9a-z_]+' # regular expression pattern describing valid names for privatedirectory # variables private_var_pattern = '_[0-9a-z_]+' # regular expression pattern describing valid names for publicdirectory # variables public_var_pattern = '[0-9A-Z][0-9A-Z_]+' # regular expression pattern describing valid names for keywords used in # functions or macros keyword_pattern = '[0-9A-Z_]+' # In the heuristic for C0201, how many conditionals to match within a loop in # before considering the loop a parser. max_conditionals_custom_parser = 2 # Require at least this many newlines between statements min_statement_spacing = 1 # Require no more than this many newlines between statements max_statement_spacing = 3 max_returns = 6 max_branches = 12 max_arguments = 5 max_localvars = 15 max_statements = 50 # ------------------------------- # Options affecting file encoding # ------------------------------- with section("encode"): # If true, emit the unicode byte-order mark (BOM) at the start of the file emit_byteorder_mark = False # Specify the encoding of the input file. Defaults to utf-8 input_encoding = 'utf-8' # Specify the encoding of the output file. Defaults to utf-8. Note that cmake # only claims to support utf-8 so be careful when using anything else output_encoding = 'utf-8' # ------------------------------------- # Miscellaneous configurations options. # ------------------------------------- with section("misc"): # A dictionary containing any per-command configuration overrides. Currently # only `command_case` is supported. per_command = {} intel-metee-67ff323/.gitattributes000066400000000000000000000000141520133174200171500ustar00rootroot00000000000000* text=auto intel-metee-67ff323/.github/000077500000000000000000000000001520133174200156225ustar00rootroot00000000000000intel-metee-67ff323/.github/workflows/000077500000000000000000000000001520133174200176575ustar00rootroot00000000000000intel-metee-67ff323/.github/workflows/codeql.yml000066400000000000000000000022061520133174200216510ustar00rootroot00000000000000name: "CodeQL" permissions: read-all on: push: branches: [ "master" ] pull_request: # The branches below must be a subset of the branches above branches: [ "master" ] jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'c' ] steps: - name: Checkout repository uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs queries: +security-extended,security-and-quality - name: Autobuild uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 with: category: "/language:${{matrix.language}}" intel-metee-67ff323/.gitignore000066400000000000000000000150741520133174200162610ustar00rootroot00000000000000## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.rsuser *.suo *.user *.userosscache *.sln.docstates # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs # Mono auto generated files mono_crash.* # Build results [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ x86/ [Ww][Ii][Nn]32/ [Aa][Rr][Mm]/ [Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ [Ll]ogs/ # Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ # Visual Studio 2017 auto generated files Generated\ Files/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* # NUnit *.VisualState.xml TestResult.xml nunit-*.xml # Build Results of an ATL Project [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c # Benchmark Results BenchmarkDotNet.Artifacts/ # .NET Core project.lock.json project.fragment.lock.json artifacts/ # ASP.NET Scaffolding ScaffoldingReadMe.txt # StyleCop StyleCopReport.xml # Files built by Visual Studio *_i.c *_p.c *_h.h *.ilk *.meta *.obj *.iobj *.pch *.pdb *.ipdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.tmp_proj *_wpftmp.csproj *.log *.tlog *.vspscc *.vssscc .builds *.pidb *.svclog *.scc # Chutzpah Test files _Chutzpah* # Visual C++ cache files ipch/ *.aps *.ncb *.opendb *.opensdf *.sdf *.cachefile *.VC.db *.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx *.sap # Visual Studio Trace Files *.e2e # TFS 2012 Local Workspace $tf/ # Guidance Automation Toolkit *.gpState # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool *.dotCover # AxoCover is a Code Coverage Tool .axoCover/* !.axoCover/settings.json # Coverlet is a free, cross platform Code Coverage Tool coverage*.json coverage*.xml coverage*.info # Visual Studio code coverage results *.coverage *.coveragexml # NCrunch _NCrunch_* .*crunch*.local.xml nCrunchTemp_* # MightyMoose *.mm.* AutoTest.Net/ # Web workbench (sass) .sass-cache/ # Installshield output folder [Ee]xpress/ # DocProject is a documentation generator add-in DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html # Click-Once directory publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml # Note: Comment the next line if you want to checkin your web deploy settings, # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to # checkin your Azure Web App publish settings, but sensitive information contained # in these scripts will be unencrypted PublishScripts/ # NuGet Packages *.nupkg # NuGet Symbol Packages *.snupkg # The packages folder can be ignored because of Package Restore **/[Pp]ackages/* # except build/, which is used as an MSBuild target. !**/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/[Pp]ackages/repositories.config # NuGet v3's project.json files produces more ignorable files *.nuget.props *.nuget.targets # Nuget personal access tokens and Credentials nuget.config # Microsoft Azure Build Output csx/ *.build.csdef # Microsoft Azure Emulator ecf/ rcf/ # Windows Store app package directories and files AppPackages/ BundleArtifacts/ Package.StoreAssociation.xml _pkginfo.txt *.appx *.appxbundle *.appxupload # Visual Studio cache files # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache !?*.[Cc]ache/ # Others ClientBin/ ~$* *~ *.dbmdl *.dbproj.schemaview *.jfm *.pfx *.publishsettings orleans.codegen.cs # Including strong name files can present a security risk # (https://github.com/github/gitignore/pull/2483#issue-259490424) #*.snk # Since there are multiple workflows, uncomment next line to ignore bower_components # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) #bower_components/ # RIA/Silverlight projects Generated_Code/ # Backup & report files from converting an old project file # to a newer Visual Studio version. Backup files are not needed, # because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm ServiceFabricBackup/ *.rptproj.bak # SQL Server files *.mdf *.ldf *.ndf # Business Intelligence projects *.rdl.data *.bim.layout *.bim_*.settings *.rptproj.rsuser *- [Bb]ackup.rdl *- [Bb]ackup ([0-9]).rdl *- [Bb]ackup ([0-9][0-9]).rdl # Microsoft Fakes FakesAssemblies/ # GhostDoc plugin setting file *.GhostDoc.xml # Node.js Tools for Visual Studio .ntvs_analysis.dat node_modules/ # Visual Studio 6 build log *.plg # Visual Studio 6 workspace options file *.opt # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) *.vbw # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts **/*.DesktopClient/ModelManifest.xml **/*.Server/GeneratedArtifacts **/*.Server/ModelManifest.xml _Pvt_Extensions # Paket dependency manager .paket/paket.exe paket-files/ # FAKE - F# Make .fake/ # CodeRush personal settings .cr/personal # Python Tools for Visual Studio (PTVS) __pycache__/ *.pyc # Cake - Uncomment if you are using it # tools/** # !tools/packages.config # Tabs Studio *.tss # Telerik's JustMock configuration file *.jmconfig # BizTalk build output *.btp.cs *.btm.cs *.odx.cs *.xsd.cs # OpenCover UI analysis results OpenCover/ # Azure Stream Analytics local run output ASALocalRun/ # MSBuild Binary and Structured Log *.binlog # NVidia Nsight GPU debugger configuration file *.nvuser # MFractors (Xamarin productivity tool) working folder .mfractor/ # Local History for Visual Studio .localhistory/ # BeatPulse healthcheck temp database healthchecksdb # Backup folder for Package Reference Convert tool in Visual Studio 2017 MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ # Fody - auto-generated XML schema FodyWeavers.xsd # VS Code files for those working on multiple tools .vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json *.code-workspace # Local History for Visual Studio Code .history/ # Windows Installer files from build outputs *.cab *.msi *.msix *.msm *.msp # JetBrains Rider .idea/ *.sln.iml # Local files that should not be uploaded cmake.config CMakeSettings.json /CMakeUserPresets.json intel-metee-67ff323/.gitlint000066400000000000000000000075521520133174200157460ustar00rootroot00000000000000# Edit this file as you like. # # All these sections are optional. Each section with the exception of [general] represents # one rule and each key in it is an option for that specific rule. # # Rules and sections can be referenced by their full name or by id. For example # section "[body-max-line-length]" could be written as "[B1]". Full section names are # used in here for clarity. # [general] # Ignore certain rules, this example uses both full name and id # ignore=title-trailing-punctuation, T3 # verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this # verbosity = 2 # By default gitlint will ignore merge, revert, fixup and squash commits. # ignore-merge-commits=true # ignore-revert-commits=true # ignore-fixup-commits=true # ignore-squash-commits=true # Ignore any data send to gitlint via stdin # ignore-stdin=true # Fetch additional meta-data from the local repository when manually passing a # commit message to gitlint via stdin or --commit-msg. Disabled by default. # staged=true # Enable debug mode (prints more output). Disabled by default. # debug=true # Enable community contributed rules # See http://jorisroovers.github.io/gitlint/contrib_rules for details # Set the extra-path where gitlint will search for user defined rules # See http://jorisroovers.github.io/gitlint/user_defined_rules for details extra-path=gitlint # This is an example of how to configure the "title-max-length" rule and # set the line-length it enforces to 80 [title-max-length] line-length=80 # [title-must-not-contain-word] # Comma-separated list of words that should not occur in the title. Matching is case # insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING" # will not cause a violation, but "WIP: my title" will. # words=wip [title-match-regex] # python like regex (https://docs.python.org/2/library/re.html) that the # commit-msg title must be matched to. # Note that the regex can contradict with other rules if not used correctly # (e.g. title-must-not-contain-word). regex=^MeTee:.* [body-max-line-length] line-length=72 # [body-min-length] # min-length=5 # [body-is-missing] # Whether to ignore this rule on merge commits (which typically only have a title) # default = True # ignore-merge-commits=false # [body-changed-file-mention] # List of files that need to be explicitly mentioned in the body when they are changed # This is useful for when developers often erroneously edit certain files or git submodules. # By specifying this rule, developers can only change the file when they explicitly reference # it in the commit message. # files=gitlint/rules.py,README.md [author-valid-email] # python like regex (https://docs.python.org/2/library/re.html) that the # commit author email address should be matched to # For example, use the following regex if you only want to allow email addresses from foo.com regex=[^@]+@(?!localhost).*$ # [ignore-by-title] # Ignore certain rules for commits of which the title matches a regex # E.g. Match commit titles that start with "Release" # regex=^Release(.*) # Ignore certain rules, you can reference them by their id or by their full name # Use 'all' to ignore all rules # ignore=T1,body-min-length # [ignore-by-body] # Ignore certain rules for commits of which the body has a line that matches a regex # E.g. Match bodies that have a line that that contain "release" # regex=(.*)release(.*) # # Ignore certain rules, you can reference them by their id or by their full name # Use 'all' to ignore all rules # ignore=T1,body-min-length # This is a contrib rule - a community contributed rule. These are disabled by default. # You need to explicitly enable them one-by-one by adding them to the "contrib" option # under [general] section above. # [contrib-title-conventional-commits] # Specify allowed commit types. For details see: https://www.conventionalcommits.org/ # types = bugfix,user-story,epic intel-metee-67ff323/CHANGELOG.md000066400000000000000000000214221520133174200160740ustar00rootroot00000000000000## [6.2.3] ### Fixed - Linux: pick libmei 1.8.3 - empty kind fix - Linux: return NOT_SUPPORTED on ENODATA - Linux: use the right side of cancel pipe - EFI: error out on wrong type - EFI: add missed status to prints - Windows: limit buffer size ### Removed - drop conan support ## [6.2.2] ### Changed - reshuffle log macros - Linux: import libmei 1.8.2 ### Added - samples: add fw status print to cpp sample - EFI: introduce new define to enable stdlib support ## [6.2.1] ### Fixed - CMake: Linux: overwrite FORTIFY_SOURCE from distribution ## [6.2.0] ### Changed - Linux: build for Android using Android NDK - Linux: import libmei 1.8.1 ### Added - add TeeCancelIO API ## [6.1.0] ### Fixed - fix cpp wrapper and add sample - efi: use %s in external debug prefix ### Changed - Linux: import libmei 1.8.0 ### Added - samples: gsc: search for gscfi device - samples: print FW status in GSC - CMake: Windows: add release and debug 64 all preset ## [6.0.2] - Windows: drop un-needed assert - EFI: do not send disconnect when not connected ## [6.0.1] - EFI: prefix internal function - Windows: add newlines to error messages ## [6.0.0] **Note:** Backward incompatible ABI change: The struct TEEHANDLE struct is packed(1) now Added field to store V2 logger callback. ### Changed - Linux: pull libmei 1.7.0 - CMake: consume four-part version - Windows: fix copyright format ### Added - Windows: C# OOP wrapper - TeeInitFull2 API ## [5.0.0] **Note:** Backward incompatible API change: The HECI_DEVICE_KIND_* enums and kind field in struct tee_device_address are renamed to HECI_HW_TYPE_* and hw_type field to avoid clash with device kind value provided by OS drivers. ### Changed - EFI: Decrease HW register polling timeout - EFI: Refactor HECI_DEVICE_KIND - Linux: pull libmei 1.6.4 ### Fixed - EFI: Change propertyMap array type to CHAR8* - EFI: Fixing compilation errors with GCC - account for old Windows driver ### Added - CMake: Windows: add release 64 static preset - Add cpp wrapper - TeeGetKind API ## [4.3.1] ### Fixed - Windows: fix asan build ### Changed - doc: update Doxygen template ## [4.3.0] ### Fixed - Windows: process access denied on open - UEFI: Add driver logic for fixed clients ### Added - Windows: add resource - cmake: add 32 bit release preset - add getters for maxMsgLen and prtocolVer ## [4.2.1] ### Fixed - EFI: fix open multiple connections to the different clients - Linux: import libmei 1.6.3: fix for traffic dump in release mode and build on 32bit Linux. ## [4.2.0] **Note:** ABI breakage in this version, struct tee_device_address was expanded ### Fixed - tests: make tests robust - Linux: fix variable type - Windows: init read/write timeout to INT_MAX - tests: add connect retries ### Added - samples: add basic sample - UEFI: initial implementation - CMake: Windows: add static build ### Changed - Linux: pull libmei 1.6.1 - CMake: minimum CMake to 3.15 and fix static build ## [4.1.0] ### Fixed - Linux: add newlines to messages - Linux: cancel waiting operation on disconnect - Windows: rewrite overlapped operations - Linux: define GUID in more compatible way - tests: fix GetDriverVersion test - tests: fix crash in failed 1000 handles test - Windows: do not retake last error from ioctl - Windows: demote print to debug - CMake: use PDB path generator expression - Linux: fix timeout and signedness ### Added - README: add thread safety section - tests: add test for interrupted read - CMake: enable several extended compilation warnings ### Changed - Linux: pull libmei 1.6.0 ### Removed - Linux: drop unused define - Windows: remove unused layers - Doxygen: disable HTML timestamps ## [4.0.0] **Note:** Backward compatible API change ### Fixed - Windows: initilaize variables - conan: support higher version of the Linux compilers - linux: fix print in get handle - linux: do not set log if init failed - Windows: fix close on exit - Windows: add missing newline - samples: return log level to original - Linux: fix timeout treatment - tests: disconnect at the end of test - log: demote FUNC_ENTRY/EXIT to debug ### Added - add CONTRIBUTING.md file - add GetTRC API - add init api with all parameters - add option for log callback - git: add full VS gitignore - CMake: add preset for full debug build ### Changed - Linux: pull libmei 1.5.6 - samples: use stdbool on windows - windows: replace spaces with tabs ### Removed - CMake: disable doc build by default - CMake: drop system ver requirement ## [3.2.4] ### Fixed - Linux: pull in libmei 1.5.4 with reconnect-on-error fix ### Added - README: add nproc explanation, refine grammar and formatting ## [3.2.3] ### Fixed - tests: fix windows tests - README: update Windows build instructions ## [3.2.2] ### Fixed - Linux: fix return value treatment of mei_set_log_level ## [3.2.1] ### Added - set security policy for the project ### Fixed - Windows: fix wrong return status - Windows: move to_int inline function to metee_win.h - Windows: remove unused labels ## [3.2.0] ### Added - Linux: pull in libmei 1.5.3 - implement log level APIs - Windows: remove redundant function WaitForOperationEnd - Windows: add license for MSFT WDK samples ## [3.1.6] ### Fixed - CMake: fix secure compiler options - Windows: convert win32 errors to library errors - doc: update doxygen config - Linux: pull in libmei 1.5.2 - Windows: return with error on memcpy failure - Windows: Drop non needed variable initialization on declaration ### Added - CMake: add preset to compile all code ## [3.1.5] ### Fixed - Linux: return better errors from TeeInit - samples: mkhi: account for errors from init - tests: update tests for fixed linux init ## [3.1.4] ### Fixed - Linux: replace select with poll - Linux: use positive errno number in strerror - conan: drop cxx requirement ### Changed - build: take gtest 1.12.1 - tests: use fixed gtest version in download ### Added - CMake: add Windows presets - test: add test for big file descriptor ## [3.1.3] ### Fixed - samples: fix assignment and add explicit type-cast - Linux: pull-in libmei 1.5.1 with fix for reconnect if client not found ## [3.1.2] ### Fixed - tests: fix gtest branch name - CHANGELOG: fix the indentation ## [3.1.1] ### Fixed - Windows: push DebugPrint down - Windows: tests: disable pending write test on Windows - doc: add missing return values documentation ### Changed - CMake: make docs optional ## [3.1.0] **Note:** Backward compatible API change ### Added - Add TEE_PERMISSION_DENIED error code - Add stress tests ## [3.0.1] ### Added - add SPDX license also on .cmake-format config file - samples: add GSC sample - Build: add conan packaging. ## Fixed - test: initialize deviceHandle in constructor - README.md and more verbose description - CMake: add secure compile and link flag ## [3.0.0] **Note:** below changes break API and ABI compatibility with older library versions. ### Changed - Windows: Add separate TeeInitGUID API to init library by using device class GUID. ### Fixed - Fix miscellaneous code issues in samples. - Windows: return right size of processed data. - Windows: fix connect to the externally provided guid. - Windows: enlarge debug output buffer. - Modernize CMake configuration. - Fix spelling mistakes all over the library. - Windows: check return pointers for NULL before write. - Windows: fix reconnect if underlying client was disconnected from FW side. - Doxygen documentation cleaned up and expanded. - Linux: import libmei 1.4 code. ### Added - Windows: ability to connect to device by path. - API to use externally opened file handle. - Tests with long buffers. - Ability to build dynamic library. - Support for meson build system. - Option to write output to console instead of Syslog/DbgView ## [2.2.2] ### Added ### Changed ### Fixed - Windows: fix package target in cmake. ## [2.2.1] ### Added - Enable gitlint, cmake-format, codespell checking. - Added .gitattributes. ### Changed - Reformat cmake files - Update .gitignore - convert CHANGELOG to Markdown format ### Fixed - Add -D_GNU_SOURCE for strdup and other functions. - Fix spelling errors in the library. - Windows: enlarge debug output buffer. - Windows: return right size of processed data. - Windows: fix connect to the externally provided guid. - Fix debug print. - Fix miscellaneous code issues. ## [2.2.0] ### Added - API to retrieve FW status registers ### Changed ### Fixed ## [2.1.1] ### Added - Add tests and samples to install package. ### Changed - Linux: Set default device to /dev/mei0 as all modern Linux kernels sports /dev/meiX char device nodes. ### Fixed - Linux: include select.h to fix build with musl libc. ## [2.1.0] ### Added - Add DEFINE_GUID macro in Linux header. ### Changed - Use name GUID in all OSs. ### Fixed intel-metee-67ff323/CMakeLists.txt000066400000000000000000000070541520133174200170300ustar00rootroot00000000000000# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2014-2024 Intel Corporation cmake_minimum_required(VERSION 3.15) cmake_policy(SET CMP0091 NEW) project(metee) option(BUILD_DOCS "Build docs" NO) option(BUILD_TEST "Build self-test" NO) option(BUILD_SAMPLES "Build samples" NO) option(BUILD_MSVC_RUNTIME_STATIC "Build with static runtime libraries on MSVC" NO ) option(BUILD_SHARED_LIBS "Build shared library" NO) option(CONSOLE_OUTPUT "Push debug and error output to console (instead of syslog)" NO) include(GNUInstallDirs) set(LICENSE Apache) include(version.cmake) if(WIN32) include(win32.cmake) else(WIN32) include(linux.cmake) endif(WIN32) set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER include/metee.h) set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${TEE_VERSION_STRING}) set_target_properties( ${PROJECT_NAME} PROPERTIES SOVERSION ${TEE_VERSION_STRING} ) set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) target_include_directories(${PROJECT_NAME} PUBLIC include) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG") install( TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_LIBDIR}" PUBLIC_HEADER DESTINATION include ) # Documentation if(BUILD_DOCS) find_package(Doxygen) if(DOXYGEN_FOUND) set(DOXYGEN_INPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY ) add_custom_target( doc ALL ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating documentation with Doxygen" VERBATIM ) if(UNIX) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/man/man3 DESTINATION ${CMAKE_INSTALL_MANDIR} ) install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${CMAKE_INSTALL_DOCDIR} ) else() install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION doc) endif() endif() endif() # CPack set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) set(CPACK_PACKAGE_VERSION_MAJOR ${TEE_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${TEE_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${TEE_VERSION_PATCH}) set(CPACK_PACKAGE_VENDOR "Intel, Inc") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "ME TEE Interface Library") set(CPACK_PACKAGE_CONTACT "linux-mei@linux.intel.com") set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/DESCRIPTION) set(CPACK_SOURCE_GENERATOR "TBZ2;ZIP") set(CPACK_SOURCE_PACKAGE_FILE_NAME ${PROJECT_NAME}-${TEE_VERSION_STRING}) add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) # RPM Specific set(CPACK_RPM_PACKAGE_RELEASE 1) set(CPACK_RPM_PACKAGE_LICENSE ${LICENSE}) set(CPACK_RPM_PACKAGE_GROUP "Development") # Debian Specific set(CPACK_DEBIAN_PACKAGE_VERSION 1) set(CPACK_DEBIAN_PACKAGE_SECTION "devel") if(UNIX) set(CPACK_GENERATOR "TGZ") find_program(RPM_EXE rpmbuild) if(RPM_EXE) list(APPEND CPACK_GENERATOR "RPM") endif(RPM_EXE) find_program(DEB_EXE debuild) if(DEB_EXE) list(APPEND CPACK_GENERATOR "DEB") endif(DEB_EXE) else(UNIX) set(CPACK_GENERATOR "ZIP") endif(UNIX) include(CPack) add_subdirectory(bindings) if(BUILD_TEST) add_subdirectory(tests) endif(BUILD_TEST) if(BUILD_SAMPLES) add_subdirectory(samples) endif(BUILD_SAMPLES) intel-metee-67ff323/CMakePresets.json000066400000000000000000000077671520133174200175240ustar00rootroot00000000000000{ "version": 2, "configurePresets": [ { "name": "base64", "displayName": "Windows x86-64 base", "description": "Build x86-64 Release, VS2019", "hidden": true, "generator": "Visual Studio 16 2019", "architecture": { "value": "x64", "strategy": "set" }, "cacheVariables": { "BUILD_SHARED_LIBS": "YES", "BUILD_MSVC_RUNTIME_STATIC": "YES" } }, { "name": "base32", "displayName": "Windows x86 base", "description": "Build x86 Release, VS2019", "hidden": true, "generator": "Visual Studio 16 2019", "architecture": { "value": "Win32", "strategy": "set" }, "cacheVariables": { "BUILD_SHARED_LIBS": "YES", "BUILD_MSVC_RUNTIME_STATIC": "YES" } }, { "name": "Release32Static", "displayName": "Windows x86 Release Static", "description": "Build x86 Release, VS2019", "inherits": "base32", "binaryDir": "${sourceDir}/Release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "BUILD_SHARED_LIBS": "NO" } }, { "name": "Release32", "displayName": "Windows x86 Release", "description": "Build x86 Release, VS2019", "inherits": "base32", "binaryDir": "${sourceDir}/Release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } }, { "name": "Release64", "displayName": "Windows x86-64 Release", "description": "Build x86-64 Release, VS2019", "inherits": "base64", "binaryDir": "${sourceDir}/Release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } }, { "name": "Release64Static", "displayName": "Windows x86-64 Release Static", "description": "Build x86-64 Release, VS2019", "inherits": "base64", "binaryDir": "${sourceDir}/Release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "BUILD_SHARED_LIBS": "NO" } }, { "name": "Release64AllStatic", "displayName": "Windows x86-64 Release Static", "description": "Build x86-64 Release, VS2019", "inherits": "base64", "binaryDir": "${sourceDir}/Release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", "BUILD_TEST": "YES", "BUILD_SAMPLES": "YES", "BUILD_SHARED_LIBS": "NO" } }, { "name": "Debug64All", "displayName": "Windows x86-64 Debug All", "description": "Build x86-64 Debug, VS2019, including test and samples", "inherits": "base64", "binaryDir": "${sourceDir}/Debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "BUILD_TEST": "YES", "BUILD_SAMPLES": "YES" } }, { "name": "Debug64AllStatic", "displayName": "Windows x86-64 Debug Static All", "description": "Build x86-64 Debug, VS2019, including test and samples", "inherits": "base64", "binaryDir": "${sourceDir}/Debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "BUILD_TEST": "YES", "BUILD_SAMPLES": "YES", "BUILD_SHARED_LIBS": "NO" } } ], "buildPresets": [ { "name": "Release32Static", "configurePreset": "Release32Static", "configuration": "Release" }, { "name": "Release32", "configurePreset": "Release32", "configuration": "Release" }, { "name": "Release64", "configurePreset": "Release64", "configuration": "Release" }, { "name": "Release64Static", "configurePreset": "Release64Static", "configuration": "Release" }, { "name": "Release64AllStatic", "configurePreset": "Release64AllStatic", "configuration": "Release" }, { "name": "Debug64All", "configurePreset": "Debug64All", "configuration": "Debug" }, { "name": "Debug64AllStatic", "configurePreset": "Debug64AllStatic", "configuration": "Debug" } ] } intel-metee-67ff323/CONTRIBUTING.md000066400000000000000000000075621520133174200165250ustar00rootroot00000000000000# Contributing ### License MeTee library is licensed under the terms in [LICENSE](COPYING). By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms. ### Git Commit Messages ### A properly formed git commit subject line should always be able to complete the following sentence If applied, this commit will *\* ### Rules for a great git commit message style * Separate subject from body with a blank line. * Do not end the subject line with a period, it will disturb the patch creation. * Capitalize each paragraph. * Use the imperative mood. * Wrap lines at 72 character.s * Use the body to explain what and why you have done something, if change is complex also explain how. ### Information in commit messages * Describe why a change is being made. * How does it address the issue? * What effects does the patch have? * Do not assume the reviewer understands what the original problem was. * Do not assume the code is self-evident/self-documenting. * Read the commit message to see if it hints at improved code structure. * The first commit line is the most important. * Describe any limitations of the current code. * Do not include patch set-specific comments. Details for each point and good commit message examples can be found on https://wiki.openstack.org/wiki/GitCommitMessages#Information_in_commit_messages ### References in commit messages * Structure: ``` MeTee: : <blank line> <body> Signed-off-by: Your Name <your.email@yyy.zzz> ``` * Possible subsection - github: changes in github management: all under .github/ - Linux: Linux os specific changes. - Windows: Windows os specific changes. - CMake: changes in the cmake build configuration. - tests: changes in tests. - samples: changes in samples. - doc: changes in documentation. ### Sign your work Please use the sign-off line at the end of the patch. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify the below (from [developercertificate.org](http://developercertificate.org/)): ``` Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 660 York Street, Suite 102, San Francisco, CA 94110 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ``` Then you just add a line to every git commit message: Signed-off-by: Joe Smith <joe.smith@email.com> Use your real name (sorry, no pseudonyms or anonymous contributions.) If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with `git commit -s`. ����������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/COPYING�������������������������������������������������������������������������0000664�0000000�0000000�00000023676�15201331742�0015333�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS ������������������������������������������������������������������intel-metee-67ff323/DESCRIPTION���������������������������������������������������������������������0000664�0000000�0000000�00000000257�15201331742�0015774�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# MeTee library MeTee library provides a cross-platform simple programming interface for accessing Intel HECI interfaces on devices found in BigCore and Atom based products. �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/README.md�����������������������������������������������������������������������0000664�0000000�0000000�00000005563�15201331742�0015552�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# Intel(R) ME TEE Library ME TEE Library is a C library to access CSE/CSME/GSC firmware via a mei interface. ME TEE provides a single cross-platform API to access to MEI devices on Linux and Windows. MEI TEE API simplify connection and communication with the mei device, and firmware status registers retrieval. ## CMake Build ME TEE library uses CMake for both Linux and Windows builds. ### Windows From the "Developer Command Prompt for VS 2019" with C compiler and CMake component installed: 1. Go to sources directory: `cd <srcdir>` 2. Create `build` directory: `mkdir build` 3. Run `cmake -G "Visual Studio 16 2019" -A <build_arch> <srcdir>` from the `build` directory (best to set *build_arch* to Win32) 4. Run `cmake --build . --config Release --target package -j <nproc>` from the `build` directory to build an archive with all executables and libraries, *nproc* is the number of parallel threads in compilation, best to set to number of processor threads available By default, CMake links with dynamic runtime (/MD), set BUILD_MSVC_RUNTIME_STATIC to ON to link with static runtime (/MT): `cmake -G "Visual Studio 16 2019" -A <build_arch> -DBUILD_MSVC_RUNTIME_STATIC=ON <srcdir>` ### Linux 1. Create `build` directory 2. Run `cmake <srcdir>` from the `build` directory 3. Run `make -j$(nproc) package` from the `build` directory to build .deb and .rpm packages and .tgz archive ### EFI When building application with C Standard support, add following preprocessor variable to build options `METEE_EFI_STDLIB_SUPPORT` ## Meson Build ME TEE library also supports Meson for both Linux and Windows builds. ### General Setup ```sh meson setup build/ meson configure -Dbuildtype=debug/release build ninja -v -C build/ ``` ### Windows Visual Studio In order to use Visual Studio project meson requires to run under Visual Studio Command Prompt. In case of Visual Studio 2019, you can use either *"x64 Native Tools Command Prompt for VS 2019"* or under powershell enter VisualStudio DevShell and then just continue with the [general setup](#general-setup) #### Powershell example setting: ```powershell $installPath = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version 16.0 -property installationpath Import-Module (Join-Path $installPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll") Enter-VsDevShell -VsInstallPath $installPath -SkipAutomaticLocation ``` ## Thread safety The library supports multithreading but is not thread-safe. Every thread should either initialize and use its own handle or a locking mechanism should be implemented by the caller to ensure that only one thread uses the handle at any time. The only exception is ability to call Disconnect to exit from read blocked on another thread. ## Artificial Intelligence These contents may have been developed with support from one or more Intel-operated generative artificial intelligence solutions.���������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/SECURITY.md���������������������������������������������������������������������0000664�0000000�0000000�00000001063�15201331742�0016053�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# Security Policy Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. ## Supported Versions | Version | Supported | | ------- | ------------------ | | 3.1.0 | :white_check_mark: | | < 3.1.0 | :x: | ## Reporting a Vulnerability Please report any security vulnerabilities in this project [utilizing the guidelines here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/VERSION�������������������������������������������������������������������������0000664�0000000�0000000�00000000006�15201331742�0015326�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������6.2.3 ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/bindings/�����������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0016057�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/bindings/CMakeLists.txt���������������������������������������������������������0000664�0000000�0000000�00000000253�15201331742�0020617�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2025 Intel Corporation if(BUILD_SHARED_LIBS AND WIN32) add_subdirectory(csharp) endif(BUILD_SHARED_LIBS AND WIN32)�����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/bindings/csharp/����������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0017337�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/bindings/csharp/AssemblyInfo.cs.in����������������������������������������������0000664�0000000�0000000�00000002545�15201331742�0022674�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2025 Intel Corporation */ using System.Reflection; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Intel.Security.Metee")] [assembly: AssemblyDescription("Metee C# bindings")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Intel Corporation")] [assembly: AssemblyProduct("Intel.Security.Metee")] [assembly: AssemblyCopyright("Copyright (C) 2025 Intel Corporation")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("62336647-651e-4c5a-a92a-fbda141e6c4e")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // [assembly: AssemblyVersion("${TEE_VERSION_STRING}")] [assembly: AssemblyFileVersion("${TEE_VERSION_STRING}")] �����������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/bindings/csharp/CMakeLists.txt��������������������������������������������������0000664�0000000�0000000�00000001420�15201331742�0022074�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2025 Intel Corporation cmake_minimum_required(VERSION 3.8) project(Intel.Security.Metee VERSION 0.1.0 LANGUAGES CSharp) include(CSharpUtilities) configure_file(AssemblyInfo.cs.in ${CMAKE_CURRENT_SOURCE_DIR}/Properties/AssemblyInfo.cs) add_library(Intel.Security.Metee Metee.cs Properties/AssemblyInfo.cs ) add_dependencies(Intel.Security.Metee metee) set_property(TARGET Intel.Security.Metee PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1") set_property(TARGET Intel.Security.Metee PROPERTY VS_DOTNET_REFERENCES "System" "System.Core" "System.Data.DataSetExtensions" "Microsoft.CSharp" "System.Data" ) install(TARGETS Intel.Security.Metee RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/bindings/csharp/Metee.cs��������������������������������������������������������0000664�0000000�0000000�00000037453�15201331742�0020741�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2025 Intel Corporation */ using System; using System.Runtime.InteropServices; using System.Text; using Microsoft.Win32.SafeHandles; namespace Intel.Security { public class MeteeException : Exception { public TeeStatus ErrorCode { get; } public enum TeeStatus { TeeSuccess = 0x0000, TeeInternalError = 0x0001, TeeDeviceNotFound = 0x0002, TeeDeviceNotReady = 0x0003, TeeInvalidParameter = 0x0004, TeeUnableToCompleteOperation = 0x0005, TeeTimeout = 0x0006, TeeNotSupported = 0x0007, TeeClientNotFound = 0x0008, TeeBusy = 0x0009, TeeDisconnected = 0x000A, TeeInsufficientBuffer = 0x000B, TeePermissionDenied = 0x000C } public MeteeException(string message, int errorCode) : base(message) { ErrorCode = (TeeStatus)errorCode; } } public class Metee : IDisposable { // Reference: https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose#implement-the-dispose-pattern-using-a-custom-safe-handle // Wraps the IntPtr allocated by Marshal.AllocHGlobal() into a SafeHandle. class LocalAllocHandle : SafeHandleZeroOrMinusOneIsInvalid { private LocalAllocHandle() : base(ownsHandle: true) { } // No need to implement a finalizer - SafeHandle's finalizer will call ReleaseHandle for you. protected override bool ReleaseHandle() { Marshal.FreeHGlobal(handle); return true; } // Allocate bytes with Marshal.AllocHGlobal() and wrap the result into a SafeHandle. public static LocalAllocHandle Allocate(int numberOfBytes) { IntPtr nativeHandle = Marshal.AllocHGlobal(numberOfBytes); LocalAllocHandle safeHandle = new LocalAllocHandle(); safeHandle.SetHandle(nativeHandle); return safeHandle; } } private LocalAllocHandle _safeHandle = LocalAllocHandle.Allocate(Marshal.SizeOf<TeeHandle>()); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void LogCallback( [MarshalAs(UnmanagedType.I1)] bool isError, [In][MarshalAs(UnmanagedType.LPStr)] string msg ); #region DllImport private enum TeeDeviceType { None = 0, Path = 1, Guid = 3, } [StructLayout(LayoutKind.Sequential, Pack = 1)] private struct TeeDeviceAddress : IDisposable { public TeeDeviceAddress(string devicePath) { DeviceType = TeeDeviceType.Path; DataPtr = Marshal.StringToHGlobalAnsi(devicePath); } public TeeDeviceAddress(Guid guid) { DeviceType = TeeDeviceType.Guid; DataPtr = Marshal.AllocHGlobal(Marshal.SizeOf<Guid>()); Marshal.StructureToPtr(guid, DataPtr, false); } [MarshalAs(UnmanagedType.I4)] public TeeDeviceType DeviceType; public IntPtr DataPtr; public void Dispose() { if (DataPtr != IntPtr.Zero) Marshal.FreeHGlobal(DataPtr); } } // Struct should be big enough to hold the data // without depending on the padding in the C struct [StructLayout(LayoutKind.Sequential)] private struct TeeHandle { private readonly IntPtr Field1; private readonly IntPtr Field2; private readonly IntPtr Field3; private readonly IntPtr Field4; private readonly IntPtr Field5; private readonly IntPtr Field6; } [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeInit(IntPtr handle, ref Guid guid, IntPtr device); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeInitFull2(IntPtr handle, ref Guid guid, TeeDeviceAddress deviceAddress, [MarshalAs(UnmanagedType.U4)] TeeLogLevel logLevel, LogCallback logCallback); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeConnect(IntPtr handle); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeDisconnect(IntPtr handle); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeRead(IntPtr handle, byte[] buffer, int bufferSize, out int bytesRead, uint timeout); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeWrite(IntPtr handle, byte[] buffer, int bufferSize, out int bytesWritten, uint timeout); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeFWStatus(IntPtr handle, uint fwStatusNum, out uint fwStatus); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeGetTRC(IntPtr handle, out uint trc); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int TeeGetKind(IntPtr handle, StringBuilder kind, ref int kindSize); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern uint TeeSetLogLevel(IntPtr handle, uint logLevel); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern uint TeeGetLogLevel(IntPtr handle); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern uint TeeGetMaxMsgLen(IntPtr handle); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern uint TeeGetProtocolVer(IntPtr handle); [DllImport("metee.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int GetDriverVersion(IntPtr handle, out TeeDriverVersion driverVersion); [StructLayout(LayoutKind.Sequential)] private struct TeeDriverVersion { public readonly short Major; public readonly short Minor; public readonly short Hotfix; public readonly short Build; } #endregion public enum TeeLogLevel { Quiet = 0, // no log prints Error = 1, // error log prints Verbose = 2, // verbose log prints } /** * Use this constructor to query driver, without connecting to FW client. */ public Metee() { Guid zeroGuid = Guid.Empty; int status = TeeInit(_safeHandle.DangerousGetHandle(), ref zeroGuid, IntPtr.Zero); if (status != 0) { throw new MeteeException("Init failed", status); } FwStatus = new FwSts(this); } /** * Use this constructor to connect to default driver instance. * Useful when only one instance of driver is present in the system. * * @param clientGuid - GUID of the FW client that want to start a session * @param logLevel - log level to set * @param logCallback - callback to be called on each log message */ public Metee(Guid clientGuid, TeeLogLevel logLevel = TeeLogLevel.Quiet, LogCallback logCallback = default) { var device = new TeeDeviceAddress { DeviceType = TeeDeviceType.None, DataPtr = IntPtr.Zero }; int status = TeeInitFull2(_safeHandle.DangerousGetHandle(), ref clientGuid, device, logLevel, logCallback); if (status != 0) { throw new MeteeException("Init failed", status); } FwStatus = new FwSts(this); } /** * Use this constructor to connect to a specific driver instance. * This is particularly useful when multiple driver instances are present in the system * and you have the instance path. * * @param clientGuid - FW client GUID * @param devicePath - Instance path * @param logLevel - log level to set * @param logCallback - callback to be called on each log message */ public Metee(Guid clientGuid, string devicePath, TeeLogLevel logLevel = TeeLogLevel.Quiet, LogCallback logCallback = default) { int status = 1; using (var device = new TeeDeviceAddress(devicePath)) { status = TeeInitFull2(_safeHandle.DangerousGetHandle(), ref clientGuid, device, logLevel, logCallback); } if (status != 0) { throw new MeteeException("Init failed", status); } FwStatus = new FwSts(this); } /** * Use this constructor to connect to a specific driver instance. * This is particularly useful when multiple driver instances are present in the system * and you have the instance interface GUID. * * @param clientGuid - FW client GUID * @param interfaceGuid - Instance interface GUID * @param logLevel - log level to set * @param logCallback - callback to be called on each log message */ public Metee(Guid clientGuid, Guid interfaceGuid, TeeLogLevel logLevel = TeeLogLevel.Quiet, LogCallback logCallback = default) { int status = 1; using (var device = new TeeDeviceAddress(interfaceGuid)) { status = TeeInitFull2(_safeHandle.DangerousGetHandle(), ref clientGuid, device, logLevel, logCallback); } if (status != 0) { throw new MeteeException("Init failed", status); } FwStatus = new FwSts(this); } /** * Connects to the TEE driver and starts a session */ public void Connect() { int status = TeeConnect(_safeHandle.DangerousGetHandle()); if (status != 0) { throw new MeteeException("Connect failed", status); } } /** * Read data from the TEE device synchronously. * @param timeout - timeout in milliseconds * @return - data read from the device */ public byte[] Read(uint timeout) { var maxMsgLen = GetMaxMsgLen(); var buffer = new byte[maxMsgLen]; int status = TeeRead(_safeHandle.DangerousGetHandle(), buffer, buffer.Length, out var bytesRead, timeout); if (status != 0) { throw new MeteeException("Read failed", status); } Array.Resize(ref buffer, bytesRead); return buffer; } /** * Write data to the TEE device synchronously. * @param buffer - data to write * @param timeout - timeout in milliseconds * @return - number of bytes written */ public uint Write(byte[] buffer, uint timeout) { int status = TeeWrite(_safeHandle.DangerousGetHandle(), buffer, buffer.Length, out var bytesWritten, timeout); if (status != 0) { throw new MeteeException("Write failed", status); } return (uint)bytesWritten; } #region Properties getters private uint GetFwStatus(RegIndex index) { int status = TeeFWStatus(_safeHandle.DangerousGetHandle(), (uint)index, out var fwStatus); if (status != 0) { throw new MeteeException("FWStatus failed", status); } return fwStatus; } private uint GetTrc() { int status = TeeGetTRC(_safeHandle.DangerousGetHandle(), out var trc); if (status != 0) { throw new MeteeException("GetTRC failed", status); } return trc; } private string GetKind() { int kindSize = 32; StringBuilder kind = new StringBuilder(kindSize); int status = TeeGetKind(_safeHandle.DangerousGetHandle(), kind, ref kindSize); if (status != 0) { throw new MeteeException("TeeGetKind failed", status); } return kind.ToString(); } private uint SetLogLevel(uint logLevel) { return TeeSetLogLevel(_safeHandle.DangerousGetHandle(), logLevel); } private uint GetLogLevel() { return TeeGetLogLevel(_safeHandle.DangerousGetHandle()); } private uint GetMaxMsgLen() { return TeeGetMaxMsgLen(_safeHandle.DangerousGetHandle()); } private uint GetProtocolVer() { return TeeGetProtocolVer(_safeHandle.DangerousGetHandle()); } private string GetDriverVersion() { int status = GetDriverVersion(_safeHandle.DangerousGetHandle(), out var driverVersion); if (status != 0) { throw new MeteeException("GetDriverVersion failed", status); } return $"{driverVersion.Major}.{driverVersion.Minor}.{driverVersion.Hotfix}.{driverVersion.Build}"; } #endregion /** * Obtains kind of the TEE device */ public string Kind => GetKind(); /** * Obtains version of the TEE device driver */ public string DriverVersion => GetDriverVersion(); /** * Retrieve client protocol version */ public uint ProtocolVersion => GetProtocolVer(); /** * Get/Set current log level */ public uint LogLevel { get => GetLogLevel(); set => SetLogLevel(value); } /** * Retrieve client maximum message length (MTU) */ public uint MaxMsgLen => GetMaxMsgLen(); /** * Retrieves TRC register. */ public uint Trc => GetTrc(); public enum RegIndex { FwStatus1 = 0, FwStatus2 = 1, FwStatus3 = 2, FwStatus4 = 3, FwStatus5 = 4, FwStatus6 = 5, } public class FwSts { private Metee _metee; internal FwSts(Metee metee) { _metee = metee; } public uint this[RegIndex index] => _metee.GetFwStatus(index); } /** * Retrieves specified FW status register. */ public FwSts FwStatus; #region IDisposable private bool _isDisposed = false; /** * Public implementation of Dispose pattern callable by consumers. */ public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /** * Protected implementation of Dispose pattern. */ protected virtual void Dispose(bool disposing) { if (!_isDisposed) { _isDisposed = true; if (disposing) { if (_safeHandle != null) { TeeDisconnect(_safeHandle.DangerousGetHandle()); _safeHandle?.Dispose(); _safeHandle = null; } } } } #endregion } }���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/get-version.py������������������������������������������������������������������0000775�0000000�0000000�00000000461�15201331742�0017102�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/usr/bin/python3 # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2020 Intel Corporation def get_ver(): ''' Obtain version string from VERSION file ''' with open('VERSION') as the_fd: return the_fd.readline() if __name__ == '__main__': version = get_ver() print(version) ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/gitlint/������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0015734�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/gitlint/rules.py����������������������������������������������������������������0000664�0000000�0000000�00000003065�15201331742�0017444�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: BSD-3-Clause # Copyright (C) 2020 Intel Corporation from gitlint.rules import CommitRule, RuleViolation from gitlint.options import IntOption, ListOption from gitlint import utils class BodyMinLineCount(CommitRule): name = "body-min-line-count" # A rule MUST have a *unique* id, we recommend starting with UC (for User-defined Commit-rule). id = "UC1" options_spec = [IntOption('min-line-count', 1, "Minimum body line count excluding Signed-off-by")] def validate(self, commit): filtered = [x for x in commit.message.body if not x.lower().startswith("signed-off-by") and x != ''] line_count = len(filtered) min_line_count = self.options['min-line-count'].value if line_count < min_line_count: message = "Body has no content, should at least have {} line.".format(min_line_count) return [RuleViolation(self.id, message, line_nr=1)] class SignedOffBy(CommitRule): """ This rule will enforce that each commit contains a "Signed-off-by:" line. We keep things simple here and just check whether the commit body contains a line that starts with "Signed-off-by:". """ name = "body-requires-signed-off-by" # A rule MUST have a *unique* id, we recommend starting with UC (for User-defined Commit-rule). id = "UC2" def validate(self, commit): for line in commit.message.body: if line.startswith("Signed-off-by:"): return return [RuleViolation(self.id, "Body does not contain a 'Signed-off-by' line", line_nr=1)] ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/include/������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0015705�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/include/Doxyfile.in�������������������������������������������������������������0000664�0000000�0000000�00000367032�15201331742�0020033�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2014-2025 Intel Corporation # Doxyfile 1.9.8 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. # # All text after a double hash (##) is considered a comment and is placed in # front of the TAG it is preceding. # # All text after a single hash (#) is considered a comment and will be ignored. # The format is: # TAG = value [value, ...] # For lists, items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (\" \"). # # Note: # # Use doxygen to compare the used configuration file with the template # configuration file: # doxygen -x [configFile] # Use doxygen to compare the used configuration file with the template # configuration file without replacing the environment variables or CMake type # replacement variables: # doxygen -x_noenv [configFile] #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the configuration # file that follow. The default is UTF-8 which is also the encoding used for all # text before the first occurrence of this tag. Doxygen uses libiconv (or the # iconv built into libc) for the transcoding. See # https://www.gnu.org/software/libiconv/ for the list of possible encodings. # The default value is: UTF-8. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded by # double-quotes, unless you are using Doxywizard) that should identify the # project for which the documentation is generated. This name is used in the # title of most generated pages and in a few other places. # The default value is: My Project. PROJECT_NAME = metee # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version # control system is used. PROJECT_NUMBER = # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # the logo to the output directory. PROJECT_LOGO = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is # entered, it will be relative to the location where doxygen was started. If # left blank the current directory will be used. OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT_DIRECTORY@ # If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 # sub-directories (in 2 levels) under the output directory of each output format # and will distribute the generated files over these directories. Enabling this # option can be useful when feeding doxygen a huge amount of source files, where # putting all generated files in the same directory would otherwise causes # performance problems for the file system. Adapt CREATE_SUBDIRS_LEVEL to # control the number of sub-directories. # The default value is: NO. CREATE_SUBDIRS = NO # Controls the number of sub-directories that will be created when # CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every # level increment doubles the number of directories, resulting in 4096 # directories at level 8 which is the default and also the maximum value. The # sub-directories are organized in 2 levels, the first level always has a fixed # number of 16 directories. # Minimum value: 0, maximum value: 8, default value: 8. # This tag requires that the tag CREATE_SUBDIRS is set to YES. CREATE_SUBDIRS_LEVEL = 8 # If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII # characters to appear in the names of generated files. If set to NO, non-ASCII # characters will be escaped, for example _xE3_x81_x84 will be used for Unicode # U+3044. # The default value is: NO. ALLOW_UNICODE_NAMES = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Bulgarian, # Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, English # (United States), Esperanto, Farsi (Persian), Finnish, French, German, Greek, # Hindi, Hungarian, Indonesian, Italian, Japanese, Japanese-en (Japanese with # English messages), Korean, Korean-en (Korean with English messages), Latvian, # Lithuanian, Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, # Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, # Swedish, Turkish, Ukrainian and Vietnamese. # The default value is: English. OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member # descriptions after the members that are listed in the file and class # documentation (similar to Javadoc). Set to NO to disable this. # The default value is: YES. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief # description of a member or function before the detailed description # # Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. # The default value is: YES. REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator that is # used to form the text in various listings. Each string in this list, if found # as the leading text of the brief description, will be stripped from the text # and the result, after processing the whole list, is used as the annotated # text. Otherwise, the brief description is used as-is. If left blank, the # following values are used ($name is automatically replaced with the name of # the entity):The $name class, The $name widget, The $name file, is, provides, # specifies, contains, represents, a, an and the. ABBREVIATE_BRIEF = # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # doxygen will generate a detailed section even if there is only a brief # description. # The default value is: NO. ALWAYS_DETAILED_SEC = NO # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. # The default value is: NO. INLINE_INHERITED_MEMB = NO # If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path # before files name in the file list and in the header files. If set to NO the # shortest path that makes the file name unique will be used # The default value is: YES. FULL_PATH_NAMES = NO # The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. # Stripping is only done if one of the specified strings matches the left-hand # part of the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the path to # strip. # # Note that you can specify absolute paths here, but also relative paths, which # will be relative from the directory where doxygen is started. # This tag requires that the tag FULL_PATH_NAMES is set to YES. STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the # path mentioned in the documentation of a class, which tells the reader which # header file to include in order to use a class. If left blank only the name of # the header file containing the class definition is used. Otherwise one should # specify the list of include paths that are normally passed to the compiler # using the -I flag. STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but # less readable) file names. This can be useful is your file systems doesn't # support long names like on DOS, Mac, or CD-ROM. # The default value is: NO. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the # first line (until the first dot) of a Javadoc-style comment as the brief # description. If set to NO, the Javadoc-style will behave just like regular Qt- # style comments (thus requiring an explicit @brief command for a brief # description.) # The default value is: NO. JAVADOC_AUTOBRIEF = NO # If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line # such as # /*************** # as being the beginning of a Javadoc-style comment "banner". If set to NO, the # Javadoc-style will behave just like regular comments and it will not be # interpreted by doxygen. # The default value is: NO. JAVADOC_BANNER = NO # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first # line (until the first dot) of a Qt-style comment as the brief description. If # set to NO, the Qt-style will behave just like regular Qt-style comments (thus # requiring an explicit \brief command for a brief description.) # The default value is: NO. QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a # multi-line C++ special comment block (i.e. a block of //! or /// comments) as # a brief description. This used to be the default behavior. The new default is # to treat a multi-line C++ comment block as a detailed description. Set this # tag to YES if you prefer the old behavior instead. # # Note that setting this tag to YES also means that rational rose comments are # not recognized any more. # The default value is: NO. MULTILINE_CPP_IS_BRIEF = NO # By default Python docstrings are displayed as preformatted text and doxygen's # special commands cannot be used. By setting PYTHON_DOCSTRING to NO the # doxygen's special commands can be used and the contents of the docstring # documentation blocks is shown as doxygen documentation. # The default value is: YES. PYTHON_DOCSTRING = YES # If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the # documentation from any documented member that it re-implements. # The default value is: YES. INHERIT_DOCS = YES # If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new # page for each member. If set to NO, the documentation of a member will be part # of the file/class/namespace that contains it. # The default value is: NO. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen # uses this value to replace tabs by spaces in code fragments. # Minimum value: 1, maximum value: 16, default value: 4. TAB_SIZE = 4 # This tag can be used to specify a number of aliases that act as commands in # the documentation. An alias has the form: # name=value # For example adding # "sideeffect=@par Side Effects:^^" # will allow you to put the command \sideeffect (or @sideeffect) in the # documentation, which will result in a user-defined paragraph with heading # "Side Effects:". Note that you cannot put \n's in the value part of an alias # to insert newlines (in the resulting output). You can put ^^ in the value part # of an alias to insert a newline as if a physical newline was in the original # file. When you need a literal { or } or , in the value part of an alias you # have to escape them by means of a backslash (\), this can lead to conflicts # with the commands \{ and \} for these it is advised to use the version @{ and # @} or use a double escape (\\{ and \\}) ALIASES = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For # instance, some of the names that are used will be different. The list of all # members will be omitted, etc. # The default value is: NO. OPTIMIZE_OUTPUT_FOR_C = YES # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or # Python sources only. Doxygen will then generate output that is more tailored # for that language. For instance, namespaces will be presented as packages, # qualified scopes will look different, etc. # The default value is: NO. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources. Doxygen will then generate output that is tailored for Fortran. # The default value is: NO. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for VHDL. # The default value is: NO. OPTIMIZE_OUTPUT_VHDL = NO # Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice # sources only. Doxygen will then generate output that is more tailored for that # language. For instance, namespaces will be presented as modules, types will be # separated into more groups, etc. # The default value is: NO. OPTIMIZE_OUTPUT_SLICE = NO # Doxygen selects the parser to use depending on the extension of the files it # parses. With this tag you can assign which parser to use for a given # extension. Doxygen has a built-in mapping, but you can override or extend it # using this tag. The format is ext=language, where ext is a file extension, and # language is one of the parsers supported by doxygen: IDL, Java, JavaScript, # Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice, # VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: # FortranFree, unknown formatted Fortran: Fortran. In the later case the parser # tries to guess whether the code is fixed or free formatted code, this is the # default for Fortran type files). For instance to make doxygen treat .inc files # as Fortran files (default is PHP), and .f files as C (default is Fortran), # use: inc=Fortran f=C. # # Note: For files without extension you can use no_extension as a placeholder. # # Note that for custom extensions you also need to set FILE_PATTERNS otherwise # the files are not read by doxygen. When specifying no_extension you should add # * to the FILE_PATTERNS. # # Note see also the list of default file extension mappings. EXTENSION_MAPPING = # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable # documentation. See https://daringfireball.net/projects/markdown/ for details. # The output of markdown processing is further processed by doxygen, so you can # mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in # case of backward compatibilities issues. # The default value is: YES. MARKDOWN_SUPPORT = YES # When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up # to that level are automatically included in the table of contents, even if # they do not have an id attribute. # Note: This feature currently applies only to Markdown headings. # Minimum value: 0, maximum value: 99, default value: 5. # This tag requires that the tag MARKDOWN_SUPPORT is set to YES. TOC_INCLUDE_HEADINGS = 0 # The MARKDOWN_ID_STYLE tag can be used to specify the algorithm used to # generate identifiers for the Markdown headings. Note: Every identifier is # unique. # Possible values are: DOXYGEN use a fixed 'autotoc_md' string followed by a # sequence number starting at 0 and GITHUB use the lower case version of title # with any whitespace replaced by '-' and punctuation characters removed. # The default value is: DOXYGEN. # This tag requires that the tag MARKDOWN_SUPPORT is set to YES. MARKDOWN_ID_STYLE = DOXYGEN # When enabled doxygen tries to link words that correspond to documented # classes, or namespaces to their corresponding documentation. Such a link can # be prevented in individual cases by putting a % sign in front of the word or # globally by setting AUTOLINK_SUPPORT to NO. # The default value is: YES. AUTOLINK_SUPPORT = YES # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should set this # tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); # versus func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. # The default value is: NO. BUILTIN_STL_SUPPORT = NO # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. # The default value is: NO. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip (see: # https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen # will parse them like normal C++ but will assume all classes use public instead # of private inheritance when no explicit protection keyword is present. # The default value is: NO. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate # getter and setter methods for a property. Setting this option to YES will make # doxygen to replace the get and set methods by a property in the documentation. # This will only work if the methods are indeed getting or setting a simple # type. If this is not the case, or you want to show the methods anyway, you # should set this option to NO. # The default value is: YES. IDL_PROPERTY_SUPPORT = YES # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. # The default value is: NO. DISTRIBUTE_GROUP_DOC = NO # If one adds a struct or class to a group and this option is enabled, then also # any nested class or struct is added to the same group. By default this option # is disabled and one has to add nested compounds explicitly via \ingroup. # The default value is: NO. GROUP_NESTED_COMPOUNDS = NO # Set the SUBGROUPING tag to YES to allow class member groups of the same type # (for instance a group of public functions) to be put as a subgroup of that # type (e.g. under the Public Functions section). Set it to NO to prevent # subgrouping. Alternatively, this can be done per class using the # \nosubgrouping command. # The default value is: YES. SUBGROUPING = YES # When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions # are shown inside the group in which they are included (e.g. using \ingroup) # instead of on a separate page (for HTML and Man pages) or section (for LaTeX # and RTF). # # Note that this feature does not work in combination with # SEPARATE_MEMBER_PAGES. # The default value is: NO. INLINE_GROUPED_CLASSES = NO # When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions # with only public data fields or simple typedef fields will be shown inline in # the documentation of the scope in which they are defined (i.e. file, # namespace, or group documentation), provided this scope is documented. If set # to NO, structs, classes, and unions are shown on a separate page (for HTML and # Man pages) or section (for LaTeX and RTF). # The default value is: NO. INLINE_SIMPLE_STRUCTS = NO # When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or # enum is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically be # useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. # The default value is: NO. TYPEDEF_HIDES_STRUCT = NO # The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This # cache is used to resolve symbols given their name and scope. Since this can be # an expensive process and often the same symbol appears multiple times in the # code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small # doxygen will become slower. If the cache is too large, memory is wasted. The # cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range # is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 # symbols. At the end of a run doxygen will report the cache usage and suggest # the optimal cache size from a speed point of view. # Minimum value: 0, maximum value: 9, default value: 0. LOOKUP_CACHE_SIZE = 0 # The NUM_PROC_THREADS specifies the number of threads doxygen is allowed to use # during processing. When set to 0 doxygen will based this on the number of # cores available in the system. You can set it explicitly to a value larger # than 0 to get more control over the balance between CPU load and processing # speed. At this moment only the input processing can be done using multiple # threads. Since this is still an experimental feature the default is set to 1, # which effectively disables parallel processing. Please report any issues you # encounter. Generating dot graphs in parallel is controlled by the # DOT_NUM_THREADS setting. # Minimum value: 0, maximum value: 32, default value: 1. NUM_PROC_THREADS = 1 # If the TIMESTAMP tag is set different from NO then each generated page will # contain the date or date and time when the page was generated. Setting this to # NO can help when comparing the output of multiple runs. # Possible values are: YES, NO, DATETIME and DATE. # The default value is: NO. TIMESTAMP = NO #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in # documentation are documented, even if no documentation was available. Private # class members and static file members will be hidden unless the # EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. # Note: This will also disable the warnings about undocumented members that are # normally produced when WARNINGS is set to YES. # The default value is: NO. EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will # be included in the documentation. # The default value is: NO. EXTRACT_PRIVATE = NO # If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual # methods of a class will be included in the documentation. # The default value is: NO. EXTRACT_PRIV_VIRTUAL = NO # If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal # scope will be included in the documentation. # The default value is: NO. EXTRACT_PACKAGE = NO # If the EXTRACT_STATIC tag is set to YES, all static members of a file will be # included in the documentation. # The default value is: NO. EXTRACT_STATIC = NO # If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined # locally in source files will be included in the documentation. If set to NO, # only classes defined in header files are included. Does not have any effect # for Java sources. # The default value is: YES. EXTRACT_LOCAL_CLASSES = YES # This flag is only useful for Objective-C code. If set to YES, local methods, # which are defined in the implementation section but not in the interface are # included in the documentation. If set to NO, only methods in the interface are # included. # The default value is: NO. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base name of # the file that contains the anonymous namespace. By default anonymous namespace # are hidden. # The default value is: NO. EXTRACT_ANON_NSPACES = NO # If this flag is set to YES, the name of an unnamed parameter in a declaration # will be determined by the corresponding definition. By default unnamed # parameters remain unnamed in the output. # The default value is: YES. RESOLVE_UNNAMED_PARAMS = YES # If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all # undocumented members inside documented classes or files. If set to NO these # members will be included in the various overviews, but no documentation # section is generated. This option has no effect if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_MEMBERS = NO # If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. If set # to NO, these classes will be included in the various overviews. This option # will also hide undocumented C++ concepts if enabled. This option has no effect # if EXTRACT_ALL is enabled. # The default value is: NO. HIDE_UNDOC_CLASSES = NO # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend # declarations. If set to NO, these declarations will be included in the # documentation. # The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any # documentation blocks found inside the body of a function. If set to NO, these # blocks will be appended to the function's detailed documentation block. # The default value is: NO. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation that is typed after a # \internal command is included. If the tag is set to NO then the documentation # will be excluded. Set it to YES to include the internal documentation. # The default value is: NO. INTERNAL_DOCS = NO # With the correct setting of option CASE_SENSE_NAMES doxygen will better be # able to match the capabilities of the underlying filesystem. In case the # filesystem is case sensitive (i.e. it supports files in the same directory # whose names only differ in casing), the option must be set to YES to properly # deal with such files in case they appear in the input. For filesystems that # are not case sensitive the option should be set to NO to properly deal with # output files written for symbols that only differ in casing, such as for two # classes, one named CLASS and the other named Class, and to also support # references to files without having to specify the exact matching casing. On # Windows (including Cygwin) and MacOS, users should typically set this option # to NO, whereas on Linux or other Unix flavors it should typically be set to # YES. # Possible values are: SYSTEM, NO and YES. # The default value is: SYSTEM. CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with # their full class and namespace scopes in the documentation. If set to YES, the # scope will be hidden. # The default value is: NO. HIDE_SCOPE_NAMES = NO # If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will # append additional text to a page's title, such as Class Reference. If set to # YES the compound reference will be hidden. # The default value is: NO. HIDE_COMPOUND_REFERENCE= NO # If the SHOW_HEADERFILE tag is set to YES then the documentation for a class # will show which file needs to be included to use the class. # The default value is: YES. SHOW_HEADERFILE = YES # If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of # the files that are included by a file in the documentation of that file. # The default value is: YES. SHOW_INCLUDE_FILES = YES # If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each # grouped member an include statement to the documentation, telling the reader # which file to include in order to use the member. # The default value is: NO. SHOW_GROUPED_MEMB_INC = NO # If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include # files with double quotes in the documentation rather than with sharp brackets. # The default value is: NO. FORCE_LOCAL_INCLUDES = NO # If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the # documentation for inline members. # The default value is: YES. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the # (detailed) documentation of file and class members alphabetically by member # name. If set to NO, the members will appear in declaration order. # The default value is: YES. SORT_MEMBER_DOCS = YES # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief # descriptions of file, namespace and class members alphabetically by member # name. If set to NO, the members will appear in declaration order. Note that # this will also influence the order of the classes in the class list. # The default value is: NO. SORT_BRIEF_DOCS = NO # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the # (brief and detailed) documentation of class members so that constructors and # destructors are listed first. If set to NO the constructors will appear in the # respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. # Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief # member documentation. # Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting # detailed member documentation. # The default value is: NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy # of group names into alphabetical order. If set to NO the group names will # appear in their defined order. # The default value is: NO. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by # fully-qualified names, including namespaces. If set to NO, the class list will # be sorted only by class name, not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the alphabetical # list. # The default value is: NO. SORT_BY_SCOPE_NAME = NO # If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper # type resolution of all parameters of a function it will reject a match between # the prototype and the implementation of a member function even if there is # only one candidate or it is obvious which candidate to choose by doing a # simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still # accept a match between prototype and implementation in such cases. # The default value is: NO. STRICT_PROTO_MATCHING = NO # The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo # list. This list is created by putting \todo commands in the documentation. # The default value is: YES. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test # list. This list is created by putting \test commands in the documentation. # The default value is: YES. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug # list. This list is created by putting \bug commands in the documentation. # The default value is: YES. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) # the deprecated list. This list is created by putting \deprecated commands in # the documentation. # The default value is: YES. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional documentation # sections, marked by \if <section_label> ... \endif and \cond <section_label> # ... \endcond blocks. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the # initial value of a variable or macro / define can have for it to appear in the # documentation. If the initializer consists of more lines than specified here # it will be hidden. Use a value of 0 to hide initializers completely. The # appearance of the value of individual variables and macros / defines can be # controlled using \showinitializer or \hideinitializer command in the # documentation regardless of this setting. # Minimum value: 0, maximum value: 10000, default value: 30. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated at # the bottom of the documentation of classes and structs. If set to YES, the # list will mention the files that were used to generate the documentation. # The default value is: YES. SHOW_USED_FILES = YES # Set the SHOW_FILES tag to NO to disable the generation of the Files page. This # will remove the Files entry from the Quick Index and from the Folder Tree View # (if specified). # The default value is: YES. SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces # page. This will remove the Namespaces entry from the Quick Index and from the # Folder Tree View (if specified). # The default value is: YES. SHOW_NAMESPACES = YES # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command command input-file, where command is the value of the # FILE_VERSION_FILTER tag, and input-file is the name of an input file provided # by doxygen. Whatever the program writes to standard output is used as the file # version. For an example see the documentation. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed # by doxygen. The layout file controls the global structure of the generated # output files in an output format independent way. To create the layout file # that represents doxygen's defaults, run doxygen with the -l option. You can # optionally specify a file name after the option, if omitted DoxygenLayout.xml # will be used as the name of the layout file. See also section "Changing the # layout of pages" for information. # # Note that if you run doxygen from a directory containing a file called # DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE # tag is left empty. LAYOUT_FILE = # The CITE_BIB_FILES tag can be used to specify one or more bib files containing # the reference definitions. This must be a list of .bib files. The .bib # extension is automatically appended if omitted. This requires the bibtex tool # to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. # For LaTeX the style of the bibliography can be controlled using # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the # search path. See also \cite for info how to create references. CITE_BIB_FILES = #--------------------------------------------------------------------------- # Configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated to # standard output by doxygen. If QUIET is set to YES this implies that the # messages are off. # The default value is: NO. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated to standard error (stderr) by doxygen. If WARNINGS is set to YES # this implies that the warnings are on. # # Tip: Turn warnings on while writing the documentation. # The default value is: YES. WARNINGS = YES # If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate # warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag # will automatically be disabled. # The default value is: YES. WARN_IF_UNDOCUMENTED = YES # If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as documenting some parameters in # a documented function twice, or documenting parameters that don't exist or # using markup commands wrongly. # The default value is: YES. WARN_IF_DOC_ERROR = YES # If WARN_IF_INCOMPLETE_DOC is set to YES, doxygen will warn about incomplete # function parameter documentation. If set to NO, doxygen will accept that some # parameters have no documentation without warning. # The default value is: YES. WARN_IF_INCOMPLETE_DOC = YES # This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that # are documented, but have no documentation for their parameters or return # value. If set to NO, doxygen will only warn about wrong parameter # documentation, but not about the absence of documentation. If EXTRACT_ALL is # set to YES then this flag will automatically be disabled. See also # WARN_IF_INCOMPLETE_DOC # The default value is: NO. WARN_NO_PARAMDOC = NO # If WARN_IF_UNDOC_ENUM_VAL option is set to YES, doxygen will warn about # undocumented enumeration values. If set to NO, doxygen will accept # undocumented enumeration values. If EXTRACT_ALL is set to YES then this flag # will automatically be disabled. # The default value is: NO. WARN_IF_UNDOC_ENUM_VAL = NO # If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when # a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS # then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but # at the end of the doxygen process doxygen will return with a non-zero status. # If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS_PRINT then doxygen behaves # like FAIL_ON_WARNINGS but in case no WARN_LOGFILE is defined doxygen will not # write the warning messages in between other messages but write them at the end # of a run, in case a WARN_LOGFILE is defined the warning messages will be # besides being in the defined file also be shown at the end of a run, unless # the WARN_LOGFILE is defined as - i.e. standard output (stdout) in that case # the behavior will remain as with the setting FAIL_ON_WARNINGS. # Possible values are: NO, YES, FAIL_ON_WARNINGS and FAIL_ON_WARNINGS_PRINT. # The default value is: NO. WARN_AS_ERROR = NO # The WARN_FORMAT tag determines the format of the warning messages that doxygen # can produce. The string should contain the $file, $line, and $text tags, which # will be replaced by the file and line number from which the warning originated # and the warning text. Optionally the format may contain $version, which will # be replaced by the version of the file (if it could be obtained via # FILE_VERSION_FILTER) # See also: WARN_LINE_FORMAT # The default value is: $file:$line: $text. WARN_FORMAT = "$file:$line: $text" # In the $text part of the WARN_FORMAT command it is possible that a reference # to a more specific place is given. To make it easier to jump to this place # (outside of doxygen) the user can define a custom "cut" / "paste" string. # Example: # WARN_LINE_FORMAT = "'vi $file +$line'" # See also: WARN_FORMAT # The default value is: at line $line of file $file. WARN_LINE_FORMAT = "at line $line of file $file" # The WARN_LOGFILE tag can be used to specify a file to which warning and error # messages should be written. If left blank the output is written to standard # error (stderr). In case the file specified cannot be opened for writing the # warning and error messages are written to standard error. When as file - is # specified the warning and error messages are written to standard output # (stdout). WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag is used to specify the files and/or directories that contain # documented source files. You may enter file names like myfile.cpp or # directories like /usr/src/myproject. Separate the files or directories with # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. INPUT = @DOXYGEN_INPUT_DIRECTORY@/include/metee.h @DOXYGEN_INPUT_DIRECTORY@/include/meteepp.h # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses # libiconv (or the iconv built into libc) for the transcoding. See the libiconv # documentation (see: # https://www.gnu.org/software/libiconv/) for the list of possible encodings. # See also: INPUT_FILE_ENCODING # The default value is: UTF-8. INPUT_ENCODING = UTF-8 # This tag can be used to specify the character encoding of the source files # that doxygen parses The INPUT_FILE_ENCODING tag can be used to specify # character encoding on a per file pattern basis. Doxygen will compare the file # name with each pattern and apply the encoding instead of the default # INPUT_ENCODING) if there is a match. The character encodings are a list of the # form: pattern=encoding (like *.php=ISO-8859-1). See cfg_input_encoding # "INPUT_ENCODING" for further information on supported encodings. INPUT_FILE_ENCODING = # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and # *.h) to filter out the source-files in the directories. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # read by doxygen. # # Note the list of default checked file patterns might differ from the list of # default file extension mappings. # # If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cxxm, # *.cpp, *.cppm, *.c++, *.c++m, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, # *.ddl, *.odl, *.h, *.hh, *.hxx, *.hpp, *.h++, *.ixx, *.l, *.cs, *.d, *.php, # *.php4, *.php5, *.phtml, *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be # provided as doxygen C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, # *.f18, *.f, *.for, *.vhd, *.vhdl, *.ucf, *.qsf and *.ice. FILE_PATTERNS = # The RECURSIVE tag can be used to specify whether or not subdirectories should # be searched for input files as well. # The default value is: NO. RECURSIVE = NO # The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. # # Note that relative paths are relative to the directory from which doxygen is # run. EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded # from the input. # The default value is: NO. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. # # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # ANamespace::AClass, ANamespace::*Test EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or directories # that contain example code fragments that are included (see the \include # command). EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and # *.h) to filter out the source-files in the directories. If left blank all # files are included. EXAMPLE_PATTERNS = # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude commands # irrespective of the value of the RECURSIVE tag. # The default value is: NO. EXAMPLE_RECURSIVE = NO # The IMAGE_PATH tag can be used to specify one or more files or directories # that contain images that are to be included in the documentation (see the # \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command: # # <filter> <input-file> # # where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the # name of an input file. Doxygen will then use the output that the filter # program writes to standard output. If FILTER_PATTERNS is specified, this tag # will be ignored. # # Note that the filter must not add or remove lines; it is applied before the # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. # # Note that doxygen will use the data processed and written to standard output # for further processing, therefore nothing else, like debug statements or used # commands (so in case of a Windows batch file always use @echo OFF), should be # written to standard output. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # properly processed by doxygen. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the # filter if there is a match. The filters are a list of the form: pattern=filter # (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how # filters are used. If the FILTER_PATTERNS tag is empty or if none of the # patterns match the file name, INPUT_FILTER is applied. # # Note that for custom extensions or not directly supported extensions you also # need to set EXTENSION_MAPPING for the extension otherwise the files are not # properly processed by doxygen. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will also be used to filter the input files that are used for # producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). # The default value is: NO. FILTER_SOURCE_FILES = NO # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file # pattern. A pattern will override the setting for FILTER_PATTERN (if any) and # it is also possible to disable source filtering for a specific pattern using # *.ext= (so without naming a filter). # This tag requires that the tag FILTER_SOURCE_FILES is set to YES. FILTER_SOURCE_PATTERNS = # If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that # is part of the input, its contents will be placed on the main page # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. USE_MDFILE_AS_MAINPAGE = # The Fortran standard specifies that for fixed formatted Fortran code all # characters from position 72 are to be considered as comment. A common # extension is to allow longer lines before the automatic comment starts. The # setting FORTRAN_COMMENT_AFTER will also make it possible that longer lines can # be processed before the automatic comment starts. # Minimum value: 7, maximum value: 10000, default value: 72. FORTRAN_COMMENT_AFTER = 72 #--------------------------------------------------------------------------- # Configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will be # generated. Documented entities will be cross-referenced with these sources. # # Note: To get rid of all source code in the generated output, make sure that # also VERBATIM_HEADERS is set to NO. # The default value is: NO. SOURCE_BROWSER = YES # Setting the INLINE_SOURCES tag to YES will include the body of functions, # classes and enums directly into the documentation. # The default value is: NO. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any # special comment blocks from generated source code fragments. Normal C, C++ and # Fortran comments will always remain visible. # The default value is: YES. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES then for each documented # entity all documented functions referencing it will be listed. # The default value is: NO. REFERENCED_BY_RELATION = NO # If the REFERENCES_RELATION tag is set to YES then for each documented function # all documented entities called/used by that function will be listed. # The default value is: NO. REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set # to YES then the hyperlinks from functions in REFERENCES_RELATION and # REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will # link to the documentation. # The default value is: YES. REFERENCES_LINK_SOURCE = YES # If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the # source code will show a tooltip with additional information such as prototype, # brief description and links to the definition and documentation. Since this # will make the HTML file larger and loading of large files a bit slower, you # can opt to disable this feature. # The default value is: YES. # This tag requires that the tag SOURCE_BROWSER is set to YES. SOURCE_TOOLTIPS = YES # If the USE_HTAGS tag is set to YES then the references to source code will # point to the HTML generated by the htags(1) tool instead of doxygen built-in # source browser. The htags tool is part of GNU's global source tagging system # (see https://www.gnu.org/software/global/global.html). You will need version # 4.8.6 or higher. # # To use it do the following: # - Install the latest version of global # - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file # - Make sure the INPUT points to the root of the source tree # - Run doxygen as normal # # Doxygen will invoke htags (and that will in turn invoke gtags), so these # tools must be available from the command line (i.e. in the search path). # # The result: instead of the source browser generated by doxygen, the links to # source code will now point to the output of htags. # The default value is: NO. # This tag requires that the tag SOURCE_BROWSER is set to YES. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a # verbatim copy of the header file for each class for which an include is # specified. Set to NO to disable this. # See also: Section \class. # The default value is: YES. VERBATIM_HEADERS = YES # If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the # clang parser (see: # http://clang.llvm.org/) for more accurate parsing at the cost of reduced # performance. This can be particularly helpful with template rich C++ code for # which doxygen's built-in parser lacks the necessary type information. # Note: The availability of this option depends on whether or not doxygen was # generated with the -Duse_libclang=ON option for CMake. # The default value is: NO. CLANG_ASSISTED_PARSING = NO # If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS # tag is set to YES then doxygen will add the directory of each input to the # include path. # The default value is: YES. # This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. CLANG_ADD_INC_PATHS = YES # If clang assisted parsing is enabled you can provide the compiler with command # line options that you would normally use when invoking the compiler. Note that # the include paths will already be set by doxygen for the files and directories # specified with INPUT and INCLUDE_PATH. # This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. CLANG_OPTIONS = # If clang assisted parsing is enabled you can provide the clang parser with the # path to the directory containing a file called compile_commands.json. This # file is the compilation database (see: # http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the # options used when the source files were built. This is equivalent to # specifying the -p option to a clang tool, such as clang-check. These options # will then be passed to the parser. Any options specified with CLANG_OPTIONS # will be added as well. # Note: The availability of this option depends on whether or not doxygen was # generated with the -Duse_libclang=ON option for CMake. CLANG_DATABASE_PATH = #--------------------------------------------------------------------------- # Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all # compounds will be generated. Enable this if the project contains a lot of # classes, structs, unions or interfaces. # The default value is: YES. ALPHABETICAL_INDEX = YES # The IGNORE_PREFIX tag can be used to specify a prefix (or a list of prefixes) # that should be ignored while generating the index headers. The IGNORE_PREFIX # tag works for classes, function and member names. The entity will be placed in # the alphabetical list under the first letter of the entity name that remains # after removing the prefix. # This tag requires that the tag ALPHABETICAL_INDEX is set to YES. IGNORE_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output # The default value is: YES. GENERATE_HTML = YES # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: html. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for each # generated HTML page (for example: .htm, .php, .asp). # The default value is: .html. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a user-defined HTML header file for # each generated HTML page. If the tag is left blank doxygen will generate a # standard header. # # To get valid HTML the header file that includes any scripts and style sheets # that doxygen needs, which is dependent on the configuration options used (e.g. # the setting GENERATE_TREEVIEW). It is highly recommended to start with a # default header using # doxygen -w html new_header.html new_footer.html new_stylesheet.css # YourConfigFile # and then modify the file new_header.html. See also section "Doxygen usage" # for information on how to generate the default header that doxygen normally # uses. # Note: The header is subject to change so you typically have to regenerate the # default header when upgrading to a newer version of doxygen. For a description # of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_HEADER = # The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each # generated HTML page. If the tag is left blank doxygen will generate a standard # footer. See HTML_HEADER for more information on how to generate a default # footer and what special commands can be used inside the footer. See also # section "Doxygen usage" for information on how to generate the default footer # that doxygen normally uses. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading style # sheet that is used by each HTML page. It can be used to fine-tune the look of # the HTML output. If left blank doxygen will generate a default style sheet. # See also section "Doxygen usage" for information on how to generate the style # sheet that doxygen normally uses. # Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as # it is more robust and this tag (HTML_STYLESHEET) will in the future become # obsolete. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_STYLESHEET = # The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined # cascading style sheets that are included after the standard style sheets # created by doxygen. Using this option one can overrule certain style aspects. # This is preferred over using HTML_STYLESHEET since it does not replace the # standard style sheet and is therefore more robust against future updates. # Doxygen will copy the style sheet files to the output directory. # Note: The order of the extra style sheet files is of importance (e.g. the last # style sheet in the list overrules the setting of the previous ones in the # list). # Note: Since the styling of scrollbars can currently not be overruled in # Webkit/Chromium, the styling will be left out of the default doxygen.css if # one or more extra stylesheets have been specified. So if scrollbar # customization is desired it has to be added explicitly. For an example see the # documentation. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_STYLESHEET = # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note # that these files will be copied to the base HTML output directory. Use the # $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these # files. In the HTML_STYLESHEET file, use the file name only. Also note that the # files will be copied as-is; there are no commands or markers available. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_EXTRA_FILES = # The HTML_COLORSTYLE tag can be used to specify if the generated HTML output # should be rendered with a dark or light theme. # Possible values are: LIGHT always generate light mode output, DARK always # generate dark mode output, AUTO_LIGHT automatically set the mode according to # the user preference, use light mode if no preference is set (the default), # AUTO_DARK automatically set the mode according to the user preference, use # dark mode if no preference is set and TOGGLE allow to user to switch between # light and dark mode via a button. # The default value is: AUTO_LIGHT. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE = AUTO_LIGHT # The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen # will adjust the colors in the style sheet and background images according to # this color. Hue is specified as an angle on a color-wheel, see # https://en.wikipedia.org/wiki/Hue for more information. For instance the value # 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 # purple, and 360 is red again. # Minimum value: 0, maximum value: 359, default value: 220. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_HUE = 220 # The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors # in the HTML output. For a value of 0 the output will use gray-scales only. A # value of 255 will produce the most vivid colors. # Minimum value: 0, maximum value: 255, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_SAT = 100 # The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the # luminance component of the colors in the HTML output. Values below 100 # gradually make the output lighter, whereas values above 100 make the output # darker. The value divided by 100 is the actual gamma applied, so 80 represents # a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not # change the gamma. # Minimum value: 40, maximum value: 240, default value: 80. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_GAMMA = 80 # If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML # documentation will contain a main index with vertical navigation menus that # are dynamically created via JavaScript. If disabled, the navigation index will # consists of multiple levels of tabs that are statically embedded in every HTML # page. Disable this option to support browsers that do not have JavaScript, # like the Qt help browser. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_MENUS = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_SECTIONS = NO # If the HTML_CODE_FOLDING tag is set to YES then classes and functions can be # dynamically folded and expanded in the generated HTML source code. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_CODE_FOLDING = YES # With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries # shown in the various tree structured indices initially; the user can expand # and collapse entries dynamically later on. Doxygen will expand the tree to # such a level that at most the specified number of entries are visible (unless # a fully collapsed tree already exceeds this amount). So setting the number of # entries 1 will produce a full collapsed tree by default. 0 is a special value # representing an infinite number of entries and will result in a full expanded # tree by default. # Minimum value: 0, maximum value: 9999, default value: 100. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_INDEX_NUM_ENTRIES = 100 # If the GENERATE_DOCSET tag is set to YES, additional index files will be # generated that can be used as input for Apple's Xcode 3 integrated development # environment (see: # https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To # create a documentation set, doxygen will generate a Makefile in the HTML # output directory. Running make will produce the docset in that directory and # running make install will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at # startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy # genXcode/_index.html for more information. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_DOCSET = NO # This tag determines the name of the docset feed. A documentation feed provides # an umbrella under which multiple documentation sets from a single provider # (such as a company or product suite) can be grouped. # The default value is: Doxygen generated docs. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDNAME = "Doxygen generated docs" # This tag determines the URL of the docset feed. A documentation feed provides # an umbrella under which multiple documentation sets from a single provider # (such as a company or product suite) can be grouped. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDURL = # This tag specifies a string that should uniquely identify the documentation # set bundle. This should be a reverse domain-name style string, e.g. # com.mycompany.MyDocSet. Doxygen will append .docset to the name. # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_BUNDLE_ID = org.doxygen.Project # The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify # the documentation publisher. This should be a reverse domain-name style # string, e.g. com.mycompany.MyDocSet.documentation. # The default value is: org.doxygen.Publisher. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_ID = org.doxygen.Publisher # The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. # The default value is: Publisher. # This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_NAME = Publisher # If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three # additional HTML index files: index.hhp, index.hhc, and index.hhk. The # index.hhp is a project file that can be read by Microsoft's HTML Help Workshop # on Windows. In the beginning of 2021 Microsoft took the original page, with # a.o. the download links, offline the HTML help workshop was already many years # in maintenance mode). You can download the HTML help workshop from the web # archives at Installation executable (see: # http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo # ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe). # # The HTML Help Workshop contains a compiler that can convert all HTML output # generated by doxygen into a single compiled HTML file (.chm). Compiled HTML # files are now used as the Windows 98 help format, and will replace the old # Windows help format (.hlp) on all Windows platforms in the future. Compressed # HTML files also contain an index, a table of contents, and you can search for # words in the documentation. The HTML workshop also contains a viewer for # compressed HTML files. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_HTMLHELP = NO # The CHM_FILE tag can be used to specify the file name of the resulting .chm # file. You can add a path in front of the file if the result should not be # written to the html output directory. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_FILE = # The HHC_LOCATION tag can be used to specify the location (absolute path # including file name) of the HTML help compiler (hhc.exe). If non-empty, # doxygen will try to run the HTML help compiler on the generated index.hhp. # The file has to be specified with full path. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. HHC_LOCATION = # The GENERATE_CHI flag controls if a separate .chi index file is generated # (YES) or that it should be included in the main .chm file (NO). # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO # The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) # and project file content. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. CHM_INDEX_ENCODING = # The BINARY_TOC flag controls whether a binary table of contents is generated # (YES) or a normal table of contents (NO) in the .chm file. Furthermore it # enables the Previous and Next buttons. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members to # the table of contents of the HTML help documentation and to the tree view. # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. TOC_EXPAND = NO # The SITEMAP_URL tag is used to specify the full URL of the place where the # generated documentation will be placed on the server by the user during the # deployment of the documentation. The generated sitemap is called sitemap.xml # and placed on the directory specified by HTML_OUTPUT. In case no SITEMAP_URL # is specified no sitemap is generated. For information about the sitemap # protocol see https://www.sitemaps.org # This tag requires that the tag GENERATE_HTML is set to YES. SITEMAP_URL = # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and # QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that # can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help # (.qch) of the generated HTML documentation. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify # the file name of the resulting .qch file. The path specified is relative to # the HTML output folder. # This tag requires that the tag GENERATE_QHP is set to YES. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help # Project output. For more information please see Qt Help Project / Namespace # (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_QHP is set to YES. QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt # Help Project output. For more information please see Qt Help Project / Virtual # Folders (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). # The default value is: doc. # This tag requires that the tag GENERATE_QHP is set to YES. QHP_VIRTUAL_FOLDER = doc # If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom # filter to add. For more information please see Qt Help Project / Custom # Filters (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_NAME = # The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the # custom filter to add. For more information please see Qt Help Project / Custom # Filters (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this # project's filter section matches. Qt Help Project / Filter Attributes (see: # https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). # This tag requires that the tag GENERATE_QHP is set to YES. QHP_SECT_FILTER_ATTRS = # The QHG_LOCATION tag can be used to specify the location (absolute path # including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to # run qhelpgenerator on the generated .qhp file. # This tag requires that the tag GENERATE_QHP is set to YES. QHG_LOCATION = # If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be # generated, together with the HTML files, they form an Eclipse help plugin. To # install this plugin and make it available under the help contents menu in # Eclipse, the contents of the directory containing the HTML and XML files needs # to be copied into the plugins directory of eclipse. The name of the directory # within the plugins directory should be the same as the ECLIPSE_DOC_ID value. # After copying Eclipse needs to be restarted before the help appears. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_ECLIPSEHELP = NO # A unique identifier for the Eclipse help plugin. When installing the plugin # the directory name containing the HTML and XML files should also have this # name. Each documentation set should have its own identifier. # The default value is: org.doxygen.Project. # This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. ECLIPSE_DOC_ID = org.doxygen.Project # If you want full control over the layout of the generated HTML pages it might # be necessary to disable the index and replace it with your own. The # DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top # of each HTML page. A value of NO enables the index and the value YES disables # it. Since the tabs in the index contain the same information as the navigation # tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. DISABLE_INDEX = NO # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. If the tag # value is set to YES, a side panel will be generated containing a tree-like # index structure (just like the one that is generated for HTML Help). For this # to work a browser that supports JavaScript, DHTML, CSS and frames is required # (i.e. any modern browser). Windows users are probably better off using the # HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can # further fine tune the look of the index (see "Fine-tuning the output"). As an # example, the default style sheet generated by doxygen has an example that # shows how to put an image at the root of the tree instead of the PROJECT_NAME. # Since the tree basically has the same information as the tab index, you could # consider setting DISABLE_INDEX to YES when enabling this option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_TREEVIEW = NO # When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the # FULL_SIDEBAR option determines if the side bar is limited to only the treeview # area (value NO) or if it should extend to the full height of the window (value # YES). Setting this to YES gives a layout similar to # https://docs.readthedocs.io with more room for contents, but less room for the # project logo, title, and description. If either GENERATE_TREEVIEW or # DISABLE_INDEX is set to NO, this option has no effect. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. FULL_SIDEBAR = NO # The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that # doxygen will group on one line in the generated HTML documentation. # # Note that a value of 0 will completely suppress the enum values from appearing # in the overview section. # Minimum value: 0, maximum value: 20, default value: 4. # This tag requires that the tag GENERATE_HTML is set to YES. ENUM_VALUES_PER_LINE = 4 # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used # to set the initial width (in pixels) of the frame in which the tree is shown. # Minimum value: 0, maximum value: 1500, default value: 250. # This tag requires that the tag GENERATE_HTML is set to YES. TREEVIEW_WIDTH = 250 # If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to # external symbols imported via tag files in a separate window. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. EXT_LINKS_IN_WINDOW = NO # If the OBFUSCATE_EMAILS tag is set to YES, doxygen will obfuscate email # addresses. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. OBFUSCATE_EMAILS = YES # If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg # tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see # https://inkscape.org) to generate formulas as SVG images instead of PNGs for # the HTML output. These images will generally look nicer at scaled resolutions. # Possible values are: png (the default) and svg (looks nicer but requires the # pdf2svg or inkscape tool). # The default value is: png. # This tag requires that the tag GENERATE_HTML is set to YES. HTML_FORMULA_FORMAT = png # Use this tag to change the font size of LaTeX formulas included as images in # the HTML documentation. When you change the font size after a successful # doxygen run you need to manually remove any form_*.png images from the HTML # output directory to force them to be regenerated. # Minimum value: 8, maximum value: 50, default value: 10. # This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_FONTSIZE = 10 # The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands # to create new LaTeX commands to be used in formulas as building blocks. See # the section "Including formulas" for details. FORMULA_MACROFILE = # Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see # https://www.mathjax.org) which uses client side JavaScript for the rendering # instead of using pre-rendered bitmaps. Use this if you do not have LaTeX # installed or if you want to formulas look prettier in the HTML output. When # enabled you may also need to install MathJax separately and configure the path # to it using the MATHJAX_RELPATH option. # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. USE_MATHJAX = NO # With MATHJAX_VERSION it is possible to specify the MathJax version to be used. # Note that the different versions of MathJax have different requirements with # regards to the different settings, so it is possible that also other MathJax # settings have to be changed when switching between the different MathJax # versions. # Possible values are: MathJax_2 and MathJax_3. # The default value is: MathJax_2. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_VERSION = MathJax_2 # When MathJax is enabled you can set the default output format to be used for # the MathJax output. For more details about the output format see MathJax # version 2 (see: # http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3 # (see: # http://docs.mathjax.org/en/latest/web/components/output.html). # Possible values are: HTML-CSS (which is slower, but has the best # compatibility. This is the name for Mathjax version 2, for MathJax version 3 # this will be translated into chtml), NativeMML (i.e. MathML. Only supported # for NathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This # is the name for Mathjax version 3, for MathJax version 2 this will be # translated into HTML-CSS) and SVG. # The default value is: HTML-CSS. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_FORMAT = HTML-CSS # When MathJax is enabled you need to specify the location relative to the HTML # output directory using the MATHJAX_RELPATH option. The destination directory # should contain the MathJax.js script. For instance, if the mathjax directory # is located at the same level as the HTML output directory, then # MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax # Content Delivery Network so you can quickly see the result without installing # MathJax. However, it is strongly recommended to install a local copy of # MathJax from https://www.mathjax.org before deployment. The default value is: # - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2 # - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3 # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest # The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax # extension names that should be enabled during MathJax rendering. For example # for MathJax version 2 (see # https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions): # MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols # For example for MathJax version 3 (see # http://docs.mathjax.org/en/latest/input/tex/extensions/index.html): # MATHJAX_EXTENSIONS = ams # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_EXTENSIONS = # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site # (see: # http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an # example see the documentation. # This tag requires that the tag USE_MATHJAX is set to YES. MATHJAX_CODEFILE = # When the SEARCHENGINE tag is enabled doxygen will generate a search box for # the HTML output. The underlying search engine uses javascript and DHTML and # should work on any modern browser. Note that when using HTML help # (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) # there is already a search function so this one should typically be disabled. # For large projects the javascript based search engine can be slow, then # enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to # search using the keyboard; to jump to the search box use <access key> + S # (what the <access key> is depends on the OS and browser, but it is typically # <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down # key> to jump into the search results window, the results can be navigated # using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel # the search. The filter options can be selected when the cursor is inside the # search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys> # to select a filter and <Enter> or <escape> to activate or cancel the filter # option. # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be # implemented using a web server instead of a web client using JavaScript. There # are two flavors of web server based searching depending on the EXTERNAL_SEARCH # setting. When disabled, doxygen will generate a PHP script for searching and # an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing # and searching needs to be provided by external tools. See the section # "External Indexing and Searching" for details. # The default value is: NO. # This tag requires that the tag SEARCHENGINE is set to YES. SERVER_BASED_SEARCH = NO # When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP # script for searching. Instead the search results are written to an XML file # which needs to be processed by an external indexer. Doxygen will invoke an # external search engine pointed to by the SEARCHENGINE_URL option to obtain the # search results. # # Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library # Xapian (see: # https://xapian.org/). # # See the section "External Indexing and Searching" for details. # The default value is: NO. # This tag requires that the tag SEARCHENGINE is set to YES. EXTERNAL_SEARCH = NO # The SEARCHENGINE_URL should point to a search engine hosted by a web server # which will return the search results when EXTERNAL_SEARCH is enabled. # # Doxygen ships with an example indexer (doxyindexer) and search engine # (doxysearch.cgi) which are based on the open source search engine library # Xapian (see: # https://xapian.org/). See the section "External Indexing and Searching" for # details. # This tag requires that the tag SEARCHENGINE is set to YES. SEARCHENGINE_URL = # When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed # search data is written to a file for indexing by an external tool. With the # SEARCHDATA_FILE tag the name of this file can be specified. # The default file is: searchdata.xml. # This tag requires that the tag SEARCHENGINE is set to YES. SEARCHDATA_FILE = searchdata.xml # When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the # EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is # useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple # projects and redirect the results back to the right project. # This tag requires that the tag SEARCHENGINE is set to YES. EXTERNAL_SEARCH_ID = # The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen # projects other than the one defined by this configuration file, but that are # all added to the same external search index. Each project needs to have a # unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of # to a relative location where the documentation can be found. The format is: # EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ... # This tag requires that the tag SEARCHENGINE is set to YES. EXTRA_SEARCH_MAPPINGS = #--------------------------------------------------------------------------- # Configuration options related to the LaTeX output #--------------------------------------------------------------------------- # If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output. # The default value is: YES. GENERATE_LATEX = NO # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: latex. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. # # Note that when not enabling USE_PDFLATEX the default is latex when enabling # USE_PDFLATEX the default is pdflatex and when in the later case latex is # chosen this is overwritten by pdflatex. For specific output languages the # default can have been set differently, this depends on the implementation of # the output language. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_CMD_NAME = latex # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate # index for LaTeX. # Note: This tag is used in the Makefile / make.bat. # See also: LATEX_MAKEINDEX_CMD for the part in the generated output file # (.tex). # The default file is: makeindex. # This tag requires that the tag GENERATE_LATEX is set to YES. MAKEINDEX_CMD_NAME = makeindex # The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to # generate index for LaTeX. In case there is no backslash (\) as first character # it will be automatically added in the LaTeX code. # Note: This tag is used in the generated output file (.tex). # See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat. # The default value is: makeindex. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_MAKEINDEX_CMD = \makeindex # If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX # documents. This may be useful for small projects and may help to save some # trees in general. # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. COMPACT_LATEX = NO # The PAPER_TYPE tag can be used to set the paper type that is used by the # printer. # Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x # 14 inches) and executive (7.25 x 10.5 inches). # The default value is: a4. # This tag requires that the tag GENERATE_LATEX is set to YES. PAPER_TYPE = a4 # The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names # that should be included in the LaTeX output. The package can be specified just # by its name or with the correct syntax as to be used with the LaTeX # \usepackage command. To get the times font for instance you can specify : # EXTRA_PACKAGES=times or EXTRA_PACKAGES={times} # To use the option intlimits with the amsmath package you can specify: # EXTRA_PACKAGES=[intlimits]{amsmath} # If left blank no extra packages will be included. # This tag requires that the tag GENERATE_LATEX is set to YES. EXTRA_PACKAGES = # The LATEX_HEADER tag can be used to specify a user-defined LaTeX header for # the generated LaTeX document. The header should contain everything until the # first chapter. If it is left blank doxygen will generate a standard header. It # is highly recommended to start with a default header using # doxygen -w latex new_header.tex new_footer.tex new_stylesheet.sty # and then modify the file new_header.tex. See also section "Doxygen usage" for # information on how to generate the default header that doxygen normally uses. # # Note: Only use a user-defined header if you know what you are doing! # Note: The header is subject to change so you typically have to regenerate the # default header when upgrading to a newer version of doxygen. The following # commands have a special meaning inside the header (and footer): For a # description of the possible markers and block names see the documentation. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_HEADER = # The LATEX_FOOTER tag can be used to specify a user-defined LaTeX footer for # the generated LaTeX document. The footer should contain everything after the # last chapter. If it is left blank doxygen will generate a standard footer. See # LATEX_HEADER for more information on how to generate a default footer and what # special commands can be used inside the footer. See also section "Doxygen # usage" for information on how to generate the default footer that doxygen # normally uses. Note: Only use a user-defined footer if you know what you are # doing! # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_FOOTER = # The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined # LaTeX style sheets that are included after the standard style sheets created # by doxygen. Using this option one can overrule certain style aspects. Doxygen # will copy the style sheet files to the output directory. # Note: The order of the extra style sheet files is of importance (e.g. the last # style sheet in the list overrules the setting of the previous ones in the # list). # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_EXTRA_STYLESHEET = # The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the LATEX_OUTPUT output # directory. Note that the files will be copied as-is; there are no commands or # markers available. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_EXTRA_FILES = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is # prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will # contain links (just like the HTML output) instead of page references. This # makes the output suitable for online browsing using a PDF viewer. # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. PDF_HYPERLINKS = YES # If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as # specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX # files. Set this option to YES, to get a higher quality PDF documentation. # # See also section LATEX_CMD_NAME for selecting the engine. # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. USE_PDFLATEX = YES # The LATEX_BATCHMODE tag signals the behavior of LaTeX in case of an error. # Possible values are: NO same as ERROR_STOP, YES same as BATCH, BATCH In batch # mode nothing is printed on the terminal, errors are scrolled as if <return> is # hit at every error; missing files that TeX tries to input or request from # keyboard input (\read on a not open input stream) cause the job to abort, # NON_STOP In nonstop mode the diagnostic message will appear on the terminal, # but there is no possibility of user interaction just like in batch mode, # SCROLL In scroll mode, TeX will stop only for missing files to input or if # keyboard input is necessary and ERROR_STOP In errorstop mode, TeX will stop at # each error, asking for user intervention. # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_BATCHMODE = NO # If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the # index chapters (such as File Index, Compound Index, etc.) in the output. # The default value is: NO. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_HIDE_INDICES = NO # The LATEX_BIB_STYLE tag can be used to specify the style to use for the # bibliography, e.g. plainnat, or ieeetr. See # https://en.wikipedia.org/wiki/BibTeX and \cite for more info. # The default value is: plain. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_BIB_STYLE = plain # The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute) # path from which the emoji images will be read. If a relative path is entered, # it will be relative to the LATEX_OUTPUT directory. If left blank the # LATEX_OUTPUT directory will be used. # This tag requires that the tag GENERATE_LATEX is set to YES. LATEX_EMOJI_DIRECTORY = #--------------------------------------------------------------------------- # Configuration options related to the RTF output #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The # RTF output is optimized for Word 97 and may not look too pretty with other RTF # readers/editors. # The default value is: NO. GENERATE_RTF = NO # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: rtf. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_OUTPUT = rtf # If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF # documents. This may be useful for small projects and may help to save some # trees in general. # The default value is: NO. # This tag requires that the tag GENERATE_RTF is set to YES. COMPACT_RTF = NO # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will # contain hyperlink fields. The RTF file will contain links (just like the HTML # output) instead of page references. This makes the output suitable for online # browsing using Word or some other Word compatible readers that support those # fields. # # Note: WordPad (write) and others do not support links. # The default value is: NO. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_HYPERLINKS = NO # Load stylesheet definitions from file. Syntax is similar to doxygen's # configuration file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. # # See also section "Doxygen usage" for information on how to generate the # default style sheet that doxygen normally uses. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an RTF document. Syntax is # similar to doxygen's configuration file. A template extensions file can be # generated using doxygen -e rtf extensionFile. # This tag requires that the tag GENERATE_RTF is set to YES. RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # Configuration options related to the man page output #--------------------------------------------------------------------------- # If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for # classes and files. # The default value is: NO. GENERATE_MAN = YES # The MAN_OUTPUT tag is used to specify where the man pages will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. A directory man3 will be created inside the directory specified by # MAN_OUTPUT. # The default directory is: man. # This tag requires that the tag GENERATE_MAN is set to YES. MAN_OUTPUT = man # The MAN_EXTENSION tag determines the extension that is added to the generated # man pages. In case the manual section does not start with a number, the number # 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is # optional. # The default value is: .3. # This tag requires that the tag GENERATE_MAN is set to YES. MAN_EXTENSION = .3 # The MAN_SUBDIR tag determines the name of the directory created within # MAN_OUTPUT in which the man pages are placed. If defaults to man followed by # MAN_EXTENSION with the initial . removed. # This tag requires that the tag GENERATE_MAN is set to YES. MAN_SUBDIR = # If the MAN_LINKS tag is set to YES and doxygen generates man output, then it # will generate one additional man file for each entity documented in the real # man page(s). These additional files only source the real man page, but without # them the man command would be unable to find the correct page. # The default value is: NO. # This tag requires that the tag GENERATE_MAN is set to YES. MAN_LINKS = NO #--------------------------------------------------------------------------- # Configuration options related to the XML output #--------------------------------------------------------------------------- # If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that # captures the structure of the code including all documentation. # The default value is: NO. GENERATE_XML = NO # The XML_OUTPUT tag is used to specify where the XML pages will be put. If a # relative path is entered the value of OUTPUT_DIRECTORY will be put in front of # it. # The default directory is: xml. # This tag requires that the tag GENERATE_XML is set to YES. XML_OUTPUT = xml # If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program # listings (including syntax highlighting and cross-referencing information) to # the XML output. Note that enabling this will significantly increase the size # of the XML output. # The default value is: YES. # This tag requires that the tag GENERATE_XML is set to YES. XML_PROGRAMLISTING = YES # If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include # namespace members in file scope as well, matching the HTML output. # The default value is: NO. # This tag requires that the tag GENERATE_XML is set to YES. XML_NS_MEMB_FILE_SCOPE = NO #--------------------------------------------------------------------------- # Configuration options related to the DOCBOOK output #--------------------------------------------------------------------------- # If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files # that can be used to generate PDF. # The default value is: NO. GENERATE_DOCBOOK = NO # The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be put in # front of it. # The default directory is: docbook. # This tag requires that the tag GENERATE_DOCBOOK is set to YES. DOCBOOK_OUTPUT = docbook #--------------------------------------------------------------------------- # Configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- # If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an # AutoGen Definitions (see https://autogen.sourceforge.net/) file that captures # the structure of the code including all documentation. Note that this feature # is still experimental and incomplete at the moment. # The default value is: NO. GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # Configuration options related to Sqlite3 output #--------------------------------------------------------------------------- # If the GENERATE_SQLITE3 tag is set to YES doxygen will generate a Sqlite3 # database with symbols found by doxygen stored in tables. # The default value is: NO. GENERATE_SQLITE3 = NO # The SQLITE3_OUTPUT tag is used to specify where the Sqlite3 database will be # put. If a relative path is entered the value of OUTPUT_DIRECTORY will be put # in front of it. # The default directory is: sqlite3. # This tag requires that the tag GENERATE_SQLITE3 is set to YES. SQLITE3_OUTPUT = sqlite3 # The SQLITE3_OVERWRITE_DB tag is set to YES, the existing doxygen_sqlite3.db # database file will be recreated with each doxygen run. If set to NO, doxygen # will warn if an a database file is already found and not modify it. # The default value is: YES. # This tag requires that the tag GENERATE_SQLITE3 is set to YES. SQLITE3_RECREATE_DB = YES #--------------------------------------------------------------------------- # Configuration options related to the Perl module output #--------------------------------------------------------------------------- # If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module # file that captures the structure of the code including all documentation. # # Note that this feature is still experimental and incomplete at the moment. # The default value is: NO. GENERATE_PERLMOD = NO # If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary # Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI # output from the Perl module output. # The default value is: NO. # This tag requires that the tag GENERATE_PERLMOD is set to YES. PERLMOD_LATEX = NO # If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely # formatted so it can be parsed by a human reader. This is useful if you want to # understand what is going on. On the other hand, if this tag is set to NO, the # size of the Perl module output will be much smaller and Perl will parse it # just the same. # The default value is: YES. # This tag requires that the tag GENERATE_PERLMOD is set to YES. PERLMOD_PRETTY = YES # The names of the make variables in the generated doxyrules.make file are # prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful # so different doxyrules.make files included by the same Makefile don't # overwrite each other's variables. # This tag requires that the tag GENERATE_PERLMOD is set to YES. PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all # C-preprocessor directives found in the sources and include files. # The default value is: YES. ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names # in the source code. If set to NO, only conditional compilation will be # performed. Macro expansion can be done in a controlled way by setting # EXPAND_ONLY_PREDEF to YES. # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. MACRO_EXPANSION = NO # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then # the macro expansion is limited to the macros specified with the PREDEFINED and # EXPAND_AS_DEFINED tags. # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES, the include files in the # INCLUDE_PATH will be searched if a #include is found. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. SEARCH_INCLUDES = YES # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by the # preprocessor. Note that the INCLUDE_PATH is not recursive, so the setting of # RECURSIVE has no effect here. # This tag requires that the tag SEARCH_INCLUDES is set to YES. INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the # directories. If left blank, the patterns specified with FILE_PATTERNS will be # used. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that are # defined before the preprocessor is started (similar to the -D option of e.g. # gcc). The argument of the tag is a list of macros of the form: name or # name=definition (no spaces). If the definition and the "=" are omitted, "=1" # is assumed. To prevent a macro definition from being undefined via #undef or # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. PREDEFINED = # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The # macro definition that is found in the sources will be used. Use the PREDEFINED # tag if you want to use a different macro definition that overrules the # definition found in the source code. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will # remove all references to function-like macros that are alone on a line, have # an all uppercase name, and do not end with a semicolon. Such function macros # are typically used for boiler-plate code, and will confuse the parser if not # removed. # The default value is: YES. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration options related to external references #--------------------------------------------------------------------------- # The TAGFILES tag can be used to specify one or more tag files. For each tag # file the location of the external documentation should be added. The format of # a tag file without this location is as follows: # TAGFILES = file1 file2 ... # Adding location for the tag files is done as follows: # TAGFILES = file1=loc1 "file2 = loc2" ... # where loc1 and loc2 can be relative or absolute paths or URLs. See the # section "Linking to external documentation" for more information about the use # of tag files. # Note: Each tag file must have a unique name (where the name does NOT include # the path). If a tag file is not located in the directory in which doxygen is # run, you must also specify the path to the tagfile here. TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create a # tag file that is based on the input files it reads. See section "Linking to # external documentation" for more information about the usage of tag files. GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES, all external classes and namespaces # will be listed in the class and namespace index. If set to NO, only the # inherited external classes will be listed. # The default value is: NO. ALLEXTERNALS = NO # If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed # in the topic index. If set to NO, only the current project's groups will be # listed. # The default value is: YES. EXTERNAL_GROUPS = YES # If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in # the related pages index. If set to NO, only the current project's pages will # be listed. # The default value is: YES. EXTERNAL_PAGES = YES #--------------------------------------------------------------------------- # Configuration options related to diagram generator tools #--------------------------------------------------------------------------- # If set to YES the inheritance and collaboration graphs will hide inheritance # and usage relations if the target is undocumented or is not a class. # The default value is: YES. HIDE_UNDOC_RELATIONS = YES # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz (see: # https://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent # Bell Labs. The other options in this section have no effect if this option is # set to NO # The default value is: YES. HAVE_DOT = NO # The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed # to run in parallel. When set to 0 doxygen will base this on the number of # processors available in the system. You can set it explicitly to a value # larger than 0 to get control over the balance between CPU load and processing # speed. # Minimum value: 0, maximum value: 32, default value: 0. # This tag requires that the tag HAVE_DOT is set to YES. DOT_NUM_THREADS = 0 # DOT_COMMON_ATTR is common attributes for nodes, edges and labels of # subgraphs. When you want a differently looking font in the dot files that # doxygen generates you can specify fontname, fontcolor and fontsize attributes. # For details please see <a href=https://graphviz.org/doc/info/attrs.html>Node, # Edge and Graph Attributes specification</a> You need to make sure dot is able # to find the font, which can be done by putting it in a standard location or by # setting the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the # directory containing the font. Default graphviz fontsize is 14. # The default value is: fontname=Helvetica,fontsize=10. # This tag requires that the tag HAVE_DOT is set to YES. DOT_COMMON_ATTR = "fontname=Helvetica,fontsize=10" # DOT_EDGE_ATTR is concatenated with DOT_COMMON_ATTR. For elegant style you can # add 'arrowhead=open, arrowtail=open, arrowsize=0.5'. <a # href=https://graphviz.org/doc/info/arrows.html>Complete documentation about # arrows shapes.</a> # The default value is: labelfontname=Helvetica,labelfontsize=10. # This tag requires that the tag HAVE_DOT is set to YES. DOT_EDGE_ATTR = "labelfontname=Helvetica,labelfontsize=10" # DOT_NODE_ATTR is concatenated with DOT_COMMON_ATTR. For view without boxes # around nodes set 'shape=plain' or 'shape=plaintext' <a # href=https://www.graphviz.org/doc/info/shapes.html>Shapes specification</a> # The default value is: shape=box,height=0.2,width=0.4. # This tag requires that the tag HAVE_DOT is set to YES. DOT_NODE_ATTR = "shape=box,height=0.2,width=0.4" # You can set the path where dot can find font specified with fontname in # DOT_COMMON_ATTR and others dot attributes. # This tag requires that the tag HAVE_DOT is set to YES. DOT_FONTPATH = # If the CLASS_GRAPH tag is set to YES or GRAPH or BUILTIN then doxygen will # generate a graph for each documented class showing the direct and indirect # inheritance relations. In case the CLASS_GRAPH tag is set to YES or GRAPH and # HAVE_DOT is enabled as well, then dot will be used to draw the graph. In case # the CLASS_GRAPH tag is set to YES and HAVE_DOT is disabled or if the # CLASS_GRAPH tag is set to BUILTIN, then the built-in generator will be used. # If the CLASS_GRAPH tag is set to TEXT the direct and indirect inheritance # relations will be shown as texts / links. # Possible values are: NO, YES, TEXT, GRAPH and BUILTIN. # The default value is: YES. CLASS_GRAPH = YES # If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a # graph for each documented class showing the direct and indirect implementation # dependencies (inheritance, containment, and class references variables) of the # class with other documented classes. Explicit enabling a collaboration graph, # when COLLABORATION_GRAPH is set to NO, can be accomplished by means of the # command \collaborationgraph. Disabling a collaboration graph can be # accomplished by means of the command \hidecollaborationgraph. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. COLLABORATION_GRAPH = YES # If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for # groups, showing the direct groups dependencies. Explicit enabling a group # dependency graph, when GROUP_GRAPHS is set to NO, can be accomplished by means # of the command \groupgraph. Disabling a directory graph can be accomplished by # means of the command \hidegroupgraph. See also the chapter Grouping in the # manual. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. GROUP_GRAPHS = YES # If the UML_LOOK tag is set to YES, doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. UML_LOOK = NO # If the UML_LOOK tag is enabled, the fields and methods are shown inside the # class node. If there are many fields or methods and many nodes the graph may # become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the # number of items for each type to make the size more manageable. Set this to 0 # for no limit. Note that the threshold may be exceeded by 50% before the limit # is enforced. So when you set the threshold to 10, up to 15 fields may appear, # but if the number exceeds 15, the total amount of fields shown is limited to # 10. # Minimum value: 0, maximum value: 100, default value: 10. # This tag requires that the tag UML_LOOK is set to YES. UML_LIMIT_NUM_FIELDS = 10 # If the DOT_UML_DETAILS tag is set to NO, doxygen will show attributes and # methods without types and arguments in the UML graphs. If the DOT_UML_DETAILS # tag is set to YES, doxygen will add type and arguments for attributes and # methods in the UML graphs. If the DOT_UML_DETAILS tag is set to NONE, doxygen # will not generate fields with class member information in the UML graphs. The # class diagrams will look similar to the default class diagrams but using UML # notation for the relationships. # Possible values are: NO, YES and NONE. # The default value is: NO. # This tag requires that the tag UML_LOOK is set to YES. DOT_UML_DETAILS = NO # The DOT_WRAP_THRESHOLD tag can be used to set the maximum number of characters # to display on a single line. If the actual line length exceeds this threshold # significantly it will wrapped across multiple lines. Some heuristics are apply # to avoid ugly line breaks. # Minimum value: 0, maximum value: 1000, default value: 17. # This tag requires that the tag HAVE_DOT is set to YES. DOT_WRAP_THRESHOLD = 17 # If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and # collaboration graphs will show the relations between templates and their # instances. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. TEMPLATE_RELATIONS = NO # If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to # YES then doxygen will generate a graph for each documented file showing the # direct and indirect include dependencies of the file with other documented # files. Explicit enabling an include graph, when INCLUDE_GRAPH is is set to NO, # can be accomplished by means of the command \includegraph. Disabling an # include graph can be accomplished by means of the command \hideincludegraph. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. INCLUDE_GRAPH = YES # If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are # set to YES then doxygen will generate a graph for each documented file showing # the direct and indirect include dependencies of the file with other documented # files. Explicit enabling an included by graph, when INCLUDED_BY_GRAPH is set # to NO, can be accomplished by means of the command \includedbygraph. Disabling # an included by graph can be accomplished by means of the command # \hideincludedbygraph. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. INCLUDED_BY_GRAPH = YES # If the CALL_GRAPH tag is set to YES then doxygen will generate a call # dependency graph for every global function or class method. # # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable call graphs for selected # functions only using the \callgraph command. Disabling a call graph can be # accomplished by means of the command \hidecallgraph. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. CALL_GRAPH = NO # If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller # dependency graph for every global function or class method. # # Note that enabling this option will significantly increase the time of a run. # So in most cases it will be better to enable caller graphs for selected # functions only using the \callergraph command. Disabling a caller graph can be # accomplished by means of the command \hidecallergraph. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical # hierarchy of all classes instead of a textual one. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. GRAPHICAL_HIERARCHY = YES # If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the # dependencies a directory has on other directories in a graphical way. The # dependency relations are determined by the #include relations between the # files in the directories. Explicit enabling a directory graph, when # DIRECTORY_GRAPH is set to NO, can be accomplished by means of the command # \directorygraph. Disabling a directory graph can be accomplished by means of # the command \hidedirectorygraph. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. DIRECTORY_GRAPH = YES # The DIR_GRAPH_MAX_DEPTH tag can be used to limit the maximum number of levels # of child directories generated in directory dependency graphs by dot. # Minimum value: 1, maximum value: 25, default value: 1. # This tag requires that the tag DIRECTORY_GRAPH is set to YES. DIR_GRAPH_MAX_DEPTH = 1 # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. For an explanation of the image formats see the section # output formats in the documentation of the dot tool (Graphviz (see: # https://www.graphviz.org/)). # Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order # to make the SVG files visible in IE 9+ (other browsers do not have this # requirement). # Possible values are: png, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd, # gif, gif:cairo, gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd, # png:cairo, png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and # png:gdiplus:gdiplus. # The default value is: png. # This tag requires that the tag HAVE_DOT is set to YES. DOT_IMAGE_FORMAT = png # If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to # enable generation of interactive SVG images that allow zooming and panning. # # Note that this requires a modern browser other than Internet Explorer. Tested # and working are Firefox, Chrome, Safari, and Opera. # Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make # the SVG files visible. Older versions of IE do not have SVG support. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. INTERACTIVE_SVG = NO # The DOT_PATH tag can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. # This tag requires that the tag HAVE_DOT is set to YES. DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the \dotfile # command). # This tag requires that the tag HAVE_DOT is set to YES. DOTFILE_DIRS = # You can include diagrams made with dia in doxygen documentation. Doxygen will # then run dia to produce the diagram and insert it in the documentation. The # DIA_PATH tag allows you to specify the directory where the dia binary resides. # If left empty dia is assumed to be found in the default search path. DIA_PATH = # The DIAFILE_DIRS tag can be used to specify one or more directories that # contain dia files that are included in the documentation (see the \diafile # command). DIAFILE_DIRS = # When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the # path where java can find the plantuml.jar file or to the filename of jar file # to be used. If left blank, it is assumed PlantUML is not used or called during # a preprocessing step. Doxygen will generate a warning when it encounters a # \startuml command in this case and will not generate output for the diagram. PLANTUML_JAR_PATH = # When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a # configuration file for plantuml. PLANTUML_CFG_FILE = # When using plantuml, the specified paths are searched for files specified by # the !include statement in a plantuml block. PLANTUML_INCLUDE_PATH = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes # that will be shown in the graph. If the number of nodes in a graph becomes # larger than this value, doxygen will truncate the graph, which is visualized # by representing a node as a red box. Note that doxygen if the number of direct # children of the root node in a graph is already larger than # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that # the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. # Minimum value: 0, maximum value: 10000, default value: 50. # This tag requires that the tag HAVE_DOT is set to YES. DOT_GRAPH_MAX_NODES = 50 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs # generated by dot. A depth value of 3 means that only nodes reachable from the # root by following a path via at most 3 edges will be shown. Nodes that lay # further from the root node will be omitted. Note that setting this option to 1 # or 2 may greatly reduce the computation time needed for large code bases. Also # note that the size of a graph can be further restricted by # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. # Minimum value: 0, maximum value: 1000, default value: 0. # This tag requires that the tag HAVE_DOT is set to YES. MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) support # this, this feature is disabled by default. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. DOT_MULTI_TARGETS = YES # If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page # explaining the meaning of the various boxes and arrows in the dot generated # graphs. # Note: This tag requires that UML_LOOK isn't set, i.e. the doxygen internal # graphical representation for inheritance and collaboration diagrams is used. # The default value is: YES. # This tag requires that the tag HAVE_DOT is set to YES. GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate # files that are used to generate the various graphs. # # Note: This setting is not only used for dot files but also for msc temporary # files. # The default value is: YES. DOT_CLEANUP = YES # You can define message sequence charts within doxygen comments using the \msc # command. If the MSCGEN_TOOL tag is left empty (the default), then doxygen will # use a built-in version of mscgen tool to produce the charts. Alternatively, # the MSCGEN_TOOL tag can also specify the name an external tool. For instance, # specifying prog as the value, doxygen will call the tool as prog -T # <outfile_format> -o <outputfile> <inputfile>. The external tool should support # output file formats "png", "eps", "svg", and "ismap". MSCGEN_TOOL = # The MSCFILE_DIRS tag can be used to specify one or more directories that # contain msc files that are included in the documentation (see the \mscfile # command). MSCFILE_DIRS = ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/include/helpers.h���������������������������������������������������������������0000664�0000000�0000000�00000007446�15201331742�0017533�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2026 Intel Corporation */ #ifndef __HELPERS_H #define __HELPERS_H #ifdef __cplusplus extern "C" { #endif #define DEBUG_MSG_LEN 1024 #if DEBUG #define TEE_DEFAULT_LOG_LEVEL TEE_LOG_LEVEL_VERBOSE #else #define TEE_DEFAULT_LOG_LEVEL TEE_LOG_LEVEL_QUIET #endif #ifdef EFI #define DEBUG_PRINT_ME_PREFIX_INTERNAL "TEELIB: (%a:%a():%d) " #else /* EFI */ #define DEBUG_PRINT_ME_PREFIX_INTERNAL "TEELIB: (%s:%s():%d) " #endif /* EFI */ #define DEBUG_PRINT_ME_PREFIX_EXTERNAL "TEELIB: (%s:%s():%d) " #ifdef _WIN32 #include <windows.h> #include <stdio.h> #include <stdarg.h> #include "metee.h" #define MALLOC(X) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, X) #define FREE(X) {if(X) { HeapFree(GetProcessHeap(), 0, X); X = NULL ; } } #define IS_HANDLE_INVALID(h) (NULL == h || 0 == h->handle || INVALID_HANDLE_VALUE == h->handle) #define INIT_STATUS TEE_INTERNAL_ERROR #else #define MALLOC(X) malloc(X) #define FREE(X) { if(X) { free(X); X = NULL ; } } #define IS_HANDLE_INVALID(h) (NULL == h || 0 == h->handle || -1 == h->handle) #define INIT_STATUS -EPERM #endif /* _WIN32 */ #if SYSLOG #ifdef _WIN32 void DebugPrintMe(const char* args, ...); #define ErrorPrintMe(fmt, ...) DebugPrintMe(fmt, __VA_ARGS__) #elif defined(ANDROID) #define LOG_TAG "metee" #include <android/log_macros.h> #define DebugPrintMe(fmt, ...) ALOGV(fmt, ##__VA_ARGS__) #define ErrorPrintMe(fmt, ...) ALOGE(fmt, ##__VA_ARGS__) #elif defined(EFI) #define DebugPrintMe(fmt, ...) AsciiPrint(fmt, ##__VA_ARGS__) #define ErrorPrintMe(fmt, ...) AsciiPrint(fmt, ##__VA_ARGS__) #else #include <syslog.h> #define DebugPrintMe(fmt, ...) syslog(LOG_DEBUG, fmt, ##__VA_ARGS__) #define ErrorPrintMe(fmt, ...) syslog(LOG_ERR, fmt, ##__VA_ARGS__) #endif #else /* SYSLOG */ #ifdef EFI #define DebugPrintMe(fmt, ...) AsciiPrint(fmt, ##__VA_ARGS__) #define ErrorPrintMe(fmt, ...) AsciiPrint(fmt, ##__VA_ARGS__) #else #include <stdlib.h> #define DebugPrintMe(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) #define ErrorPrintMe(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) #endif #endif /* SYSLOG */ #define LEGACY_CALLBACK_SET(h) ((h)->log_callback ? 1 : 0) #define STANDARD_CALLBACK_SET(h) ((h)->log_callback2 ? 1 : 0) void CallbackPrintHelper(IN PTEEHANDLE handle, bool is_error, const char* args, ...); #define DBGPRINT(h, _x_, ...) \ if ((h) && (h)->log_level >= TEE_LOG_LEVEL_VERBOSE) { \ if (LEGACY_CALLBACK_SET(h)) \ (h)->log_callback(false, DEBUG_PRINT_ME_PREFIX_EXTERNAL _x_,__FILE__,__FUNCTION__,__LINE__, ##__VA_ARGS__); \ else if (STANDARD_CALLBACK_SET(h)) \ CallbackPrintHelper((h), false, DEBUG_PRINT_ME_PREFIX_EXTERNAL _x_,__FILE__,__FUNCTION__,__LINE__, ##__VA_ARGS__); \ else \ DebugPrintMe(DEBUG_PRINT_ME_PREFIX_INTERNAL _x_,__FILE__,__FUNCTION__,__LINE__, ##__VA_ARGS__); \ } #define ERRPRINT(h, _x_, ...) \ if ((h) && (h)->log_level >= TEE_LOG_LEVEL_ERROR) { \ if (LEGACY_CALLBACK_SET(h)) \ (h)->log_callback(true, DEBUG_PRINT_ME_PREFIX_EXTERNAL _x_,__FILE__,__FUNCTION__,__LINE__, ##__VA_ARGS__); \ else if (STANDARD_CALLBACK_SET(h)) \ CallbackPrintHelper((h), true, DEBUG_PRINT_ME_PREFIX_EXTERNAL _x_,__FILE__,__FUNCTION__,__LINE__, ##__VA_ARGS__); \ else \ ErrorPrintMe(DEBUG_PRINT_ME_PREFIX_INTERNAL _x_,__FILE__,__FUNCTION__,__LINE__, ##__VA_ARGS__); \ } #define FUNC_ENTRY(h) DBGPRINT(h, "Entry\n") #define FUNC_EXIT(h, status) DBGPRINT(h, "Exit with status: %d\n", status) #ifdef EFI #include <Library/BaseMemoryLib.h> static inline void __tee_init_handle(PTEEHANDLE handle) { SetMem(handle, sizeof(TEEHANDLE), 0);} #else /* _WIN32, LINUX */ static inline void __tee_init_handle(PTEEHANDLE handle) { memset(handle, 0, sizeof(TEEHANDLE));} #endif /* EFI */ #ifdef __cplusplus } #endif #endif /* __HELPERS_H */ ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/include/metee.h�����������������������������������������������������������������0000664�0000000�0000000�00000034127�15201331742�0017164�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2025 Intel Corporation */ /*! \file metee.h * \brief metee library API */ #ifndef __METEE_H #define __METEE_H #ifdef __cplusplus extern "C" { #endif #include <stddef.h> #include <stdint.h> #include <stdbool.h> //! @cond suppress_warnings #ifdef _WIN32 #include <Windows.h> #include <initguid.h> #ifndef METEE_DLL #define METEE_DLL_API #else /* METEE_DLL */ #ifdef METEE_DLL_EXPORT #define METEE_DLL_API __declspec(dllexport) #else #define METEE_DLL_API __declspec(dllimport) #endif /* METEE_DLL_EXPORT */ #endif /* METEE_DLL */ #define TEEAPI METEE_DLL_API __stdcall #define TEE_DEVICE_HANDLE HANDLE #define TEE_INVALID_DEVICE_HANDLE ((void*)0) #elif defined(EFI) #include <Uefi.h> #define TEEAPI #define TEE_DEVICE_HANDLE void * #define TEE_INVALID_DEVICE_HANDLE ((void*)-1) // when calling TeeInitFull // TEE_DEVICE_TYPE_BDF - HECI device Bus Device Function #else /* _WIN32 */ #ifndef METEE_DLL #define METEE_DLL_API #else /*! METEE_DLL */ #ifdef METEE_DLL_EXPORT #define METEE_DLL_API __attribute__((__visibility__("default"))) #else #define METEE_DLL_API #endif /* METEE_DLL_EXPORT */ #endif /* METEE_DLL */ #define TEEAPI METEE_DLL_API #ifndef GUID_DEFINED #define GUID_DEFINED 1 typedef struct _GUID { uint32_t l; uint16_t w1; uint16_t w2; uint8_t b[8]; } GUID; #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ const GUID name \ = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } #endif /* GUID_DEFINED */ #define TEE_DEVICE_HANDLE int #define TEE_INVALID_DEVICE_HANDLE (-1) #ifndef IN #define IN #endif #ifndef OUT #define OUT #endif #ifndef OPTIONAL #define OPTIONAL #endif #endif /* _WIN32 */ //! @endcond /*! log level */ enum tee_log_level { TEE_LOG_LEVEL_QUIET = 0, /**< no log prints */ TEE_LOG_LEVEL_ERROR = 1, /**< error log prints */ TEE_LOG_LEVEL_VERBOSE = 2, /**< verbose log prints */ TEE_LOG_LEVEL_MAX = 3, /**< upper sentinel */ }; /*! log callback function format * @deprecated Since version 6.0 */ typedef void(*TeeLogCallback)(bool is_error, const char* fmt, ...); /*! log callback function format */ typedef void(*TeeLogCallback2)(bool is_error, const char* msg); #pragma pack(1) /*! * Structure to store connection data */ typedef struct _TEEHANDLE { void *handle; /**< Handle to the internal structure */ size_t maxMsgLen; /**< FW Client Max Message Length */ uint8_t protcolVer; /**< FW Client Protocol FW */ enum tee_log_level log_level; /**< Log level */ TeeLogCallback log_callback; /**< Deprecated Log callback */ TeeLogCallback2 log_callback2; /**< Log callback */ } TEEHANDLE; /*! * \var typedestruct _TEEHANDLE *PTEEHANDLE * \brief A type definition for pointer to TEEHANDLE */ typedef TEEHANDLE *PTEEHANDLE; /*! Device address passed to the init function */ struct tee_device_address { /*! Device address type */ enum { TEE_DEVICE_TYPE_NONE = 0, /**< Select first available device */ TEE_DEVICE_TYPE_PATH = 1, /**< Use device by path (char*) */ TEE_DEVICE_TYPE_HANDLE = 2, /**< Use device by pre-opend handle */ TEE_DEVICE_TYPE_GUID = 3, /**< Select first device by GUID (Windows only) */ TEE_DEVICE_TYPE_BDF = 4, /**< Use BDF to work with HECI, EFI only */ TEE_DEVICE_TYPE_MAX = 5, /**< upper sentinel */ } type; /*! Device address */ union { const char* path; /** < Path to device */ const GUID* guid; /** Device GUID (Windows only) */ TEE_DEVICE_HANDLE handle; /**< Pre-opend handle */ struct { struct { uint32_t segment; /** HECI device Segment */ uint32_t bus; /** HECI device Bus */ uint32_t device; /** HECI device Device */ uint32_t function; /** HECI device Function */ } value; /*! Specifies HW layout: HECI, FWSTS registers locations */ enum HECI_HW_TYPE { HECI_HW_TYPE_PCH, HECI_HW_TYPE_GFX_GSC, HECI_HW_TYPE_GFX_CSC, } hw_type; /** HECI device HW type */ } bdf; } data; }; #pragma pack() /** ZERO/NULL device handle */ #define TEEHANDLE_ZERO {0} typedef uint16_t TEESTATUS; /**< return status for API functions */ /** METEE ERROR BASE */ #define TEE_ERROR_BASE 0x0000U /** METEE SUCCESS */ #define TEE_SUCCESS (TEE_ERROR_BASE + 0) /** An internal error occurred in the library */ #define TEE_INTERNAL_ERROR (TEE_ERROR_BASE + 1) /** The device is not in the system or is not working */ #define TEE_DEVICE_NOT_FOUND (TEE_ERROR_BASE + 2) /** The device is not ready for the operation */ #define TEE_DEVICE_NOT_READY (TEE_ERROR_BASE + 3) /** An invalid parameter was used in the call */ #define TEE_INVALID_PARAMETER (TEE_ERROR_BASE + 4) /** It is not possible to complete the operation */ #define TEE_UNABLE_TO_COMPLETE_OPERATION (TEE_ERROR_BASE + 5) /** The operation has timed out */ #define TEE_TIMEOUT (TEE_ERROR_BASE + 6) /** The operation is not supported */ #define TEE_NOTSUPPORTED (TEE_ERROR_BASE + 7) /** The ME client is not present in the firmware */ #define TEE_CLIENT_NOT_FOUND (TEE_ERROR_BASE + 8) /** The device is busy */ #define TEE_BUSY (TEE_ERROR_BASE + 9) /** The ME client is not connected */ #define TEE_DISCONNECTED (TEE_ERROR_BASE + 10) /** The buffer for read not big enough */ #define TEE_INSUFFICIENT_BUFFER (TEE_ERROR_BASE + 11) /** The user don't have permission for this operation */ #define TEE_PERMISSION_DENIED (TEE_ERROR_BASE + 12) /*! Macro for successful operation result check */ #define TEE_IS_SUCCESS(Status) (((TEESTATUS)(Status)) == TEE_SUCCESS) /*! Initializes a TEE connection * @deprecated Since version 6.0 * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device device address structure * \param log_level log level to set (from enum tee_log_level) * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback); /*! Initializes a TEE connection * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device device address structure * \param log_level log level to set (from enum tee_log_level) * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeInitFull2(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback2 log_callback); /*! Initializes a TEE connection * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device optional device path, set NULL to use default * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN OPTIONAL const char *device); #ifdef _WIN32 /*! Initializes a TEE connection * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device optional device class GUID, set NULL to use default * - use the first device from that class * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeInitGUID(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN OPTIONAL const GUID *device); #endif /* _WIN32 */ /*! Initializes a TEE connection * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device_handle open file handle * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const TEE_DEVICE_HANDLE device_handle); /*! Connects to the TEE driver and starts a session * \param handle A handle to the TEE device * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle); /*! Read data from the TEE device synchronously. * \param handle The handle of the session to read from. * \param buffer A pointer to a buffer that receives the data read from the TEE device. * \param bufferSize The number of bytes to be read. * \param pNumOfBytesRead A pointer to the variable that receives the number of bytes read, * ignored if set to NULL. * \param timeout The timeout to complete read in milliseconds, zero for infinite * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout); /*! Writes the specified buffer to the TEE device synchronously. * \param handle The handle of the session to write to. * \param buffer A pointer to the buffer containing the data to be written to the TEE device. * \param bufferSize The number of bytes to be written. * \param numberOfBytesWritten A pointer to the variable that receives the number of bytes written, * ignored if set to NULL. * \param timeout The timeout to complete write in milliseconds, zero for infinite * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout); /*! Retrieves specified FW status register. * \param handle The handle of the session. * \param fwStatusNum The FW status register number (0-5). * \param fwStatus The memory to store obtained FW status. * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle, IN uint32_t fwStatusNum, OUT uint32_t *fwStatus); /*! Retrieves TRC register. * \param handle The handle of the session. * \param trc_val The memory to store obtained TRC value. * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val); /*! Closes the session to TEE driver * Make sure that you call this function as soon as you are done with the device, * as other clients might be blocked until the session is closed. * \param handle The handle of the session to close. */ void TEEAPI TeeDisconnect(IN PTEEHANDLE handle); /*! Try to stop all in-process reads and writes * \param handle The handle of the session */ void TEEAPI TeeCancelIO(IN PTEEHANDLE handle); /*! Returns handle of TEE device * Obtains HECI device handle on Windows and mei device file descriptor on Linux * \param handle The handle of the session. * \return device handle */ TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle); /*! Structure to store version data */ typedef struct { uint16_t major; /**< Major version number */ uint16_t minor; /**< Minor version number */ uint16_t hotfix; /**< Hotfix version number */ uint16_t build; /**< Build version number */ } teeDriverVersion_t; /*! Obtains version of the TEE device driver * Not implemented on Linux * \param handle The handle of the session. * \param driverVersion Pointer to driver version struct * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion); /*! Set log level * * \param handle The handle of the session. * \param log_level log level to set * \return previous log level */ uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level); /*! Retrieve current log level * * \param handle The handle of the session. * \return current log level */ uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle); /*! Set log callback * @deprecated Since version 6.0 * \param handle The handle of the session. * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback); /*! Set log callback * * \param handle The handle of the session. * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeSetLogCallback2(IN const PTEEHANDLE handle, TeeLogCallback2 log_callback); /*! Retrieve client maximum message length (MTU) * * \param handle The handle of the session. * \return client maximum message length. * If client never connected, will return zero. */ uint32_t TEEAPI TeeGetMaxMsgLen(IN const PTEEHANDLE handle); /*! Retrieve client protocol version * * \param handle The handle of the session. * \return client protocol version. * If client never connected, will return zero. */ uint8_t TEEAPI TeeGetProtocolVer(IN const PTEEHANDLE handle); /*! Obtains kind of the TEE device * \param handle The handle of the session. * \param kind Buffer to fill with device kind null terminated string, may be NULL. * \param kindSize Pointer to kind buffer size in bytes, updated to number of bytes filled in buffer, including null character, on out. * If buffer is NULL, required size is returned anyway. * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size_t *kindSize); #ifdef __cplusplus } #endif #endif /* __METEE_H */ �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/include/meteepp.h���������������������������������������������������������������0000664�0000000�0000000�00000025547�15201331742�0017532�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2021-2025 Intel Corporation */ /*! \file meteepp.h \brief metee C++ library API */ #ifndef _METEEPP_H_ #define _METEEPP_H_ #include <sstream> #include <stdexcept> #include <string> #include <system_error> #include <vector> #include "metee.h" namespace intel { namespace security { /*! \def TEE_ERR_STATE(state) * Internal macro */ /*! MeTee error category class */ static class metee_category_t : public std::error_category { public: virtual const char* name() const noexcept { return "MeTee"; } virtual std::string message(int ev) const { #define TEE_ERR_STATE(state) case TEE_##state: return #state switch (ev) { TEE_ERR_STATE(SUCCESS); TEE_ERR_STATE(INTERNAL_ERROR); TEE_ERR_STATE(DEVICE_NOT_FOUND); TEE_ERR_STATE(DEVICE_NOT_READY); TEE_ERR_STATE(INVALID_PARAMETER); TEE_ERR_STATE(UNABLE_TO_COMPLETE_OPERATION); TEE_ERR_STATE(TIMEOUT); TEE_ERR_STATE(NOTSUPPORTED); TEE_ERR_STATE(CLIENT_NOT_FOUND); TEE_ERR_STATE(BUSY); TEE_ERR_STATE(DISCONNECTED); TEE_ERR_STATE(INSUFFICIENT_BUFFER); TEE_ERR_STATE(PERMISSION_DENIED); default: return std::to_string(ev); } #undef TEE_ERR_STATE } } metee_category; /*! MeTee error exception class class */ class metee_exception : public std::system_error { public: /*! Constructor * \param what error string * \param err error code */ metee_exception(const std::string& what, int err = TEE_INTERNAL_ERROR) : std::system_error(err, metee_category, what) {} /*! Constructor * \param err error code * \param cat error category */ metee_exception(int err, const std::error_category& cat) : std::system_error(err, cat) {} /*! Constructor * \param err error code * \param cat error category * \param what error string */ metee_exception(int err, const std::error_category& cat, const std::string& what) : std::system_error(err, cat, what) {} /*! Destructor */ virtual ~metee_exception() noexcept {} }; /*! Dummy client GUID for default constructor */ DEFINE_GUID(METEE_GUID_ZERO, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); /*! Main interface class * \brief C++ class to access CSE/CSME/GSC firmware via a mei interface. */ class metee { public: /*! Default constructor, when connection to specific client is not required */ metee() : metee(METEE_GUID_ZERO) {} /*! Constructor without client GUID, when connection to specific client is not required * \param log_level log level to set (from enum tee_log_level) * \param log_callback pointer to function to run for log write (type 2) */ metee(uint32_t log_level, TeeLogCallback2 log_callback) : metee(METEE_GUID_ZERO, log_level, log_callback) {} /*! Constructor * \param guid GUID of the FW client that want to start a session */ metee(const GUID& guid) { TEESTATUS status = TeeInit(&_handle, &guid, nullptr); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("Init failed", status); } } /*! Constructor * \param guid GUID of the FW client that want to start a session * \param log_level log level to set (from enum tee_log_level) */ metee(const GUID& guid, uint32_t log_level) : metee(guid, log_level, static_cast<TeeLogCallback2>(nullptr)) {} /*! Constructor * \param guid GUID of the FW client that want to start a session * \param log_level log level to set (from enum tee_log_level) * \param log_callback pointer to function to run for log write */ metee(const GUID& guid, uint32_t log_level, TeeLogCallback log_callback) : metee(guid, { tee_device_address::TEE_DEVICE_TYPE_NONE , nullptr }, log_level, log_callback) {} /*! Constructor * \param guid GUID of the FW client that want to start a session * \param log_level log level to set (from enum tee_log_level) * \param log_callback pointer to function to run for log write (type 2) */ metee(const GUID& guid, uint32_t log_level, TeeLogCallback2 log_callback) : metee(guid, { tee_device_address::TEE_DEVICE_TYPE_NONE , nullptr }, log_level, log_callback) {} /*! Constructor * \param guid GUID of the FW client that want to start a session * \param device device address structure * \param log_level log level to set (from enum tee_log_level) */ metee(const GUID& guid, const struct tee_device_address& device, uint32_t log_level) : metee(guid, device, log_level, static_cast<TeeLogCallback2>(nullptr)) {} /*! Constructor * \param guid GUID of the FW client that want to start a session * \param device device address structure * \param log_level log level to set (from enum tee_log_level) * \param log_callback pointer to function to run for log write */ metee(const GUID &guid, const struct tee_device_address &device, uint32_t log_level, TeeLogCallback log_callback) { TEESTATUS status = TeeInitFull(&_handle, &guid, device, log_level, log_callback); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("Init failed", status); } } /*! Constructor * \param guid GUID of the FW client that want to start a session * \param device device address structure * \param log_level log level to set (from enum tee_log_level) * \param log_callback pointer to function to run for log write (type 2) */ metee(const GUID& guid, const struct tee_device_address& device, uint32_t log_level, TeeLogCallback2 log_callback) { TEESTATUS status = TeeInitFull2(&_handle, &guid, device, log_level, log_callback); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("Init failed", status); } } /*! Copy constructor - disabled */ metee(const metee& other) = delete; /*! Move constructor * \param other Object to move from */ metee(metee&& other) noexcept : _handle(other._handle) { other._handle.handle = nullptr; } /*! Copy operator - disabled */ metee& operator=(const metee& other) = delete; /*! Move operator * \param other Object to move from */ metee& operator=(metee&& other) noexcept { TeeDisconnect(&_handle); _handle = other._handle; other._handle.handle = nullptr; return *this; } /*! Destructor, disconnects, if connected */ virtual ~metee() { TeeDisconnect(&_handle); } /*! Try to stop all in-process reads and writes */ void cancel_io() { TeeCancelIO(&_handle); } /*! Connects to the TEE driver and starts a session */ void connect() { TEESTATUS status; status = TeeConnect(&_handle); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("Connect failed", status); } } /*! Read data from the TEE device synchronously. * \param timeout The timeout to complete read in milliseconds, zero for infinite * \return vector with data read from the TEE device */ std::vector<uint8_t> read(uint32_t timeout) { TEESTATUS status; size_t size = 0; std::vector<uint8_t> buffer(max_msg_len()); status = TeeRead(&_handle, buffer.data(), buffer.size(), &size, timeout); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("Read failed", status); } buffer.resize(size); return std::move(buffer); } /*! Writes the specified buffer to the TEE device synchronously. * \param buffer vector containing the data to be written to the TEE device. * \param timeout The timeout to complete write in milliseconds, zero for infinite * \return the number of bytes written */ size_t write(const std::vector<uint8_t> &buffer, uint32_t timeout) { TEESTATUS status; size_t size = 0; status = TeeWrite(&_handle, buffer.data(), buffer.size(), &size, timeout); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("Write failed", status); } return size; } /*! Retrieves specified FW status register. * \param fwStatusNum The FW status register number (0-5). * \return obtained FW status. */ uint32_t fw_status(uint32_t fwStatusNum) { TEESTATUS status; uint32_t fwStatus = 0; status = TeeFWStatus(&_handle, fwStatusNum, &fwStatus); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("FWStatus failed", status); } return fwStatus; } /*! Retrieves TRC register. * \return TRC value. */ uint32_t trc() { TEESTATUS status; uint32_t trc_val = 0; status = TeeGetTRC(&_handle, &trc_val); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("GetTRC failed", status); } return trc_val; } /*! Retrieves device kind. * \return kind string value. */ std::string kind() { TEESTATUS status; const size_t KIND_SIZE = 32; char kind[KIND_SIZE]; size_t kind_size = KIND_SIZE; status = TeeGetKind(&_handle, kind, &kind_size); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("TeeGetKind failed", status); } return kind; } /*! Set log level * * \param log_level log level to set * \return previous log level */ uint32_t log_level(uint32_t log_level) { return TeeSetLogLevel(&_handle, log_level); } /*! Retrieve current log level * * \return current log level */ uint32_t log_level() { return TeeGetLogLevel(&_handle); } /*! Set log callback * * \param log_callback pointer to function to run for log write, set NULL to use built-in function */ void log_callback(TeeLogCallback log_callback) { TeeSetLogCallback(&_handle, log_callback); } /*! Retrieve client maximum message length (MTU) * * \return client maximum message length. */ uint32_t max_msg_len() { return TeeGetMaxMsgLen(&_handle); } /*! Retrieve client protocol version * * \return client protocol version. */ uint8_t protocol_ver() { return TeeGetProtocolVer(&_handle); } /*! Returns handle of TEE device * Obtains HECI device handle on Windows and mei device file descriptor on Linux * \return the handle of the session. */ TEE_DEVICE_HANDLE device_handle() { return TeeGetDeviceHandle(&_handle); } /*! Obtains version of the TEE device driver * Not implemented on Linux * \return Driver version as dotted string. */ std::string driver_version() { TEESTATUS status; teeDriverVersion_t driverVersion = { 0 }; status = ::GetDriverVersion(&_handle, &driverVersion); if (!TEE_IS_SUCCESS(status)) { throw metee_exception("GetDriverVersion failed", status); } std::stringstream ss; ss << driverVersion.major << "." << driverVersion.minor << "." << driverVersion.hotfix << "." << driverVersion.build; return ss.str(); } private: _TEEHANDLE _handle; /*!< Internal device handle */ }; } // namespace security } // namespace intel #endif // _METEEPP_H_ ���������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/linux.cmake���������������������������������������������������������������������0000664�0000000�0000000�00000005140�15201331742�0016423�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2014-2026 Intel Corporation set(TEE_SOURCES src/linux/metee_linux.c src/linux/mei.c) add_library(${PROJECT_NAME} ${TEE_SOURCES}) target_include_directories(${PROJECT_NAME} PRIVATE src/linux) target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<BOOL:BUILD_SHARED_LIBS>:METEE_DLL> $<$<BOOL:BUILD_SHARED_LIBS>:METEE_DLL_EXPORT> ) # Check for new IOCTLs include(CheckSymbolExists) check_symbol_exists(IOCTL_MEI_CONNECT_CLIENT_VTAG linux/mei.h HAVE_VTAG) if(NOT HAVE_VTAG) include_directories(BEFORE "src/linux/include") endif() # More warnings and warning-as-error set(COMPILE_OPTIONS -Wall -Werror) include(CheckCCompilerFlag) check_c_compiler_flag(-Wshadow WARNING_SHADOW) if(WARNING_SHADOW) set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wshadow) endif() check_c_compiler_flag(-Wnull-dereference WARNING_NULL_DEREFERENCE) if(WARNING_NULL_DEREFERENCE) set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wnull-dereference) endif() check_c_compiler_flag(-Wfloat-conversion WARNING_FLOAT_CONVERSION) if(WARNING_FLOAT_CONVERSION) set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wfloat-conversion) endif() check_c_compiler_flag(-Wsign-conversion WARNING_SIGN_CONVERSION) if(WARNING_SIGN_CONVERSION) set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wsign-conversion) endif() check_c_compiler_flag(-Wstringop-truncation WARNING_STRINGOP_TRUNCATION) if(WARNING_STRINGOP_TRUNCATION) set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wstringop-truncation) endif() check_c_compiler_flag(-Wjump-misses-init WARNING_JUMP_MISSES_INIT) if(WARNING_JUMP_MISSES_INIT) set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wjump-misses-init) endif() check_c_compiler_flag(-Wunsuffixed-float-constants WARNING_UNSUFFIXED_FLOAT_CONSTANTS) if(WARNING_UNSUFFIXED_FLOAT_CONSTANTS) set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wunsuffixed-float-constants) endif() target_compile_options( ${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS}) # Security options target_compile_options( ${PROJECT_NAME} PRIVATE -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -O2 -Wformat -Wformat-security PRIVATE $<$<C_COMPILER_ID:GNU>:-fno-strict-overflow> PRIVATE $<$<C_COMPILER_ID:GNU>:-fno-delete-null-pointer-checks> PRIVATE -fwrapv ) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now") set_target_properties(${PROJECT_NAME} PROPERTIES C_VISIBILITY_PRESET hidden) if(NOT CONSOLE_OUTPUT) target_compile_definitions(${PROJECT_NAME} PRIVATE -DSYSLOG) endif() target_compile_definitions(${PROJECT_NAME} PRIVATE -D_GNU_SOURCE) if(ANDROID) target_link_libraries(${PROJECT_NAME} PRIVATE log) endif() ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/meson.build���������������������������������������������������������������������0000664�0000000�0000000�00000005437�15201331742�0016435�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2020-2022 Intel Corporation project('metee', 'c', version : run_command('get-version.py').stdout().strip(), license : 'Apache 2.0', meson_version : '>=0.51.0', default_options : ['warning_level=2', 'default_library=static', 'c_std=gnu99', 'optimization=2'], ) metee_sources_linux = [ 'src/linux/metee_linux.c', 'src/linux/mei.c' ] metee_sources_windows = [ 'src/Windows/metee_win.c', 'src/Windows/metee_winhelpers.c' ] warning_flags = [ '-Wno-unused-command-line-argument', '-Wsign-compare', '-Wformat-security', '-Wstack-protector', '-Winit-self', '/WX', '/W4' ] # secure compile flags security_flags = [ '-fstack-protector-strong', '-Wformat', '-Wformat-security', '-fno-strict-overflow', '-fno-delete-null-pointer-checks', '-fwrapv', '/GS', '/sdl' ] if get_option('optimization').to_int() >= 2 security_flags += [ '-D_FORTIFY_SOURCE=2' ] endif debug_flags = [] if get_option('buildtype') == 'debug' debug_flags += [ '-O0', '-g3', '-ggdb' ] endif cc = meson.get_compiler('c') if cc.get_id() == 'msvc' add_project_arguments('-DUNICODE', '-D_UNICODE', language : 'c') if get_option('mvsc_runtime_static') if get_option('buildtype') == 'debug' add_project_arguments('/MT', language : 'c') else add_project_arguments('/MTd', language : 'c') endif endif endif add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c') add_project_arguments(cc.get_supported_arguments(security_flags), language : 'c') add_project_arguments(cc.get_supported_arguments(debug_flags), language : 'c') add_project_arguments('-D_XOPEN_SOURCE=700', language : 'c') global_link_args = [] test_link_args = [ '-Wl,-z,relro', '-Wl,-z,now', '-Wl,-z,noexecstack', ] foreach link_arg: test_link_args if cc.has_link_argument(link_arg) global_link_args += link_arg endif endforeach add_project_link_arguments( global_link_args, language: 'c' ) if target_machine.system() == 'linux' local_inc = ['include', 'src/linux'] if not cc.has_header_symbol('linux/mei.h', 'IOCTL_MEI_CONNECT_CLIENT_VTAG') local_inc = ['src/linux/include'] + local_inc endif metee_lib_static = static_library('metee', sources : metee_sources_linux, include_directories : local_inc ) elif target_machine.system() == 'windows' metee_lib_static = static_library('metee', sources : metee_sources_windows, include_directories : ['include', 'src/Windows'], link_args : ['CfgMgr32.lib'] ) endif metee_dep_static = declare_dependency( link_with : metee_lib_static, include_directories : include_directories('include'), ) ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/meson_options.txt���������������������������������������������������������������0000664�0000000�0000000�00000000330�15201331742�0017713�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2020 Intel Corporation option('mvsc_runtime_static', type : 'boolean', value : 'true', description : 'Build with static runtime libraries on MSVC' ) ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0015726�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/CMakeLists.txt����������������������������������������������������������0000664�0000000�0000000�00000002434�15201331742�0020471�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2014-2024 Intel Corporation cmake_minimum_required(VERSION 3.15) project(metee_sample) add_executable(metee-mkhi metee_mkhi.c) target_link_libraries(metee-mkhi metee) if(MSVC) target_compile_definitions(metee-mkhi PRIVATE -D_CRT_SECURE_NO_WARNINGS) endif() install(TARGETS metee-mkhi RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) add_executable(metee-gsc metee_gsc.c) target_link_libraries(metee-gsc metee) install(TARGETS metee-gsc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(UNIX) add_executable(metee-connect metee_connect.c meiuuid.c) target_link_libraries(metee-connect metee) install(TARGETS metee-connect RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif(UNIX) add_executable(metee-trc metee_trc.c) target_link_libraries(metee-trc metee) install(TARGETS metee-trc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) add_executable(metee-basic metee_basic.c) target_link_libraries(metee-basic metee) install(TARGETS metee-basic RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) add_executable(meteepp-basic meteepp_basic.cpp) target_link_libraries(meteepp-basic metee) install(TARGETS meteepp-basic RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(BUILD_SHARED_LIBS AND WIN32) add_subdirectory(csharp) endif(BUILD_SHARED_LIBS AND WIN32)������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/csharp/�����������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0017206�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/csharp/AssemblyInfo.cs.in�����������������������������������������������0000664�0000000�0000000�00000002542�15201331742�0022540�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2025 Intel Corporation */ using System.Reflection; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("metee-csharp-sample")] [assembly: AssemblyDescription("C# sample project")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Intel Corporation")] [assembly: AssemblyProduct("metee-csharp-sample")] [assembly: AssemblyCopyright("Copyright (C) 2025 Intel Corporation")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("62336647-651e-4c5a-a92a-fbda141e6c4e")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // [assembly: AssemblyVersion("${TEE_VERSION_STRING}")] [assembly: AssemblyFileVersion("${TEE_VERSION_STRING}")]��������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/csharp/CMakeLists.txt���������������������������������������������������0000664�0000000�0000000�00000001401�15201331742�0021742�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2025 Intel Corporation cmake_minimum_required(VERSION 3.8) project(csharp-example VERSION 0.1.0 LANGUAGES CSharp) include(CSharpUtilities) configure_file(AssemblyInfo.cs.in ${CMAKE_CURRENT_SOURCE_DIR}/Properties/AssemblyInfo.cs) add_executable(csharp-example Program.cs Properties/AssemblyInfo.cs ) target_link_libraries(csharp-example Intel.Security.Metee) set_property(TARGET csharp-example PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1") set_property(TARGET csharp-example PROPERTY VS_DOTNET_REFERENCES "System" "System.Core" "System.Data.DataSetExtensions" "Microsoft.CSharp" "System.Data" ) install(TARGETS csharp-example RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/csharp/Program.cs�������������������������������������������������������0000664�0000000�0000000�00000010647�15201331742�0021154�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2025 Intel Corporation */ using Intel.Security; using System; namespace metee_csharp_sample { internal class Program { static void PrintFwVersion(byte[] data) { var version = new FwVersionResponse(data); Console.WriteLine($"CodeMinor: {version.CodeMinor}"); Console.WriteLine($"CodeMajor: {version.CodeMajor}"); Console.WriteLine($"CodeBuildNo: {version.CodeBuildNo}"); Console.WriteLine($"CodeHotFix: {version.CodeHotFix}"); } const byte MkhiGetFwVersionCommandId = 0x02; const byte MkhiGenGroupId = 0xFF; class FwMkhiCommandRequest { private int _data; public int GroupId { set => _data |= value; } public int Command { set => _data |= (value << 8); } public byte[] Data => BitConverter.GetBytes(_data); } class FwVersionRequest : FwMkhiCommandRequest { public FwVersionRequest() { GroupId = MkhiGenGroupId; Command = MkhiGetFwVersionCommandId; } } class FwMkhiCommandResponse { protected const int ResultOffset = 4; protected readonly byte[] Data; protected FwMkhiCommandResponse(byte[] data) { Data = data; if (Data.Length < ResultOffset) throw new ArgumentException("Data length is too short"); } } class FwVersionResponse : FwMkhiCommandResponse { public FwVersionResponse(byte[] data) : base(data) { if (Data.Length < (ResultOffset + 8)) throw new ArgumentException("Data length is too short"); } public int CodeMinor => BitConverter.ToInt16(Data, ResultOffset); public int CodeMajor => BitConverter.ToInt16(Data, ResultOffset + 2); public int CodeBuildNo => BitConverter.ToInt16(Data, ResultOffset + 4); public int CodeHotFix => BitConverter.ToInt16(Data, ResultOffset + 6); } static byte[] BasicMeTeeFlow(Metee metee) { Console.WriteLine($"Driver Version {metee.DriverVersion}"); Console.WriteLine($"TRC {metee.Trc}"); Console.WriteLine($"FWSTS 1 0x{metee.FwStatus[Metee.RegIndex.FwStatus1]:X8}"); Console.WriteLine($"FWSTS 2 0x{metee.FwStatus[Metee.RegIndex.FwStatus2]:X8}"); metee.Connect(); Console.WriteLine($"Protocol Version {metee.ProtocolVersion}"); Console.WriteLine($"MaxMsgLen {metee.MaxMsgLen}"); metee.Write(new FwVersionRequest().Data, Int32.MaxValue); return metee.Read(Int32.MaxValue); } static void Main(string[] args) { var mkhiClient = new Guid(0x8e6a6715, 0x9abc, 0x4043, 0x88, 0xef, 0x9e, 0x39, 0xc6, 0xf6, 0x3e, 0x0f); try { var teeDriverInterface = new Guid(0xE2D1FF34, 0x3458, 0x49A9, 0x88, 0xDA, 0x8E, 0x69, 0x15, 0xCE, 0x9B, 0xE5); using (var metee = new Metee(mkhiClient, teeDriverInterface, Metee.TeeLogLevel.Verbose, delegate(bool error, string msg) { Console.Write($"{error} ==> [{msg}]"); })) { var res = BasicMeTeeFlow(metee); PrintFwVersion(res); } using (var metee = new Metee(mkhiClient)) { var res = BasicMeTeeFlow(metee); PrintFwVersion(res); } // This code demonstrates how to use MeTee with a given device path. // Keep in mind that the device path may vary across different systems. // // var pathToTeeDriver = @"\\?\PCI#VEN_8086..HERE-GOES-YOUR-DEVICE-PATH..."; // using (var metee = new Metee(mkhiClient, pathToTeeDriver)) // { // var res = BasicMeTeeFlow(metee); // PrintFwVersion(res); // } } catch (DllNotFoundException e) { // Ensure that metee.dll is in the same directory as the executable Console.WriteLine(e); } } } }�����������������������������������������������������������������������������������������intel-metee-67ff323/samples/meiuuid.c���������������������������������������������������������������0000664�0000000�0000000�00000002275�15201331742�0017541�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2024 Intel Corporation */ #include <stdlib.h> #include <stdint.h> #include <ctype.h> #include <string.h> #include "metee.h" #include "meiuuid.h" int mei_uuid_parse(const char *str, GUID *uuid) { const char *p = "00000000-0000-0000-0000-000000000000"; const size_t len = strlen(p); uint32_t a; uint16_t b, c; uint8_t d[2], e[6]; char buf[3]; int i; if (strlen(str) != len) return -1; for (i = 0; i < len; i++) { if (str[i] == '-') { if (p[i] == '-') continue; else return -1; } else if (!isxdigit(str[i])) { return -1; } } a = strtoul(str + 0, NULL, 16); b = strtoul(str + 9, NULL, 16); c = strtoul(str + 14, NULL, 16); buf[2] = 0; for (i = 0; i < 2; i++) { buf[0] = str[19 + i * 2]; buf[1] = str[19 + i * 2 + 1]; d[i] = strtoul(buf, NULL, 16); } for (i = 0; i < 6; i++) { buf[0] = str[24 + i * 2]; buf[1] = str[24 + i * 2 + 1]; e[i] = strtoul(buf, NULL, 16); } uuid->l = a; uuid->w1 = b; uuid->w2 = c; uuid->b[0] = d[0]; uuid->b[1] = d[1]; uuid->b[2] = e[0]; uuid->b[3] = e[1]; uuid->b[4] = e[2]; uuid->b[5] = e[3]; uuid->b[6] = e[4]; uuid->b[7] = e[5]; return 0; } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/meiuuid.h���������������������������������������������������������������0000664�0000000�0000000�00000000217�15201331742�0017540�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2024 Intel Corporation */ int mei_uuid_parse(const char *str, GUID *uuid); ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/metee_basic.c�����������������������������������������������������������0000664�0000000�0000000�00000007721�15201331742�0020341�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024-2025 Intel Corporation */ #include <stdio.h> #include <stdlib.h> #ifdef __linux__ #include <unistd.h> #endif /* __linux__ */ #include <metee.h> DEFINE_GUID(MEI_MKHIF, 0x8e6a6715, 0x9abc, 0x4043, 0x88, 0xef, 0x9e, 0x39, 0xc6, 0xf6, 0x3e, 0xf); #define MKHI_TIMEOUT 10000 #define CONNECT_RETRIES 3 #pragma pack(1) struct mkhi_msg_hdr { union { uint32_t data; struct { uint32_t GroupId : 8; uint32_t Command : 7; uint32_t IsResponse : 1; uint32_t Reserved : 8; uint32_t Result : 8; }; }; }; struct mkhi_fwver_req { struct mkhi_msg_hdr header; }; struct mkhi_fw_version_block { uint16_t minor; uint16_t major; uint16_t buildNo; uint16_t hotFix; }; struct mkhi_fw_version { struct mkhi_fw_version_block code; struct mkhi_fw_version_block NFTP; struct mkhi_fw_version_block FITC; }; struct mkhi_fwver_rsp { struct mkhi_msg_hdr header; struct mkhi_fw_version version; }; #pragma pack() int main(int argc, char* argv[]) { TEEHANDLE handle; TEESTATUS status; struct tee_device_address addr = { .type = TEE_DEVICE_TYPE_NONE, .data.path = NULL }; int retry = CONNECT_RETRIES; size_t written = 0; struct mkhi_fwver_req req; uint8_t *read_buf = NULL; struct mkhi_fwver_rsp* rsp; char kind[32]; size_t kind_size = sizeof(kind); status = TeeInitFull(&handle, &MEI_MKHIF, addr, TEE_LOG_LEVEL_VERBOSE, NULL); if (!TEE_IS_SUCCESS(status)) { fprintf(stderr, "TeeInitFull failed with status = %u\n", status); return 1; } status = TeeGetKind(&handle, kind, &kind_size); if (!TEE_IS_SUCCESS(status)) { fprintf(stderr, "TeeGetKind failed with status = %u\n", status); } else { printf("Tee device kind is %s\n", kind); } while (retry--) { status = TeeConnect(&handle); if (status != TEE_BUSY && status != TEE_UNABLE_TO_COMPLETE_OPERATION) /* windows return this error on busy */ break; fprintf(stderr, "Client is busy, retrying\n"); #ifdef WIN32 Sleep(2000); #else sleep(2); #endif /* WIN32 */ } switch (status) { case TEE_SUCCESS: break; case TEE_CLIENT_NOT_FOUND: fprintf(stderr, "TeeConnect failed with status = %u (Client not found)\n", status); goto out; default: fprintf(stderr, "TeeConnect failed with status = %u\n", status); goto out; } if (TeeGetMaxMsgLen(&handle) == 0) { fprintf(stderr, "Client reported zero MTU. Aborting.\n"); goto out; } /* Write */ req.header.data = 0; /* Reset */ req.header.GroupId = 0xFF; /* MKHI */ req.header.Command = 0x02; /* GET FW Version */ req.header.IsResponse = 0; req.header.Reserved = 0; status = TeeWrite(&handle, &req, sizeof(req), &written, MKHI_TIMEOUT); if (!TEE_IS_SUCCESS(status)) { fprintf(stderr, "TeeWrite failed with status = %u\n", status); goto out; } if (written != sizeof(req)) { fprintf(stderr, "TeeWrite failed written = %zu\n", written); status = TEE_INTERNAL_ERROR; goto out; } /* Read */ read_buf = (uint8_t*)malloc(TeeGetMaxMsgLen(&handle)); if (!read_buf) { fprintf(stderr, "malloc failed\n"); status = TEE_INTERNAL_ERROR; goto out; } status = TeeRead(&handle, read_buf, TeeGetMaxMsgLen(&handle), &written, MKHI_TIMEOUT); if (!TEE_IS_SUCCESS(status)) { fprintf(stderr, "TeeWrite failed with status = %u\n", status); goto out; } rsp = (struct mkhi_fwver_rsp*)read_buf; if (written < sizeof(struct mkhi_msg_hdr)) { fprintf(stderr, "Returned less then header = %zu\n", written); status = TEE_INTERNAL_ERROR; goto out; } if (written < sizeof(struct mkhi_fwver_rsp)) { fprintf(stderr, "Returned less then response = %zu\n", written); status = TEE_INTERNAL_ERROR; goto out; } if (rsp->header.Result) { fprintf(stderr, "Result = %u\n", rsp->header.Result); status = TEE_INTERNAL_ERROR; goto out; } printf("Version: %u.%u.%u.%u\n", rsp->version.code.major, rsp->version.code.minor, rsp->version.code.hotFix, rsp->version.code.buildNo); out: TeeDisconnect(&handle); if (read_buf) free(read_buf); return TEE_IS_SUCCESS(status) ? 0 : 1; } �����������������������������������������������intel-metee-67ff323/samples/metee_connect.c���������������������������������������������������������0000664�0000000�0000000�00000004645�15201331742�0020713�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2024 Intel Corporation */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <sys/ioctl.h> #include <unistd.h> #include <errno.h> #include <stdint.h> #include <stdbool.h> #include <limits.h> #include <ctype.h> #include <linux/mei.h> #include <metee.h> #include "meiuuid.h" struct params { bool verbose; GUID uuid; int iterations; }; static int work(struct params *p) { TEEHANDLE cl; const unsigned char cmd[] = "AB"; const ssize_t sz = sizeof(cmd); unsigned char *buf = NULL; size_t rsz, wsz; int i; TEESTATUS status; status = TeeInit(&cl, &p->uuid, NULL); if (status != TEE_SUCCESS) goto out; status = TeeConnect(&cl); if (status != TEE_SUCCESS) goto out; rsz = TeeGetMaxMsgLen(&cl); if (rsz == 0) { fprintf(stderr, "client reproted zero MTU.\n"); goto out; } buf = (unsigned char *)malloc(rsz); if (buf == NULL) goto out; memset(buf, 0, rsz); for (i = 0; i < p->iterations; i++) { status = TeeWrite(&cl, cmd , sz, &wsz, 0); if (status != TEE_SUCCESS) goto out; if (wsz != sz) { status = TEE_UNABLE_TO_COMPLETE_OPERATION; goto out; } status = TeeRead(&cl, buf, rsz, NULL, 10000); if (status != TEE_SUCCESS) goto out; } out: TeeDisconnect(&cl); free(buf); return status; } static void usage(const char *p) { fprintf(stdout, "%s: -u <uuid> [-i <iterations>] [-h]\n", p); } #define BIT(_x) (1L<<(_x)) #define UUID_BIT BIT(1) #define ITER_BIT BIT(2) static int mei_getopt(int argc, char *argv[], struct params *p) { unsigned long required = UUID_BIT; unsigned long present = 0; extern char *optarg; int opt; while ((opt = getopt(argc, argv, "hvu:i:")) != -1) { switch (opt) { case 'v': p->verbose = true; break; case 'u': present |= UUID_BIT; if (mei_uuid_parse(optarg, &p->uuid) < 0) return -1; break; case 'i': present |= ITER_BIT; p->iterations = strtoul(optarg, NULL, 10); break; case 'h': case '?': usage(argv[0]); break; } } if ((required & present) != required) { usage(argv[0]); return -1; } return 0; } int main(int argc, char *argv[]) { struct params p; int rc; p.verbose = false; memset(&p.uuid, 0, sizeof(p.uuid)); p.iterations = 1; #ifdef _WIN32 //p.uuid = ; #else rc = mei_getopt(argc, argv, &p); if (rc) { usage(argv[0]); exit(EXIT_FAILURE); } #endif /* _WIN32 */ rc = work(&p); exit(rc); } �������������������������������������������������������������������������������������������intel-metee-67ff323/samples/metee_gsc.c�������������������������������������������������������������0000664�0000000�0000000�00000026435�15201331742�0020037�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2020-2025 Intel Corporation */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <stdint.h> #include <metee.h> #ifndef BIT #define BIT(n) 1 << (n) #endif /* BIT */ #include <stdbool.h> #ifdef _WIN32 typedef SSIZE_T ssize_t; #else #include <unistd.h> #endif /* _WIN32 */ #pragma pack(1) struct gsc_fwu_heci_header { uint8_t command_id; uint8_t is_response :1; uint8_t reserved :7; uint8_t reserved2[2]; }; struct gsc_fwu_heci_version_req { struct gsc_fwu_heci_header header; uint32_t partition; }; struct gsc_fwu_heci_response { struct gsc_fwu_heci_header header; uint32_t status; uint32_t reserved; }; struct gsc_fwu_heci_version_resp { struct gsc_fwu_heci_response response; uint32_t partition; uint32_t version_length; uint8_t version[]; }; struct gsc_fwu_external_version { char project[4]; uint16_t hotfix; uint16_t build; }; #pragma pack() #define GSC_FWU_HECI_COMMAND_ID_GET_IP_VERSION 6 enum gsc_fwu_heci_payload_type { gsc_fwu_heci_payload_type_invalid = 0, /**< lower sentinel */ gsc_fwu_heci_payload_type_gfx_fw = 1, /**< graphics firmware */ gsc_fwu_heci_payload_type_oprom_data = 2, /**< oprom data partition */ gsc_fwu_heci_payload_type_oprom_code = 3, /**< oprom code partition */ }; /** GSC firmware update status SUCCESS */ #define GSC_FWU_STATUS_SUCCESS 0x0 /** GSC firmware update status size error */ #define GSC_FWU_STATUS_SIZE_ERROR 0x5 /** GSC Update oprom section does not exists error */ #define GSC_FWU_STATUS_INVALID_COMMAND 0x8D /** GSC firmware update status invalid param error */ #define GSC_FWU_STATUS_INVALID_PARAMS 0x85 /** GSC firmware update general failure */ #define GSC_FWU_STATUS_FAILURE 0x9E #define MKHI_READ_TIMEOUT 10000 const char *mkhi_status(uint32_t status) { #define MKH_STATUS(_x) case _x: return #_x switch(status) { MKH_STATUS(GSC_FWU_STATUS_SUCCESS); MKH_STATUS(GSC_FWU_STATUS_SIZE_ERROR); MKH_STATUS(GSC_FWU_STATUS_INVALID_COMMAND); MKH_STATUS(GSC_FWU_STATUS_INVALID_PARAMS); MKH_STATUS(GSC_FWU_STATUS_FAILURE); default: fprintf(stderr, "unknown 0x%08X\n", status); return "unknown"; } #undef MKH_STATUS } DEFINE_GUID(GUID_DEVINTERFACE_HECI_GSC_CHILD, 0x5315db55, 0xe7c7, 0x4e67, 0xb3, 0x96, 0x80, 0xa, 0x75, 0xdd, 0x6f, 0xe4); DEFINE_GUID(GUID_METEE_FWU, 0x87d90ca5, 0x3495, 0x4559, 0x81, 0x05, 0x3f, 0xbf, 0xa3, 0x7b, 0x8b, 0x79); struct mk_host_if { TEEHANDLE mei_cl; bool initialized; bool reconnect; bool verbose; }; static void mk_host_if_fw_status(struct mk_host_if *acmd) { uint32_t fwStatus = 0; for (uint32_t i = 0; i < 6; i++) if (TeeFWStatus(&acmd->mei_cl, i, &fwStatus) == TEE_SUCCESS) printf("FW Status[%u] = 0x%08X\n", i, fwStatus); } static bool mk_host_if_is_gscfi(struct mk_host_if *acmd) { char kind[32]; size_t kind_size = sizeof(kind); if (TeeGetKind(&acmd->mei_cl, kind, &kind_size) != TEE_SUCCESS) return false; return !strcmp(kind, "gscfi"); } static bool mk_host_if_connect(struct mk_host_if *acmd) { acmd->initialized = (TeeConnect(&acmd->mei_cl) == 0); return acmd->initialized; } static void mk_host_if_log(bool is_error, const char* data) { fprintf((is_error) ? stderr : stdout, "LIB: %s", data); } static bool mk_host_if_init(struct mk_host_if *acmd, const GUID *guid, bool reconnect, bool verbose) { #ifdef WIN32 #define ADDR_NUM 1 struct tee_device_address addr[ADDR_NUM] = { { .type = TEE_DEVICE_TYPE_GUID, .data.guid = &GUID_DEVINTERFACE_HECI_GSC_CHILD } }; #else #define ADDR_NUM 3 struct tee_device_address addr[ADDR_NUM] = { { .type = TEE_DEVICE_TYPE_PATH, .data.path = "/dev/mei0" }, { .type = TEE_DEVICE_TYPE_PATH, .data.path = "/dev/mei1" }, { .type = TEE_DEVICE_TYPE_PATH, .data.path = "/dev/mei2" }, }; #endif /* WIN32 */ acmd->reconnect = reconnect; acmd->verbose = verbose; for (size_t i = 0; i < ADDR_NUM; i++) { if (TeeInitFull2(&acmd->mei_cl, guid, addr[i], (verbose) ? TEE_LOG_LEVEL_VERBOSE : TEE_LOG_LEVEL_ERROR, mk_host_if_log) != TEE_SUCCESS) return false; if (!mk_host_if_is_gscfi(acmd)) { TeeDisconnect(&acmd->mei_cl); continue; } mk_host_if_fw_status(acmd); return mk_host_if_connect(acmd); } return false; } static void mk_host_if_deinit(struct mk_host_if *acmd) { TeeDisconnect(&acmd->mei_cl); } static uint32_t mkhi_verify_response_header(struct gsc_fwu_heci_header *msg, struct gsc_fwu_heci_header *resp) { bool match = true; if (msg->command_id != resp->command_id) { printf("Mismatch Command; Req-Command = %d , Resp-Command = %d\n", msg->command_id, resp->command_id); match = false; } if (resp->is_response != 1) { printf("Wrong IsResponse; Resp-IsResponse = %d\n", resp->is_response); match = false; } return match ? GSC_FWU_STATUS_SUCCESS : GSC_FWU_STATUS_FAILURE; } static uint32_t mk_host_if_call(struct mk_host_if *acmd, const unsigned char *command, ssize_t command_sz, uint8_t **read_buf, uint32_t rcmd, unsigned int expected_sz) { uint32_t in_buf_sz; size_t out_buf_sz; size_t written; TEESTATUS status; struct gsc_fwu_heci_response *msg_hdr; int count = 0; in_buf_sz = TeeGetMaxMsgLen(&acmd->mei_cl); if (in_buf_sz == 0) { if (acmd->verbose) fprintf(stderr, "mkhif: client reproted zero MTU.\n"); return GSC_FWU_STATUS_FAILURE; } *read_buf = (uint8_t *)malloc(in_buf_sz); if (*read_buf == NULL) return GSC_FWU_STATUS_FAILURE; memset(*read_buf, 0, in_buf_sz); msg_hdr = (struct gsc_fwu_heci_response *)*read_buf; while (count++ < 2) { status = TeeWrite(&acmd->mei_cl, command, command_sz, &written, 0); if (status || written != command_sz) { if(!acmd->reconnect || !mk_host_if_connect(acmd)) return GSC_FWU_STATUS_FAILURE; continue; } break; } status = TeeRead(&acmd->mei_cl, *read_buf, in_buf_sz, &out_buf_sz, MKHI_READ_TIMEOUT); if (status) return GSC_FWU_STATUS_FAILURE; status = msg_hdr->status; if (acmd->verbose) fprintf(stderr, "mkhif: message header read status = %d\n", status); status = mkhi_verify_response_header((struct gsc_fwu_heci_header *)command, &msg_hdr->header); if (status != GSC_FWU_STATUS_SUCCESS) return status; if (expected_sz && expected_sz != out_buf_sz) { return GSC_FWU_STATUS_FAILURE; } return GSC_FWU_STATUS_SUCCESS; } static void printf_if_fw_version(struct gsc_fwu_external_version *version) { printf("Firmware Version %c%c%c%c.%d.%d\n", version->project[0], version->project[1], version->project[2], version->project[3], version->hotfix, version->build); } static uint32_t mk_host_if_fw_version(struct mk_host_if *cmd, struct gsc_fwu_external_version *version) { struct gsc_fwu_heci_version_req req; struct gsc_fwu_heci_version_resp *response = NULL; uint32_t status; size_t size = sizeof(struct gsc_fwu_heci_version_resp) + sizeof(struct gsc_fwu_external_version); req.header.command_id = GSC_FWU_HECI_COMMAND_ID_GET_IP_VERSION; /* GET FW Version */ req.header.is_response = 0; req.header.reserved = 0; req.header.reserved2[0] = 0; req.header.reserved2[1] = 0; req.partition = gsc_fwu_heci_payload_type_gfx_fw; status = mk_host_if_call(cmd, (const unsigned char *)&req, sizeof(req), (uint8_t **)&response, 0, (unsigned int)size); if (status != GSC_FWU_STATUS_SUCCESS) { return status; } memcpy(version, response->version, sizeof(struct gsc_fwu_external_version)); return status; } static uint32_t mk_host_if_fw_version_req(struct mk_host_if *acmd) { struct gsc_fwu_heci_version_req req; unsigned char *buf = (unsigned char *)&req; size_t written; TEESTATUS status; req.header.command_id = GSC_FWU_HECI_COMMAND_ID_GET_IP_VERSION; /* GET FW Version */ req.header.is_response = 0; req.header.reserved = 0; req.header.reserved2[0] = 0; req.header.reserved2[1] = 0; req.partition = gsc_fwu_heci_payload_type_gfx_fw; status = TeeWrite(&acmd->mei_cl, buf, sizeof(req), &written, 0); if (status || written != sizeof(req)) return GSC_FWU_STATUS_FAILURE; return GSC_FWU_STATUS_SUCCESS; } static uint32_t mk_host_if_fw_version_resp(struct mk_host_if *acmd) { size_t recvd; TEESTATUS status; unsigned char rec_msg[100]; struct gsc_fwu_heci_version_resp *response = (struct gsc_fwu_heci_version_resp *)rec_msg; size_t size = sizeof(struct gsc_fwu_heci_version_resp) + sizeof(struct gsc_fwu_external_version); status = TeeRead(&acmd->mei_cl, rec_msg, size, &recvd, MKHI_READ_TIMEOUT); if (status || recvd <= 0) return GSC_FWU_STATUS_FAILURE; printf_if_fw_version((struct gsc_fwu_external_version *)response->version); return GSC_FWU_STATUS_SUCCESS; } static void usage(const char *p) { fprintf(stderr, "Usage: %s [-hv] [-e <l> ] [-i <n> ] [-b M.m.f.b] [-r] [-s <seq>] [-k <n>]\n", p); fprintf(stderr, " -h help\n"); fprintf(stderr, " -v verbose\n"); fprintf(stderr, " -i <n> iterate n times\n"); fprintf(stderr, " -r reconnect if failed to write\n"); fprintf(stderr, " -k <n> timeout between iterations in microseconds (default: 0)\n"); } int main(int argc, char *argv[]) { struct mk_host_if acmd; /* Version Data */ struct gsc_fwu_external_version version; unsigned int i, iterations = 1; const GUID *guid = &GUID_METEE_FWU; char *sequence = NULL; bool verbose = false; int ret = 0; bool reconnect = false; unsigned long iter_timeout = 0; #ifdef _WIN32 verbose = true; reconnect = true; #else size_t echo_size; extern char *optarg; int opt; while ((opt = getopt(argc, argv, "hv:i:s:rk:")) != -1) { switch (opt) { case 'v': verbose = true; break; case 'i': ret = sscanf(optarg,"%u", &iterations); if (ret != 1) { usage(argv[0]); exit(1); } break; case 's': sequence = optarg; break; case 'r': reconnect = true; break; case 'k': ret = sscanf(optarg,"%lu", &iter_timeout); if (ret != 1) { usage(argv[0]); exit(1); } break; case 'h': usage(argv[0]); exit(EXIT_SUCCESS); case '?': default: usage(argv[0]); exit(EXIT_FAILURE); } } #endif /* _WIN32 */ if (!mk_host_if_init(&acmd, guid, reconnect, verbose)) { ret = 1; goto out; } if (sequence) { for (i = 0; i < strlen(sequence); i++) { if (sequence[i] == 's') mk_host_if_fw_version_req(&acmd); else if (sequence[i] == 'r') mk_host_if_fw_version_resp(&acmd); } } for (i = 0; i < iterations ; i++) { if (iter_timeout && i > 0) { printf("Sleeping for %lu microseconds ...\n", iter_timeout); #ifdef _WIN32 Sleep(iter_timeout/1000); #else usleep(iter_timeout); #endif /* _WIN32_ */ } printf("Running version test %d...\n", i); memset(&version, 0, sizeof(version)); ret = mk_host_if_fw_version(&acmd, &version); if (ret != GSC_FWU_STATUS_SUCCESS) goto out; printf_if_fw_version(&version); if (ret != GSC_FWU_STATUS_SUCCESS) goto out; } out: mk_host_if_deinit(&acmd); printf("STATUS %s\n", mkhi_status(ret)); return ret; } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/metee_mkhi.c������������������������������������������������������������0000664�0000000�0000000�00000037404�15201331742�0020211�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2012-2024 Intel Corporation */ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <stdint.h> #include <metee.h> #ifndef BIT #define BIT(n) 1 << (n) #endif /* BIT */ #include <stdbool.h> #ifdef _WIN32 typedef SSIZE_T ssize_t; #else #include <unistd.h> #endif /* _WIN32 */ struct mkhi_msg_hdr { union { uint32_t data; struct { uint32_t GroupId :8; uint32_t Command :7; uint32_t IsResponse :1; uint32_t Reserved :8; uint32_t Result :8; }; }; }; struct mk_host_if_msg { struct mkhi_msg_hdr header; uint8_t data[0]; }; struct _firmware_version { uint16_t minor; uint16_t major; uint16_t buildNo; uint16_t hotFix; }; struct mei_firmware_version { struct _firmware_version code; struct _firmware_version NFTP; struct _firmware_version FITC; }; enum mkhi_group_id { MKHI_CBM_GROUP_ID = 0, MKHI_PM_GROUP_ID, MKHI_PWD_GROUP_ID, MKHI_FWCAPS_GROUP_ID, MKHI_APP_GROUP_ID, /* Reserved (no longer used). */ MKHI_FWUPDATE_GROUP_ID, /* This is for manufacturing downgrade */ MKHI_FIRMWARE_UPDATE_GROUP_ID, MKHI_BIST_GROUP_ID, MKHI_MDES_GROUP_ID, MKHI_ME_DBG_GROUP_ID, MKHI_MAX_GROUP_ID, MKHI_GEN_GROUP_ID = 0xFF }; #define MKHI_STATUS_SUCCESS 0x0 #define MKHI_STATUS_INTERNAL_ERROR 0x1 #define MKHI_STATUS_NOT_READY 0x2 #define MKHI_STATUS_INVALID_AMT_MODE 0x3 #define MKHI_STATUS_INVALID_MESSAGE_LENGTH 0x4 #define MKHI_STATUS_HOST_IF_EMPTY_RESPONSE 0x4000 #define MKHI_STATUS_SDK_RESOURCES 0x1004 #define MKHI_TEST_ECHO_GROUP_ID MKHI_APP_GROUP_ID #define TEST_ECHO_CMD 0x01 #define MKHI_READ_TIMEOUT 10000 const char *mkhi_status(uint32_t status) { #define MKH_STATUS(_x) case _x: return #_x switch(status) { MKH_STATUS(MKHI_STATUS_SUCCESS); MKH_STATUS(MKHI_STATUS_INTERNAL_ERROR); MKH_STATUS(MKHI_STATUS_NOT_READY); MKH_STATUS(MKHI_STATUS_INVALID_AMT_MODE); MKH_STATUS(MKHI_STATUS_INVALID_MESSAGE_LENGTH); MKH_STATUS(MKHI_STATUS_HOST_IF_EMPTY_RESPONSE); MKH_STATUS(MKHI_STATUS_SDK_RESOURCES); default: fprintf(stderr, "unknown 0x%08X\n", status); return "unknown"; } #undef MKH_STATUS } struct mkhi_test_msg_hdr { union { uint32_t data; struct { uint32_t GroupId :8; uint32_t Command :7; uint32_t IsResponse :1; uint32_t Size :16; }; }; }; struct mkhi_test_msg { struct mkhi_test_msg_hdr header; unsigned char data[0]; }; static size_t mkhi_test_msg_size(struct mkhi_test_msg *msg) { return msg->header.Size + sizeof(msg->header); } static struct mkhi_test_msg *mkhi_test_msg_alloc(size_t size) { size_t cnt = size / 4 + 1 + 1; /* size + possible alignment + header */ struct mkhi_test_msg * _ptr = (struct mkhi_test_msg *)calloc(cnt, sizeof(uint32_t)); if (_ptr) _ptr->header.Size = (uint32_t)size; return _ptr; } #define MAX_TEST_MESSAGE_SIZE_BYTES 1000 #define MAX_TEST_MESSAGE_SIZE_DWORDS MAX_TEST_MESSAGE_SIZE_BYTES/sizeof(uint32_t) DEFINE_GUID(MEI_MKHIF, 0x8e6a6715, 0x9abc,0x4043, 0x88, 0xef, 0x9e, 0x39, 0xc6, 0xf6, 0x3e, 0xf); DEFINE_GUID(MEI_MKHIF_TEST, 0x22222222, 0x9abc, 0x4043, 0x88, 0xef, 0x9e, 0x39, 0xc6, 0xf6, 0x3e, 0xf); struct mk_host_if { TEEHANDLE mei_cl; bool initialized; bool reconnect; bool verbose; }; static bool mk_host_if_connect(struct mk_host_if *acmd) { acmd->initialized = (TeeConnect(&acmd->mei_cl) == 0); return acmd->initialized; } void mk_host_if_log(bool is_error, const char* fmt, ...) { #define DEBUG_MSG_LEN 1024 char msg[DEBUG_MSG_LEN + 1]; va_list varl; va_start(varl, fmt); vsprintf(msg, fmt, varl); va_end(varl); fprintf((is_error) ? stderr : stdout, "LIB: %s", msg); } static bool mk_host_if_init(struct mk_host_if *acmd, const GUID *guid, bool reconnect, bool verbose) { int status; uint32_t log_level, original_log_level; struct tee_device_address addr = { .type = TEE_DEVICE_TYPE_NONE, .data.path = NULL }; acmd->reconnect = reconnect; acmd->verbose = verbose; status = TeeInitFull(&acmd->mei_cl, guid, addr, (verbose) ? TEE_LOG_LEVEL_VERBOSE : TEE_LOG_LEVEL_ERROR, mk_host_if_log); if (!TEE_IS_SUCCESS(status)) { fprintf(stderr, "init failed with status = %d\n", status); return false; } original_log_level = TeeGetLogLevel(&acmd->mei_cl); printf("Original log level: %u\n", original_log_level); log_level = TeeSetLogLevel(&acmd->mei_cl, TEE_LOG_LEVEL_ERROR); printf("Original log level: %u\n", log_level); log_level = TeeGetLogLevel(&acmd->mei_cl); printf("New log level: %u\n", log_level); TeeSetLogLevel(&acmd->mei_cl, original_log_level); printf("Original log level: %u\n", original_log_level); return mk_host_if_connect(acmd); } static void mk_host_if_deinit(struct mk_host_if *acmd) { TeeDisconnect(&acmd->mei_cl); } static uint32_t mkhi_verify_response_header(struct mkhi_msg_hdr *msg, struct mkhi_msg_hdr *resp) { bool match = true; if (msg->Command != resp->Command) { printf("Mismatch Command; Req-Command = %d , Resp-Command = %d\n", msg->Command, resp->Command); match = false; } if (msg->GroupId != resp->GroupId) { printf("Mismatch GroupId; Req-GroupId = %d , Resp-GroupId = %d\n", msg->GroupId, resp->GroupId); match = false; } if (resp->IsResponse != 1) { printf("Wrong IsResponse; Resp-IsResponse = %d\n", resp->IsResponse); match = false; } return match ? MKHI_STATUS_SUCCESS : MKHI_STATUS_INTERNAL_ERROR; } static uint32_t mk_host_if_call(struct mk_host_if *acmd, const unsigned char *command, ssize_t command_sz, uint8_t **read_buf, uint32_t rcmd, unsigned int expected_sz) { uint32_t in_buf_sz; size_t out_buf_sz; size_t written; TEESTATUS status; struct mk_host_if_msg *msg_hdr; int count = 0; in_buf_sz = TeeGetMaxMsgLen(&acmd->mei_cl); if (in_buf_sz == 0) { if (acmd->verbose) fprintf(stderr, "mkhif: client reproted zero MTU.\n"); return MKHI_STATUS_INTERNAL_ERROR; } *read_buf = (uint8_t *)malloc(in_buf_sz); if (*read_buf == NULL) return MKHI_STATUS_SDK_RESOURCES; memset(*read_buf, 0, in_buf_sz); msg_hdr = (struct mk_host_if_msg *)*read_buf; while (count++ < 2) { status = TeeWrite(&acmd->mei_cl, command, command_sz, &written, 0); if (status || written != command_sz) { if(!acmd->reconnect || !mk_host_if_connect(acmd)) return MKHI_STATUS_INTERNAL_ERROR; continue; } break; } status = TeeRead(&acmd->mei_cl, *read_buf, in_buf_sz, &out_buf_sz, MKHI_READ_TIMEOUT); if (status) return MKHI_STATUS_HOST_IF_EMPTY_RESPONSE; status = msg_hdr->header.Result; if (acmd->verbose) fprintf(stderr, "mkhif: message header read status = %d\n", status); #if 0 if (status != MKHI_STATUS_SUCCESS) return status; #endif status = mkhi_verify_response_header((struct mkhi_msg_hdr *)command, &msg_hdr->header); if (status != MKHI_STATUS_SUCCESS) return status; if (expected_sz && expected_sz != out_buf_sz) { return MKHI_STATUS_INTERNAL_ERROR; } return MKHI_STATUS_SUCCESS; } static uint32_t mk_host_if_fw_component_version_validate(const char *component, struct _firmware_version *version, struct _firmware_version *expected) { uint32_t match = 0; if (!component) return (uint32_t)-1; if (version->major != expected->major) { printf("Wrong %s Major %d != %d\n", component, version->major, expected->major); match |= BIT(1); } if (version->minor != expected->minor) { printf("Wrong %s Minor %d != %d\n", component, version->minor, expected->minor); match |= BIT(2); } if (version->hotFix != expected->hotFix) { printf("Wrong %s HotFix %d != %d\n", component, version->hotFix, expected->hotFix); match |= BIT(3); } if (version->buildNo != expected->buildNo) { printf("Wrong %s BuildNo %d != %d\n", component, version->buildNo, expected->buildNo); match |= BIT(4); } return match; } static uint32_t mk_host_if_fw_version_validate(struct mei_firmware_version *version, struct mei_firmware_version *expected) { uint32_t match = 0; match |= mk_host_if_fw_component_version_validate("code", &version->code, &expected->code); match |= mk_host_if_fw_component_version_validate("NFTP", &version->NFTP, &expected->NFTP); /* Do not validate FITC * match |= mk_host_if_fw_component_version_validate("FITC", &version->FITC, &expected->FITC); */ return match == 0 ? MKHI_STATUS_SUCCESS : MKHI_STATUS_INTERNAL_ERROR; } static void printf_if_fw_version(struct mei_firmware_version *version) { #define print_ver_component(COMP) \ printf("ME "# COMP " Firmware Version %d.%d.%d.%d\n", \ version->COMP.major, version->COMP.minor, \ version->COMP.hotFix, version->COMP.buildNo); print_ver_component(code); print_ver_component(NFTP); print_ver_component(FITC); #undef print_ver_component } static uint32_t mk_host_if_fw_version(struct mk_host_if *cmd, struct mei_firmware_version *version) { struct mkhi_msg_hdr hdr; struct mk_host_if_msg *response = NULL; uint32_t status; size_t size = sizeof(struct mkhi_msg_hdr) + sizeof(struct mei_firmware_version); hdr.data = 0; /* Reset */ hdr.GroupId = 0xFF; /* MKHI */ hdr.Command = 0x02; /* GET FW Version */ hdr.IsResponse = 0; hdr.Reserved = 0; status = mk_host_if_call(cmd, (const unsigned char *)&hdr, sizeof(hdr), (uint8_t **)&response, 0, (unsigned int)size); if (status != MKHI_STATUS_SUCCESS) { return status; } memcpy(version, response->data, sizeof(struct mei_firmware_version)); return status; } static uint32_t mk_host_if_fw_version_req(struct mk_host_if *acmd) { struct mkhi_msg_hdr hdr; unsigned char *buf = (unsigned char *)&hdr; size_t written; TEESTATUS status; hdr.data = 0; /* Reset */ hdr.GroupId = 0xFF; /* MKHI */ hdr.Command = 0x02; /* GET FW Version */ hdr.IsResponse = 0; hdr.Reserved = 0; status = TeeWrite(&acmd->mei_cl, buf, sizeof(hdr), &written, 0); if (status || written != sizeof(hdr)) return MKHI_STATUS_INTERNAL_ERROR; return MKHI_STATUS_SUCCESS; } static uint32_t mk_host_if_fw_version_resp(struct mk_host_if *acmd) { size_t recvd; TEESTATUS status; unsigned char rec_msg[100]; size_t size = sizeof(struct mkhi_msg_hdr) + sizeof(struct mei_firmware_version); status = TeeRead(&acmd->mei_cl, rec_msg, size, &recvd, MKHI_READ_TIMEOUT); if (status || recvd <= 0) return MKHI_STATUS_HOST_IF_EMPTY_RESPONSE; printf_if_fw_version((struct mei_firmware_version *)rec_msg); return MKHI_STATUS_SUCCESS; } static uint32_t mk_host_if_echo_validate(uint8_t *request, uint8_t *response, size_t len) { unsigned int i; for (i = 0; i < len; i++) if (request[i] != response[i]) break; if (i < len) { printf("Mismatch Echo [%d] request=0x%08X:response=0x%08X\n", i, request[i], response[i]); return MKHI_STATUS_INTERNAL_ERROR; } return MKHI_STATUS_SUCCESS; } static uint32_t mk_host_if_echo(struct mk_host_if *cmd, struct mkhi_test_msg *msg) { struct mkhi_test_msg *response = NULL; size_t echo_len = mkhi_test_msg_size(msg); uint32_t status; msg->header.GroupId = MKHI_TEST_ECHO_GROUP_ID; msg->header.Command = TEST_ECHO_CMD; msg->header.IsResponse = 0; status = mk_host_if_call(cmd, (const unsigned char *)msg, (unsigned int)echo_len, (uint8_t **)&response, 0, (unsigned int)echo_len); if (status != MKHI_STATUS_SUCCESS) return status; if (response->header.Size != msg->header.Size) { printf("Mismatch Echo size request=%d:response=%d\n", msg->header.Size, response->header.Size); return MKHI_STATUS_INVALID_MESSAGE_LENGTH; } status = mk_host_if_echo_validate(msg->data, response->data, msg->header.Size); return status; } static void usage(const char *p) { fprintf(stderr, "Usage: %s [-hv] [-e <l> ] [-i <n> ] [-b M.m.f.b] [-r] [-s <seq>] [-k <n>]\n", p); fprintf(stderr, " -h help\n"); fprintf(stderr, " -v verbose\n"); fprintf(stderr, " -b [M.m.f.b] expect fw version M.m.f.b\n"); fprintf(stderr, " -t check for test fw\n"); fprintf(stderr, " -e <l> run echo command of l (less then 1024) bytes (only with test fw)\n"); fprintf(stderr, " -i <n> iterate n times\n"); fprintf(stderr, " -r reconnect if failed to write\n"); fprintf(stderr, " -k <n> timeout between iterations in microseconds (default: 0)\n"); } int main(int argc, char *argv[]) { struct mk_host_if acmd; /* Version Data */ struct mei_firmware_version version; struct mei_firmware_version *_expected = NULL; struct mkhi_test_msg *echo_msg = NULL; unsigned int i, iterations = 1; const GUID *guid = &MEI_MKHIF; char *sequence = NULL; bool verbose = false; int ret = 0; bool reconnect = false; unsigned long iter_timeout = 0; #ifdef _WIN32 verbose = true; reconnect = true; #else struct mei_firmware_version expected; size_t echo_size; extern char *optarg; int opt; while ((opt = getopt(argc, argv, "hvb:e::i:ts:rk:")) != -1) { switch (opt) { case 'v': verbose = true; break; case 't': guid = &MEI_MKHIF_TEST; expected.code.major = 1; expected.code.minor = 2; expected.code.buildNo = 3; expected.code.hotFix = 4; expected.NFTP.minor = 5; expected.NFTP.major = 6; expected.NFTP.buildNo = 7; expected.NFTP.hotFix = 8; expected.FITC.minor = 9; expected.FITC.major = 10; expected.FITC.buildNo = 11; expected.FITC.hotFix = 12; _expected = &expected; break; case 'b': _expected = &expected; ret = sscanf(optarg, "%hd.%hd.%hd.%hd", &expected.code.major, &expected.code.minor, &expected.code.hotFix, &expected.code.buildNo); if (ret != 4) { usage(argv[0]); exit(1); } memcpy(&expected.NFTP, &expected.code, sizeof(expected.NFTP)); /* No need to check for FITC */ break; case 'e': ret = sscanf(optarg,"%zu", &echo_size); if (ret != 1) { usage(argv[0]); exit(1); } if (echo_size > 1024) { fprintf(stderr, "echo size is limited to 1024\n"); usage(argv[0]); exit(1); } echo_msg = mkhi_test_msg_alloc(echo_size); if (!echo_msg) { fprintf(stderr, "cannot allocate memory\n"); exit(1); } for (i = 0; i < echo_size; i++) { echo_msg->data[i] = i; } break; case 'i': ret = sscanf(optarg,"%u", &iterations); if (ret != 1) { usage(argv[0]); exit(1); } break; case 's': sequence = optarg; break; case 'r': reconnect = true; break; case 'k': ret = sscanf(optarg,"%lu", &iter_timeout); if (ret != 1) { usage(argv[0]); exit(1); } break; case 'h': usage(argv[0]); exit(EXIT_SUCCESS); case '?': default: usage(argv[0]); exit(EXIT_FAILURE); } } #endif /* _WIN32 */ if (!mk_host_if_init(&acmd, guid, reconnect, verbose)) { ret = 1; goto out; } if (sequence) { for (i = 0; i < strlen(sequence); i++) { if (sequence[i] == 's') mk_host_if_fw_version_req(&acmd); else if (sequence[i] == 'r') mk_host_if_fw_version_resp(&acmd); } } for (i = 0; i < iterations ; i++) { if (iter_timeout && i > 0) { printf("Sleeping for %lu microseconds ...\n", iter_timeout); #ifdef _WIN32 Sleep(iter_timeout/1000); #else usleep(iter_timeout); #endif /* _WIN32_ */ } printf("Running version test %d...\n", i); memset(&version, 0, sizeof(struct mei_firmware_version)); ret = mk_host_if_fw_version(&acmd, &version); if (ret != MKHI_STATUS_SUCCESS) goto out; if (_expected) ret = mk_host_if_fw_version_validate(&version, _expected); printf_if_fw_version(&version); if (ret != MKHI_STATUS_SUCCESS) goto out; } if (echo_msg) { printf("Running echo test size=%d...\n", echo_msg->header.Size); ret = mk_host_if_echo(&acmd, echo_msg); } out: free(echo_msg); mk_host_if_deinit(&acmd); printf("STATUS %s\n", mkhi_status(ret)); return ret; } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/metee_trc.c�������������������������������������������������������������0000664�0000000�0000000�00000001544�15201331742�0020045�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2023 Intel Corporation */ #include <stdio.h> #include <metee.h> DEFINE_GUID(GUID_DEVINTERFACE_NULL, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); int main(int argc, char* argv[]) { TEEHANDLE handle; TEESTATUS status; uint32_t trc_val = 0; struct tee_device_address addr = { .type = TEE_DEVICE_TYPE_NONE, .data.path = NULL }; status = TeeInitFull(&handle, &GUID_DEVINTERFACE_NULL, addr, TEE_LOG_LEVEL_VERBOSE, NULL); if (!TEE_IS_SUCCESS(status)) { fprintf(stderr, "init failed with status = %u\n", status); return 1; } status = TeeGetTRC(&handle, &trc_val); if (!TEE_IS_SUCCESS(status)) { fprintf(stderr, "TeeGetTRC failed with status = %u\n", status); } else { fprintf(stdout, "TRC = 0x%08X\n", trc_val); } TeeDisconnect(&handle); return 0; }������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/samples/meteepp_basic.cpp�������������������������������������������������������0000664�0000000�0000000�00000006263�15201331742�0021241�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2025 Intel Corporation */ #include <iostream> #include <thread> #include <meteepp.h> DEFINE_GUID(MEI_MKHIF, 0x8e6a6715, 0x9abc, 0x4043, 0x88, 0xef, 0x9e, 0x39, 0xc6, 0xf6, 0x3e, 0x0f); static const uint32_t MKHI_TIMEOUT = 10000; static const int CONNECT_RETRIES = 3; #pragma pack(1) struct mkhi_msg_hdr { union { uint32_t data; struct { uint32_t GroupId : 8; uint32_t Command : 7; uint32_t IsResponse : 1; uint32_t Reserved : 8; uint32_t Result : 8; }; }; }; struct mkhi_fwver_req { struct mkhi_msg_hdr header; }; struct mkhi_fw_version_block { uint16_t minor; uint16_t major; uint16_t buildNo; uint16_t hotFix; }; struct mkhi_fw_version { struct mkhi_fw_version_block code; struct mkhi_fw_version_block NFTP; struct mkhi_fw_version_block FITC; }; struct mkhi_fwver_rsp { struct mkhi_msg_hdr header; struct mkhi_fw_version version; }; #pragma pack() int main(int argc, char* argv[]) { int retry = CONNECT_RETRIES; try { intel::security::metee metee(MEI_MKHIF, TEE_LOG_LEVEL_VERBOSE); try { std::cout << "Device kind is " << metee.kind() << std::endl; } catch (const intel::security::metee_exception& ex) { std::cerr << ex.what() << std::endl; } while (retry--) { try { metee.connect(); break; } catch (const intel::security::metee_exception& ex) { if (ex.code().value() != TEE_BUSY && ex.code().value() != TEE_UNABLE_TO_COMPLETE_OPERATION) /* windows return this error on busy */ throw; std::cerr << "Client is busy, retrying" << std::endl; } std::this_thread::sleep_for(std::chrono::milliseconds(2000)); } if (metee.max_msg_len() == 0) { std::cerr << "Client reported zero MTU. Aborting." << std::endl; return 1; } struct mkhi_fwver_req req; uint8_t* u = reinterpret_cast<uint8_t*>(&req); /* Write */ req.header.data = 0; /* Reset */ req.header.GroupId = 0xFF; /* MKHI */ req.header.Command = 0x02; /* GET FW Version */ req.header.IsResponse = 0; req.header.Reserved = 0; size_t written = metee.write(std::vector<uint8_t>(u, u + sizeof req), MKHI_TIMEOUT); if (written != sizeof(req)) { std::cerr << "Write failed written " << written << std::endl; return 1; } std::vector<uint8_t> res = metee.read(MKHI_TIMEOUT); if (res.size() < sizeof(struct mkhi_msg_hdr)) { std::cerr << "Returned less than header = " << res.size() << std::endl; return 1; } if (res.size() < sizeof(struct mkhi_fwver_rsp)) { std::cerr << "Returned less than response = " << res.size() << std::endl; return 1; } struct mkhi_fwver_rsp* rsp; rsp = reinterpret_cast<struct mkhi_fwver_rsp*>(res.data()); if (rsp->header.Result) { std::cerr << "Result = " << rsp->header.Result << std::endl; return 1; } std::cout << "Version: " << rsp->version.code.major << "." << rsp->version.code.minor << "." << rsp->version.code.hotFix << "." << rsp->version.code.buildNo << std::endl; for (size_t i = 0; i < 6; i++) std::cout << "FW Status " << i + 1 << " : " << metee.fw_status(i) << std::endl; return 0; } catch (const intel::security::metee_exception& ex) { std::cerr << ex.what() << std::endl; return 1; } } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/����������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0015051�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/Windows/��������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0016503�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/Windows/LICENSE.WDK.Ms-LPL��������������������������������������������������0000664�0000000�0000000�00000005406�15201331742�0021144�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������MICROSOFT LIMITED PUBLIC LICENSE version 1.1 This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software. 1. Definitions The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. A "contribution" is the original software, or any additions or changes to the software. A "contributor" is any person that distributes its contribution under this license. "Licensed patents" are a contributor's patent claims that read directly on its contribution. 2. Grant of Rights (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 3. Conditions and Limitations (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. (F) Platform Limitation- The licenses granted in sections 2(A) & 2(B) extend only to the software or derivative works that you create that run on a Microsoft Windows operating system product.����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/Windows/metee.rc.in���������������������������������������������������������0000664�0000000�0000000�00000004502�15201331742�0020536�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024 Intel Corporation */ // Microsoft Visual C++ generated resource script. // #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include <Windows.h> ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // English (United States) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE BEGIN "resource.h\0" END 2 TEXTINCLUDE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION @TEE_VERSION_COMM@ PRODUCTVERSION @TEE_VERSION_COMM@ FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L #else FILEFLAGS 0x0L #endif FILEOS 0x40004L FILETYPE 0x2L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE "CompanyName", "Intel Corporation" VALUE "FileDescription", "Intel(R) CSME/GSC HECI Interface Library" VALUE "FileVersion", "@TEE_VERSION_STRING@" VALUE "InternalName", "MeTee" VALUE "LegalCopyright", "Copyright (C) 2014, Intel Corporation." VALUE "OriginalFilename", "metee.dll" VALUE "ProductName", "Intel(R) CSME/GSC HECI Interface Library" VALUE "ProductVersion", "@TEE_VERSION_STRING@" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END #endif // English (United States) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/Windows/metee_win.c���������������������������������������������������������0000664�0000000�0000000�00000046341�15201331742�0020633�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2025 Intel Corporation */ #include <windows.h> #include <initguid.h> #include <winioctl.h> #include <malloc.h> #include <limits.h> #include <setupapi.h> #include <devpkey.h> #include "public.h" #include "helpers.h" #include "metee.h" #include "metee_win.h" static TEESTATUS __CreateFile(PTEEHANDLE handle, const char *devicePath, PHANDLE deviceHandle) { TEESTATUS status; FUNC_ENTRY(handle); *deviceHandle = CreateFileA(devicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (*deviceHandle == INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); ERRPRINT(handle, "Error in CreateFile, error: %lu\n", err); switch (err) { case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: status = TEE_DEVICE_NOT_FOUND; break; case ERROR_ACCESS_DENIED: status = TEE_PERMISSION_DENIED; break; default: status = TEE_DEVICE_NOT_READY; break; } } else { status = TEE_SUCCESS; } FUNC_EXIT(handle, status); return status; } /********************************************************************** ** TEE Lib Function * **********************************************************************/ static TEESTATUS TeeInitFullInt(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN TeeLogCallback log_callback, TeeLogCallback2 log_callback2) { TEESTATUS status; errno_t res; char devicePath[MAX_PATH] = {0}; const char *devicePathP = NULL; HANDLE deviceHandle = INVALID_HANDLE_VALUE; struct METEE_WIN_IMPL* impl_handle = NULL; if (NULL == guid || NULL == handle) { return TEE_INVALID_PARAMETER; } __tee_init_handle(handle); handle->log_level = (log_level >= TEE_LOG_LEVEL_MAX) ? TEE_LOG_LEVEL_VERBOSE : log_level; handle->log_callback = log_callback; handle->log_callback2 = log_callback2; FUNC_ENTRY(handle); if (log_level >= TEE_LOG_LEVEL_MAX) { ERRPRINT(handle, "LogLevel %u is too big.\n", log_level); status = TEE_INVALID_PARAMETER; goto Cleanup; } switch (device.type) { case TEE_DEVICE_TYPE_NONE: if (device.data.path != NULL) { ERRPRINT(handle, "Path is not NULL.\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } status = GetDevicePath(handle, &GUID_DEVINTERFACE_HECI, devicePath, MAX_PATH); if (status) { ERRPRINT(handle, "Error in GetDevicePath, error: %d\n", status); goto Cleanup; } devicePathP = devicePath; break; case TEE_DEVICE_TYPE_PATH: if (device.data.path == NULL) { ERRPRINT(handle, "Path is NULL.\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } devicePathP = device.data.path; break; case TEE_DEVICE_TYPE_HANDLE: if (device.data.handle == TEE_INVALID_DEVICE_HANDLE) { ERRPRINT(handle, "Handle is invalid.\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } deviceHandle = device.data.handle; break; case TEE_DEVICE_TYPE_GUID: if (device.data.guid == NULL) { ERRPRINT(handle, "Device GUID is NULL.\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } status = GetDevicePath(handle, device.data.guid, devicePath, MAX_PATH); if (status) { ERRPRINT(handle, "Error in GetDevicePath, error: %d\n", status); goto Cleanup; } devicePathP = devicePath; break; default: ERRPRINT(handle, "Wrong device type %u.\n", device.type); status = TEE_INVALID_PARAMETER; goto Cleanup; break; } impl_handle = (struct METEE_WIN_IMPL*)malloc(sizeof(*impl_handle)); if (impl_handle == NULL) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "Can't allocate memory for internal struct\n"); goto Cleanup; } memset(impl_handle, 0, sizeof(*impl_handle)); switch (device.type) { case TEE_DEVICE_TYPE_NONE: case TEE_DEVICE_TYPE_PATH: case TEE_DEVICE_TYPE_GUID: status = __CreateFile(handle, devicePathP, &deviceHandle); if (status != TEE_SUCCESS) { goto Cleanup; } impl_handle->handle = deviceHandle; impl_handle->close_on_exit = true; impl_handle->device_path = _strdup(devicePathP); if (impl_handle->device_path == NULL) { ERRPRINT(handle, "Error in in device path copy\n"); status = TEE_UNABLE_TO_COMPLETE_OPERATION; goto Cleanup; } break; case TEE_DEVICE_TYPE_HANDLE: impl_handle->handle = deviceHandle; impl_handle->close_on_exit = false; impl_handle->device_path = NULL; break; default: break; } impl_handle->state = METEE_CLIENT_STATE_NONE; res = memcpy_s(&impl_handle->guid, sizeof(impl_handle->guid), guid, sizeof(GUID)); if (res != 0) { ERRPRINT(handle, "Error in in guid copy, res = %u\n", res); status = TEE_UNABLE_TO_COMPLETE_OPERATION; goto Cleanup; } // allocate overlapped struct for (size_t i = 0; i < MAX_EVT; i++) { impl_handle->evt[i] = (EVENTHANDLE)MALLOC(sizeof(OVERLAPPED)); if (NULL == impl_handle->evt[i]) { status = TEE_UNABLE_TO_COMPLETE_OPERATION; ERRPRINT(handle, "Error in MALLOC, error: %d\n", GetLastError()); goto Cleanup; } impl_handle->evt[i]->hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (NULL == impl_handle->evt[i]->hEvent) { status = TEE_UNABLE_TO_COMPLETE_OPERATION; ERRPRINT(handle, "Error in CreateEvent, error: %d\n", GetLastError()); goto Cleanup; } } handle->handle = impl_handle; status = TEE_SUCCESS; Cleanup: if (TEE_SUCCESS != status) { if (impl_handle) { for (size_t i = 0; i < MAX_EVT; i++) { if (impl_handle->evt[i]) { if (impl_handle->evt[i]->hEvent) CloseHandle(impl_handle->evt[i]->hEvent); FREE(impl_handle->evt[i]); } } free(impl_handle->device_path); free(impl_handle); } if (deviceHandle) CloseHandle(deviceHandle); if (handle) handle->handle = NULL; } FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback) { return TeeInitFullInt(handle, guid, device, log_level, log_callback, NULL); } TEESTATUS TEEAPI TeeInitFull2(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback2 log_callback) { return TeeInitFullInt(handle, guid, device, log_level, NULL, log_callback); } TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN OPTIONAL const char* device) { struct tee_device_address addr; addr.type = (device) ? TEE_DEVICE_TYPE_PATH : TEE_DEVICE_TYPE_NONE; addr.data.path = device; return TeeInitFull(handle, guid, addr, TEE_DEFAULT_LOG_LEVEL, NULL); } TEESTATUS TEEAPI TeeInitGUID(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN OPTIONAL const GUID* device) { struct tee_device_address addr; addr.type = (device) ? TEE_DEVICE_TYPE_GUID : TEE_DEVICE_TYPE_NONE; addr.data.guid = device; return TeeInitFull(handle, guid, addr, TEE_DEFAULT_LOG_LEVEL, NULL); } TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const TEE_DEVICE_HANDLE device_handle) { struct tee_device_address addr; addr.type = TEE_DEVICE_TYPE_HANDLE; addr.data.handle = device_handle; return TeeInitFull(handle, guid, addr, TEE_DEFAULT_LOG_LEVEL, NULL); } TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); TEESTATUS status; DWORD bytesReturned = 0; FW_CLIENT fwClient = {0}; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (impl_handle->state == METEE_CLIENT_STATE_CONNECTED) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "The client is already connected\n"); goto Cleanup; } if (impl_handle->state == METEE_CLIENT_STATE_FAILED && impl_handle->close_on_exit) { /* the handle have to be reopened in this case to reconnect to work */ CloseHandle(impl_handle->handle); impl_handle->handle = NULL; status = __CreateFile(handle, impl_handle->device_path, &impl_handle->handle); if (status != TEE_SUCCESS) { goto Cleanup; } } status = SendIOCTL(handle, impl_handle->evt[METEE_WIN_EVT_IOCTL], (DWORD)IOCTL_TEEDRIVER_CONNECT_CLIENT, (LPVOID)&impl_handle->guid, sizeof(GUID), &fwClient, sizeof(FW_CLIENT), &bytesReturned); if (status) { // Connect IOCTL returns invalid handle if client is not found if (status == TEE_INVALID_PARAMETER) status = TEE_CLIENT_NOT_FOUND; ERRPRINT(handle, "Error in SendIOCTL, status: %lu\n", status); goto Cleanup; } impl_handle->state = METEE_CLIENT_STATE_CONNECTED; handle->maxMsgLen = fwClient.MaxMessageLength; handle->protcolVer = fwClient.ProtocolVersion; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void* buffer, IN size_t bufferSize, OUT OPTIONAL size_t* pNumOfBytesRead, IN OPTIONAL uint32_t timeout) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); TEESTATUS status; DWORD bytesRead = 0; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle || NULL == buffer || 0 == bufferSize) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (timeout > INT_MAX) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "Timeout is too big %u > %d \n", timeout, INT_MAX); goto Cleanup; } if (impl_handle->state != METEE_CLIENT_STATE_CONNECTED) { status = TEE_DISCONNECTED; ERRPRINT(handle, "The client is not connected\n"); goto Cleanup; } status = BeginOverlappedInternal(ReadOperation, handle, buffer, bufferSize, impl_handle->evt[METEE_WIN_EVT_READ]); if (status) { ERRPRINT(handle, "Error in BeginOverlappedInternal, error: %d\n", status); impl_handle->state = METEE_CLIENT_STATE_FAILED; goto Cleanup; } if (timeout == 0) timeout = INFINITE; status = EndOverlapped(handle, impl_handle->evt[METEE_WIN_EVT_READ], timeout, &bytesRead); if (status) { ERRPRINT(handle, "Error in EndOverlapped, error: %d\n", status); impl_handle->state = METEE_CLIENT_STATE_FAILED; goto Cleanup; } if (pNumOfBytesRead != NULL) { *pNumOfBytesRead = bytesRead; } status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void* buffer, IN size_t bufferSize, OUT OPTIONAL size_t* numberOfBytesWritten, IN OPTIONAL uint32_t timeout) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); TEESTATUS status; DWORD bytesWritten = 0; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle || NULL == buffer || 0 == bufferSize) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (timeout > INT_MAX) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "Timeout is too big %u > %d \n", timeout, INT_MAX); goto Cleanup; } if (impl_handle->state != METEE_CLIENT_STATE_CONNECTED) { status = TEE_DISCONNECTED; ERRPRINT(handle, "The client is not connected\n"); goto Cleanup; } status = BeginOverlappedInternal(WriteOperation, handle, (PVOID)buffer, bufferSize, impl_handle->evt[METEE_WIN_EVT_WRITE]); if (status) { ERRPRINT(handle, "Error in BeginOverlappedInternal, error: %d\n", status); impl_handle->state = METEE_CLIENT_STATE_FAILED; goto Cleanup; } if (timeout == 0) timeout = INFINITE; status = EndOverlapped(handle, impl_handle->evt[METEE_WIN_EVT_WRITE], timeout, &bytesWritten); if (status) { ERRPRINT(handle, "Error in EndOverlapped, error: %d\n", status); impl_handle->state = METEE_CLIENT_STATE_FAILED; goto Cleanup; } if (numberOfBytesWritten != NULL) { *numberOfBytesWritten = bytesWritten; } status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle, IN uint32_t fwStatusNum, OUT uint32_t *fwStatus) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); TEESTATUS status; DWORD bytesReturned = 0; DWORD fwSts = 0; DWORD fwStsNum = fwStatusNum; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle || NULL == fwStatus) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (fwStatusNum > 5) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "fwStatusNum should be 0..5\n"); goto Cleanup; } status = SendIOCTL(handle, impl_handle->evt[METEE_WIN_EVT_IOCTL], (DWORD)IOCTL_TEEDRIVER_GET_FW_STS, &fwStsNum, sizeof(DWORD), &fwSts, sizeof(DWORD), &bytesReturned); if (status) { ERRPRINT(handle, "Error in SendIOCTL, status: %lu\n", status); impl_handle->state = METEE_CLIENT_STATE_FAILED; goto Cleanup; } *fwStatus = fwSts; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val) { struct METEE_WIN_IMPL* impl_handle = to_int(handle); TEESTATUS status; DWORD bytesReturned = 0; DWORD trc = 0; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!impl_handle || !trc_val) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } status = SendIOCTL(handle, impl_handle->evt[METEE_WIN_EVT_IOCTL], (DWORD)IOCTL_TEEDRIVER_GET_TRC, NULL, 0, &trc, sizeof(DWORD), &bytesReturned); if (status) { ERRPRINT(handle, "Error in SendIOCTL, status: %lu\n", status); impl_handle->state = METEE_CLIENT_STATE_FAILED; goto Cleanup; } *trc_val = trc; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } static void __TeeCancelIO(PTEEHANDLE handle) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); DWORD ret; if (CancelIoEx(impl_handle->handle, NULL)) { HANDLE handles[MAX_EVT]; for (size_t i = 0; i < MAX_EVT; i++) { handles[i] = impl_handle->evt[i]->hEvent; } ret = WaitForMultipleObjects(MAX_EVT, handles, TRUE, CANCEL_TIMEOUT); if (ret > (WAIT_OBJECT_0 + MAX_EVT - 1)) { ERRPRINT(handle, "Error in WaitForMultipleObjects, return: %lu, error: %lu\n", ret, GetLastError()); } } } void TEEAPI TeeCancelIO(IN PTEEHANDLE handle) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); FUNC_ENTRY(handle); if (NULL != impl_handle) { __TeeCancelIO(handle); } FUNC_EXIT(handle, TEE_SUCCESS); } VOID TEEAPI TeeDisconnect(IN PTEEHANDLE handle) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); if (NULL == handle) { return; } FUNC_ENTRY(handle); if (NULL == impl_handle) { goto Cleanup; } __TeeCancelIO(handle); for (size_t i = 0; i < MAX_EVT; i++) { if (impl_handle->evt[i]) { if (impl_handle->evt[i]->hEvent) CloseHandle(impl_handle->evt[i]->hEvent); FREE(impl_handle->evt[i]); } } if (impl_handle->close_on_exit) CloseHandle(impl_handle->handle); free(impl_handle->device_path); free(impl_handle); handle->handle = NULL; Cleanup: FUNC_EXIT(handle, TEE_SUCCESS); } TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); if (NULL == handle) { return TEE_INVALID_DEVICE_HANDLE; } FUNC_ENTRY(handle); if (NULL == impl_handle) { FUNC_EXIT(handle, TEE_INVALID_PARAMETER); return TEE_INVALID_DEVICE_HANDLE; } FUNC_EXIT(handle, TEE_SUCCESS); return impl_handle->handle; } #pragma pack(1) //HECI_VERSION_V3 struct HECI_VERSION { uint16_t major; uint16_t minor; uint16_t hotfix; uint16_t build; }; #pragma pack() TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion) { struct METEE_WIN_IMPL *impl_handle = to_int(handle); TEESTATUS status; DWORD bytesReturned = 0; struct HECI_VERSION ver; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle || NULL == driverVersion) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } status = SendIOCTL(handle, impl_handle->evt[METEE_WIN_EVT_IOCTL], (DWORD)IOCTL_TEEDRIVER_GET_VERSION, NULL, 0, &ver, sizeof(ver), &bytesReturned); if (status) { ERRPRINT(handle, "Error in SendIOCTL, status: %lu\n", status); impl_handle->state = METEE_CLIENT_STATE_FAILED; goto Cleanup; } driverVersion->major = ver.major; driverVersion->minor = ver.minor; driverVersion->hotfix = ver.hotfix; driverVersion->build = ver.build; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level) { uint32_t prev_log_level = TEE_DEFAULT_LOG_LEVEL; if (NULL == handle) { return prev_log_level; } FUNC_ENTRY(handle); prev_log_level = handle->log_level; handle->log_level = (log_level > TEE_LOG_LEVEL_VERBOSE) ? TEE_LOG_LEVEL_VERBOSE : log_level; FUNC_EXIT(handle, prev_log_level); return prev_log_level; } uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle) { uint32_t prev_log_level = TEE_DEFAULT_LOG_LEVEL; if (NULL == handle) { return prev_log_level; } FUNC_ENTRY(handle); prev_log_level = handle->log_level; FUNC_EXIT(handle, prev_log_level); return prev_log_level; } TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback) { struct METEE_WIN_IMPL* impl_handle = to_int(handle); TEESTATUS status; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (handle->log_callback2) { ERRPRINT(handle, "Standard callback already in use\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } handle->log_callback = log_callback; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeSetLogCallback2(IN const PTEEHANDLE handle, TeeLogCallback2 log_callback) { struct METEE_WIN_IMPL* impl_handle = to_int(handle); TEESTATUS status; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (handle->log_callback) { ERRPRINT(handle, "Legacy callback already in use\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } handle->log_callback2 = log_callback; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } uint32_t TEEAPI TeeGetMaxMsgLen(IN const PTEEHANDLE handle) { if (NULL == handle) { return 0; } return (uint32_t)handle->maxMsgLen; } uint8_t TEEAPI TeeGetProtocolVer(IN const PTEEHANDLE handle) { if (NULL == handle) { return 0; } return handle->protcolVer; } TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size_t *kindSize) { TEESTATUS status = TEE_INTERNAL_ERROR; if (NULL == handle) { return TEE_INVALID_PARAMETER; } struct METEE_WIN_IMPL* impl_handle = to_int(handle); FUNC_ENTRY(handle); if (NULL == impl_handle || NULL == kindSize) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } status = GetDeviceKind(handle, kind, kindSize); Cleanup: FUNC_EXIT(handle, status); return status; } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/Windows/metee_win.h���������������������������������������������������������0000664�0000000�0000000�00000004416�15201331742�0020635�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2026 Intel Corporation */ #ifndef __TEELIBWIN_H #define __TEELIBWIN_H #include <Windows.h> #include <stdbool.h> #include "metee.h" #define CANCEL_TIMEOUT 5000 enum METEE_CLIENT_STATE { METEE_CLIENT_STATE_NONE, METEE_CLIENT_STATE_CONNECTED, METEE_CLIENT_STATE_FAILED }; #define METEE_WIN_EVT_IOCTL 0 #define METEE_WIN_EVT_READ 1 #define METEE_WIN_EVT_WRITE 2 #define MAX_EVT 3 struct METEE_WIN_IMPL { HANDLE handle; /**< file descriptor - Handle to the Device File */ GUID guid; /**< fw client guid */ LPOVERLAPPED evt[MAX_EVT]; /**< event for executing async */ bool close_on_exit; /**< close handle on exit */ enum METEE_CLIENT_STATE state; /**< the client state */ char *device_path; /**< device path */ }; /********************************************************************* ** Windows Helper Types ** **********************************************************************/ typedef LPOVERLAPPED EVENTHANDLE, *PEVENTHANDLE; typedef enum _TEE_OPERATION { ReadOperation, WriteOperation } TEE_OPERATION; /********************************************************************* ** Windows Helper Functions ** **********************************************************************/ TEESTATUS BeginOverlappedInternal(IN TEE_OPERATION operation, IN PTEEHANDLE handle, IN PVOID buffer, IN size_t bufferSize, OUT EVENTHANDLE evt); TEESTATUS EndOverlapped(IN PTEEHANDLE handle, IN EVENTHANDLE evt, IN DWORD milliseconds, OUT OPTIONAL LPDWORD pNumberOfBytesTransferred); TEESTATUS GetDevicePath(IN PTEEHANDLE handle, IN LPCGUID InterfaceGuid, OUT char *path, IN SIZE_T pathSize); TEESTATUS GetDeviceKind(IN PTEEHANDLE handle, IN OUT OPTIONAL char *kind, IN OUT size_t *kindSize); TEESTATUS SendIOCTL(IN PTEEHANDLE handle, IN EVENTHANDLE evt, IN DWORD ioControlCode, IN LPVOID pInBuffer, IN DWORD inBufferSize, IN LPVOID pOutBuffer, IN DWORD outBufferSize, OUT LPDWORD pBytesRetuned); TEESTATUS Win32ErrorToTee(IN DWORD win32Error); static inline struct METEE_WIN_IMPL *to_int(PTEEHANDLE _h) { return _h ? (struct METEE_WIN_IMPL *)_h->handle : NULL; } #endif /* __TEELIBWIN_H */ ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/Windows/metee_winhelpers.c��������������������������������������������������0000664�0000000�0000000�00000027250�15201331742�0022214�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2026 Intel Corporation */ #include <windows.h> #include <initguid.h> #include "helpers.h" #include "metee.h" #include "metee_win.h" #include <cfgmgr32.h> #include <Objbase.h> #include <Devpkey.h> #include <Strsafe.h> /********************************************************************* ** Windows Helper Functions ** **********************************************************************/ void DebugPrintMe(const char* args, ...) { char msg[DEBUG_MSG_LEN + 1]; va_list varl; va_start(varl, args); vsprintf_s(msg, DEBUG_MSG_LEN, args, varl); va_end(varl); OutputDebugStringA(msg); } void CallbackPrintHelper(IN PTEEHANDLE handle, bool is_error, const char* args, ...) { char msg[DEBUG_MSG_LEN + 1]; va_list varl; va_start(varl, args); vsprintf_s(msg, DEBUG_MSG_LEN, args, varl); va_end(varl); handle->log_callback2(is_error, msg); } /* ** Start Overlapped Operation ** ** Parameters: ** ** Return: ** TEE_INVALID_PARAMETER ** TEE_INTERNAL_ERROR */ TEESTATUS BeginOverlappedInternal(IN TEE_OPERATION operation, IN PTEEHANDLE handle, IN PVOID buffer, IN size_t bufferSize, OUT EVENTHANDLE evt) { TEESTATUS status; DWORD bytesTransferred= 0; BOOLEAN optSuccesed = FALSE; struct METEE_WIN_IMPL *impl_handle = to_int(handle); FUNC_ENTRY(handle); if (INVALID_HANDLE_VALUE == impl_handle->handle || NULL == buffer || 0 == bufferSize || NULL == evt) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (bufferSize > MAXDWORD) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "Buffer size is too big: %zu\n", bufferSize); goto Cleanup; } if (operation == ReadOperation) { if (ReadFile(impl_handle->handle, buffer, (DWORD)bufferSize, &bytesTransferred, evt)) { optSuccesed = TRUE; } } else if (operation == WriteOperation) { if (WriteFile(impl_handle->handle, buffer, (DWORD)bufferSize, &bytesTransferred, evt)) { optSuccesed = TRUE; } } if (optSuccesed == FALSE) { DWORD err = GetLastError(); if (ERROR_IO_PENDING != err) { status = Win32ErrorToTee(err); ERRPRINT(handle, "Error in ReadFile/Write, error: %d\n", err); } else { DBGPRINT(handle, "Pending in ReadFile/Write\n"); status = TEE_SUCCESS; } } else { status = TEE_SUCCESS; } Cleanup: FUNC_EXIT(handle, status); return status; } TEESTATUS EndOverlapped(IN PTEEHANDLE handle, IN EVENTHANDLE evt, IN DWORD milliseconds, OUT OPTIONAL LPDWORD pNumberOfBytesTransferred) { TEESTATUS status; DWORD err; DWORD bytesTransferred = 0; LPDWORD pBytesTransferred = NULL; struct METEE_WIN_IMPL *impl_handle = to_int(handle); FUNC_ENTRY(handle); if (INVALID_HANDLE_VALUE == impl_handle->handle || NULL == evt) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } pBytesTransferred = pNumberOfBytesTransferred ? pNumberOfBytesTransferred : &bytesTransferred; // wait for the answer err = WaitForSingleObject(evt->hEvent, milliseconds); if (err == WAIT_TIMEOUT) { status = TEE_TIMEOUT; ERRPRINT(handle, "WaitForSingleObject timed out!\n"); goto Cleanup; } if (err != WAIT_OBJECT_0) { err = GetLastError(); status = Win32ErrorToTee(err); ERRPRINT(handle, "WaitForSingleObject reported error: %d\n", err); goto Cleanup; } // last parameter is true b/c if we're here the operation has been completed) if (!GetOverlappedResult(impl_handle->handle, evt, pBytesTransferred, TRUE)) { err = GetLastError(); status = Win32ErrorToTee(err); ERRPRINT(handle, "Error in GetOverlappedResult, error: %d\n", err); goto Cleanup; } status = TEE_SUCCESS; //not really needed, but for completeness... Cleanup: FUNC_EXIT(handle, status); return status; } /* ** Return the given Device Path according to it's device GUID ** ** Parameters: ** handle - metee handle ** InterfaceGuid - Device GUID ** path - Device path buffer ** pathSize - Device Path buffer size ** ** Return: ** TEE_DEVICE_NOT_FOUND ** TEE_INVALID_PARAMETER ** TEE_INTERNAL_ERROR */ TEESTATUS GetDevicePath(IN PTEEHANDLE handle, IN LPCGUID InterfaceGuid, OUT char *path, IN SIZE_T pathSize) { CONFIGRET cr; char *deviceInterfaceList = NULL; ULONG deviceInterfaceListLength = 0; HRESULT hr = E_FAIL; TEESTATUS status = TEE_INTERNAL_ERROR; FUNC_ENTRY(handle); if (InterfaceGuid == NULL || path == NULL || pathSize < 1) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } path[0] = 0x00; cr = CM_Get_Device_Interface_List_SizeA( &deviceInterfaceListLength, (LPGUID)InterfaceGuid, NULL, CM_GET_DEVICE_INTERFACE_LIST_PRESENT); if (cr != CR_SUCCESS) { ERRPRINT(handle, "Error 0x%x retrieving device interface list size.\n", cr); status = TEE_INTERNAL_ERROR; goto Cleanup; } if (deviceInterfaceListLength <= 1) { status = TEE_DEVICE_NOT_FOUND; ERRPRINT(handle, "SetupDiGetClassDevs returned status %d\n", GetLastError()); goto Cleanup; } deviceInterfaceList = (char*)malloc(deviceInterfaceListLength * sizeof(char)); if (deviceInterfaceList == NULL) { ERRPRINT(handle, "Error allocating memory for device interface list.\n"); status = TEE_INTERNAL_ERROR; goto Cleanup; } ZeroMemory(deviceInterfaceList, deviceInterfaceListLength * sizeof(char)); cr = CM_Get_Device_Interface_ListA( (LPGUID)InterfaceGuid, NULL, deviceInterfaceList, deviceInterfaceListLength, CM_GET_DEVICE_INTERFACE_LIST_PRESENT); if (cr != CR_SUCCESS) { ERRPRINT(handle, "Error 0x%x retrieving device interface list.\n", cr); status = TEE_INTERNAL_ERROR; goto Cleanup; } hr = StringCchCopyA(path, pathSize, deviceInterfaceList); if (FAILED(hr)) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "Error: StringCchCopy failed with HRESULT 0x%x\n", hr); goto Cleanup; } status = TEE_SUCCESS; Cleanup: if (deviceInterfaceList != NULL) { free(deviceInterfaceList); } FUNC_EXIT(handle, status); return status; } DEFINE_DEVPROPKEY(DEVPKEY_TeedriverKindString, 0x3279649a, 0x75b8, 0x4663, 0xab, 0x4f, 0x9d, 0xec, 0x58, 0xc5, 0x58, 0xf5, DEVPROP_TYPE_STRING); /* ** Get device kind implementation ** ** Parameters: ** handle - metee handle ** kind - pointer to hold device kind, null terminated C string ** kindSize - size in bytes allocated to kind including null terminator ** ** Return: ** TEE_SUCCESS ** TEE_INVALID_PARAMETER ** TEE_INTERNAL_ERROR */ TEESTATUS GetDeviceKind(IN PTEEHANDLE handle, IN OUT OPTIONAL char *kind, IN OUT size_t *kindSize) { CONFIGRET cr; DEVPROPTYPE prop_type = 0; ULONG prop_size = 0; DEVINST devInstHandle; WCHAR instance_id[MAX_PATH] = { 0 }; WCHAR* device_path_w = NULL; WCHAR* kind_w = NULL; size_t converted_chars; errno_t err; TEESTATUS status = TEE_INTERNAL_ERROR; if (NULL == handle) { return TEE_INVALID_PARAMETER; } struct METEE_WIN_IMPL* impl_handle = to_int(handle); FUNC_ENTRY(handle); size_t device_path_len = strlen(impl_handle->device_path) + 1; size_t device_path_size = device_path_len * sizeof(WCHAR); device_path_w = (WCHAR*)malloc(device_path_size); if (NULL == device_path_w) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "Error allocating memory for device path.\n"); goto Cleanup; } converted_chars = 0; mbstowcs_s(&converted_chars, device_path_w, device_path_len, impl_handle->device_path, _TRUNCATE); if (converted_chars != device_path_len) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "Error converting device path to wide.\n"); goto Cleanup; } prop_size = MAX_PATH; cr = CM_Get_Device_Interface_PropertyW(device_path_w, &DEVPKEY_Device_InstanceId, &prop_type, (PBYTE)instance_id, &prop_size, 0); if (cr != CR_SUCCESS) { ERRPRINT(handle, "CM_Get_Device_Interface_Property: %d\n", cr); status = TEE_INTERNAL_ERROR; goto Cleanup; } if (DEVPROP_TYPE_STRING != prop_type) { ERRPRINT(handle, "Invalid property type %d\n", prop_type); status = TEE_INTERNAL_ERROR; goto Cleanup; } cr = CM_Locate_DevNodeW(&devInstHandle, &instance_id[0], CM_LOCATE_DEVNODE_NORMAL); if (cr != CR_SUCCESS) { ERRPRINT(handle, "CM_Locate_DevNode: %d\n", cr); status = TEE_INTERNAL_ERROR; goto Cleanup; } prop_size = 0; cr = CM_Get_DevNode_PropertyW(devInstHandle, &DEVPKEY_TeedriverKindString, &prop_type, NULL, &prop_size, 0); if (cr == CR_NO_SUCH_VALUE) { DBGPRINT(handle, "CM_Get_DevNode_Property: kind not found\n"); status = TEE_NOTSUPPORTED; goto Cleanup; } if (cr != CR_BUFFER_SMALL) { ERRPRINT(handle, "CM_Get_DevNode_Property: %d %d\n", cr, prop_size); status = TEE_INTERNAL_ERROR; goto Cleanup; } kind_w = (WCHAR*)malloc(prop_size); if (NULL == kind_w) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "Error allocating memory for driver kind wide.\n"); goto Cleanup; } cr = CM_Get_DevNode_PropertyW(devInstHandle, &DEVPKEY_TeedriverKindString, &prop_type, (PBYTE)kind_w, &prop_size, 0); if (cr != CR_SUCCESS) { ERRPRINT(handle, "CM_Get_DevNode_Property: %d %d\n", cr, prop_size); status = TEE_INTERNAL_ERROR; goto Cleanup; } if (*kindSize < prop_size) { ERRPRINT(handle, "Insufficient buffer %d %d\n", *kindSize, prop_size); *kindSize = prop_size; status = TEE_INSUFFICIENT_BUFFER; goto Cleanup; } /* safe implementation of the conversion function handles NULL input/output buffer values and output buffer overrun */ err = wcstombs_s(&converted_chars, kind, *kindSize, kind_w, _TRUNCATE); if (err != 0) { ERRPRINT(handle, "convert to multi-byte error %d\n", err); if (err == STRUNCATE || err == EINVAL) { *kindSize = prop_size; status = TEE_INSUFFICIENT_BUFFER; } else { status = TEE_INTERNAL_ERROR; } goto Cleanup; } *kindSize = converted_chars; status = TEE_SUCCESS; Cleanup: free(kind_w); free(device_path_w); FUNC_EXIT(handle, status); return status; } TEESTATUS SendIOCTL(IN PTEEHANDLE handle, IN EVENTHANDLE evt, IN DWORD ioControlCode, IN LPVOID pInBuffer, IN DWORD inBufferSize, IN LPVOID pOutBuffer, IN DWORD outBufferSize, OUT LPDWORD pBytesRetuned) { TEESTATUS status; DWORD err; struct METEE_WIN_IMPL *impl_handle = to_int(handle); FUNC_ENTRY(handle); if (INVALID_HANDLE_VALUE == impl_handle->handle || NULL == pBytesRetuned) { status = ERROR_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (!DeviceIoControl(impl_handle->handle, ioControlCode, pInBuffer, inBufferSize, pOutBuffer, outBufferSize, pBytesRetuned, evt)) { err = GetLastError(); // it's ok to get an error here, because it's overlapped if (ERROR_IO_PENDING != err) { ERRPRINT(handle, "Error in DeviceIoControl, error: %d\n", err); status = Win32ErrorToTee(err); goto Cleanup; } } if (!GetOverlappedResult(impl_handle->handle, evt, pBytesRetuned, TRUE)) { err = GetLastError(); ERRPRINT(handle, "Error in GetOverlappedResult, error: %d\n", err); status = Win32ErrorToTee(err); goto Cleanup; } status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } TEESTATUS Win32ErrorToTee(IN DWORD win32Error) { switch (win32Error) { case ERROR_INVALID_HANDLE: return TEE_INVALID_PARAMETER; case ERROR_INSUFFICIENT_BUFFER: return TEE_INSUFFICIENT_BUFFER; case ERROR_GEN_FAILURE: return TEE_UNABLE_TO_COMPLETE_OPERATION; case ERROR_DEVICE_NOT_CONNECTED: return TEE_DEVICE_NOT_READY; case ERROR_NOT_FOUND: return TEE_CLIENT_NOT_FOUND; case ERROR_ACCESS_DENIED: return TEE_PERMISSION_DENIED; case ERROR_OPERATION_ABORTED: return TEE_UNABLE_TO_COMPLETE_OPERATION; default: return TEE_INTERNAL_ERROR; } } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/Windows/public.h������������������������������������������������������������0000664�0000000�0000000�00000002475�15201331742�0020142�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2023 Intel Corporation */ /*++ Module Name: public.h Abstract: This module contains the common declarations shared by driver and user applications. Environment: user and kernel --*/ #ifndef __PUBLIC_H #define __PUBLIC_H // // Define an Interface Guid so that app can find the device and talk to it. // DEFINE_GUID(GUID_DEVINTERFACE_HECI, 0xE2D1FF34, 0x3458, 0x49A9, 0x88, 0xDA, 0x8E, 0x69, 0x15, 0xCE, 0x9B, 0xE5); // {1b6cc5ff-1bba-4a0d-9899-13427aa05156} #define FILE_DEVICE_HECI 0x8000 // Define Interface reference/dereference routines for // Interfaces exported by IRP_MN_QUERY_INTERFACE #define IOCTL_TEEDRIVER_GET_VERSION \ CTL_CODE(FILE_DEVICE_HECI, 0x800, METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS) #define IOCTL_TEEDRIVER_CONNECT_CLIENT \ CTL_CODE(FILE_DEVICE_HECI, 0x801, METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS) #define IOCTL_TEEDRIVER_GET_FW_STS \ CTL_CODE(FILE_DEVICE_HECI, 0x803, METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS) #define IOCTL_TEEDRIVER_GET_TRC \ CTL_CODE(FILE_DEVICE_HECI, 0x813, METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS) #pragma pack(1) typedef struct _FW_CLIENT { UINT32 MaxMessageLength; UINT8 ProtocolVersion; } FW_CLIENT; #pragma pack( ) #endif ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/linux/����������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0016210�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/linux/LICENSE.libmei��������������������������������������������������������0000664�0000000�0000000�00000003333�15201331742�0020457�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/****************************************************************************** * This source is provided under BSD license. * * BSD LICENSE * * Copyright(c) 2013 - 2019 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name Intel Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/linux/include/��������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0017633�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/linux/include/linux/��������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0020772�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/linux/include/linux/mei.h���������������������������������������������������0000664�0000000�0000000�00000006622�15201331742�0021723�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ /* * Copyright(c) 2003-2015 Intel Corporation. All rights reserved. * Intel Management Engine Interface (Intel MEI) Linux driver * Intel MEI Interface Header */ #ifndef _LINUX_MEI_H #define _LINUX_MEI_H #include <linux/uuid.h> /* * This IOCTL is used to associate the current file descriptor with a * FW Client (given by UUID). This opens a communication channel * between a host client and a FW client. From this point every read and write * will communicate with the associated FW client. * Only in close() (file_operation release()) the communication between * the clients is disconnected * * The IOCTL argument is a struct with a union that contains * the input parameter and the output parameter for this IOCTL. * * The input parameter is UUID of the FW Client. * The output parameter is the properties of the FW client * (FW protocol version and max message size). * */ #define IOCTL_MEI_CONNECT_CLIENT \ _IOWR('H', 0x01, struct mei_connect_client_data) /* * Intel MEI client information struct */ struct mei_client { __u32 max_msg_length; __u8 protocol_version; __u8 reserved[3]; }; /* * IOCTL Connect Client Data structure */ struct mei_connect_client_data { union { uuid_le in_client_uuid; struct mei_client out_client_properties; }; }; /** * DOC: set and unset event notification for a connected client * * The IOCTL argument is 1 for enabling event notification and 0 for * disabling the service * Return: -EOPNOTSUPP if the devices doesn't support the feature */ #define IOCTL_MEI_NOTIFY_SET _IOW('H', 0x02, __u32) /** * DOC: retrieve notification * * The IOCTL output argument is 1 if an event was is pending and 0 otherwise * the ioctl has to be called in order to acknowledge pending event * * Return: -EOPNOTSUPP if the devices doesn't support the feature */ #define IOCTL_MEI_NOTIFY_GET _IOR('H', 0x03, __u32) /** * struct mei_connect_client_vtag - mei client information struct with vtag * * @in_client_uuid: UUID of client to connect * @vtag: virtual tag * @reserved: reserved for future use */ struct mei_connect_client_vtag { uuid_le in_client_uuid; __u8 vtag; __u8 reserved[3]; }; /** * struct mei_connect_client_data_vtag - IOCTL connect data union * * @connect: input connect data * @out_client_properties: output client data */ struct mei_connect_client_data_vtag { union { struct mei_connect_client_vtag connect; struct mei_client out_client_properties; }; }; /** * DOC: * This IOCTL is used to associate the current file descriptor with a * FW Client (given by UUID), and virtual tag (vtag). * The IOCTL opens a communication channel between a host client and * a FW client on a tagged channel. From this point on, every read * and write will communicate with the associated FW client with * on the tagged channel. * Upone close() the communication is terminated. * * The IOCTL argument is a struct with a union that contains * the input parameter and the output parameter for this IOCTL. * * The input parameter is UUID of the FW Client, a vtag [0,255] * The output parameter is the properties of the FW client * (FW protocool version and max message size). * * Clients that do not support tagged connection * will respond with -EOPNOTSUPP. */ #define IOCTL_MEI_CONNECT_CLIENT_VTAG \ _IOWR('H', 0x04, struct mei_connect_client_data_vtag) #endif /* _LINUX_MEI_H */ ��������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/linux/libmei.h��������������������������������������������������������������0000664�0000000�0000000�00000026362�15201331742�0017633�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright(c) 2013 - 2025 Intel Corporation. All rights reserved. * * Intel Management Engine Interface (Intel MEI) Library */ /*! \file libmei.h * \brief mei library API */ #ifndef __LIBMEI_H__ #define __LIBMEI_H__ #include <linux/uuid.h> #include <linux/mei.h> #include <stdbool.h> #include <stdint.h> #include <unistd.h> #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /*! Library API version encode helper */ #define MEI_ENCODE_VERSION(major, minor) ((major) << 16 | (minor) << 8) /*! Library API version */ #define LIBMEI_API_VERSION MEI_ENCODE_VERSION(1, 6) /*! Get current supported library API version * * \return version value */ unsigned int mei_get_api_version(void); /*! ME client connection state */ enum mei_cl_state { MEI_CL_STATE_ZERO = 0, /**< reserved */ MEI_CL_STATE_INTIALIZED = 1, /**< client is initialized (typo) */ MEI_CL_STATE_INITIALIZED = 1, /**< client is initialized */ MEI_CL_STATE_CONNECTED, /**< client is connected */ MEI_CL_STATE_DISCONNECTED, /**< client is disconnected */ MEI_CL_STATE_NOT_PRESENT, /**< client with GUID is not present in the system */ MEI_CL_STATE_VERSION_MISMATCH, /**< client version not supported */ MEI_CL_STATE_ERROR, /**< client is in error state */ MEI_CL_STATE_DISABLED, /**< client is in disabled state */ }; /*! log level */ enum mei_log_level { MEI_LOG_LEVEL_QUIET = 0, /**< no log prints */ MEI_LOG_LEVEL_ERROR = 1, /**< error log prints */ MEI_LOG_LEVEL_VERBOSE = 2 /**< verbose log prints */ }; /*! log callback function format * @deprecated Since version 1.7.0 */ typedef void(*mei_log_callback)(bool is_error, const char* fmt, ...); /*! log callback function format */ typedef void(*mei_log_callback2)(bool is_error, const char* msg); /*! Structure to store connection data */ struct mei { uuid_le guid; /**< client UUID */ unsigned int buf_size; /**< maximum buffer size supported by client*/ unsigned char prot_ver; /**< protocol version */ int fd; /**< connection file descriptor */ int state; /**< client connection state */ int last_err; /**< saved errno */ bool notify_en; /**< notification is enabled */ enum mei_log_level log_level; /**< libmei log level */ bool close_on_exit; /**< close handle on deinit */ char *device; /**< device name */ uint8_t vtag; /**< vtag used in communication */ mei_log_callback log_callback; /**< Deprecated Log callback */ mei_log_callback2 log_callback2; /**< Log callback */ }; /*! Default name of mei device */ #define MEI_DEFAULT_DEVICE_NAME "mei0" /*! Default path to mei device */ #define MEI_DEFAULT_DEVICE_PREFIX "/dev/" #define MEI_DEFAULT_DEVICE (MEI_DEFAULT_DEVICE_PREFIX MEI_DEFAULT_DEVICE_NAME) /*! Allocate and initialize me handle structure * * \param device device path, set MEI_DEFAULT_DEVICE to use default * \param guid UUID/GUID of associated mei client * \param req_protocol_version minimal required protocol version, 0 for any * \param verbose print verbose output to console * \return me handle to the mei device. All subsequent calls to the lib's functions * must be with this handle. NULL on failure. */ struct mei *mei_alloc(const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose); /*! Allocate and initialize me handle structure * * \param fd open file descriptor of MEI device * \param guid UUID/GUID of associated mei client * \param req_protocol_version minimal required protocol version, 0 for any * \param verbose print verbose output to console * \return me handle to the mei device. All subsequent calls to the lib's functions * must be with this handle. NULL on failure. */ struct mei *mei_alloc_fd(int fd, const uuid_le *guid, unsigned char req_protocol_version, bool verbose); /*! Free me handle structure * * \param me The mei handle */ void mei_free(struct mei *me); /*! Initializes a mei connection * * \param me A handle to the mei device. All subsequent calls to the lib's functions * must be with this handle * \param device device path, set MEI_DEFAULT_DEVICE to use default * \param guid UUID/GUID of associated mei client * \param req_protocol_version minimal required protocol version, 0 for any * \param verbose print verbose output to a console * \return 0 if successful, otherwise error code */ int mei_init(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose); /*! Initializes a mei connection with log callback * * @deprecated Since version 1.7.0 * \param me A handle to the mei device. All subsequent calls to the lib's functions * must be with this handle * \param device device path, set MEI_DEFAULT_DEVICE to use default * \param guid GUID of associated mei client * \param req_protocol_version minimal required protocol version, 0 for any * \param verbose print verbose output to a console * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code */ int mei_init_with_log(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose, mei_log_callback log_callback); /*! Initializes a mei connection with log callback * * \param me A handle to the mei device. All subsequent calls to the lib's functions * must be with this handle * \param device device path, set MEI_DEFAULT_DEVICE to use default * \param guid GUID of associated mei client * \param req_protocol_version minimal required protocol version, 0 for any * \param verbose print verbose output to a console * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code */ int mei_init_with_log2(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose, mei_log_callback2 log_callback); /*! Initializes a mei connection * * \param me A handle to the mei device. All subsequent calls to the lib's functions * must be with this handle * \param fd open file descriptor of MEI device * \param guid UUID/GUID of associated mei client * \param req_protocol_version minimal required protocol version, 0 for any * \param verbose print verbose output to a console * \return 0 if successful, otherwise error code */ int mei_init_fd(struct mei *me, int fd, const uuid_le *guid, unsigned char req_protocol_version, bool verbose); /*! Closes the session to me driver * Make sure that you call this function as soon as you are done with the device, * as other clients might be blocked until the session is closed. * * \param me The mei handle */ void mei_deinit(struct mei *me); /*! Open mei device and starts a session with a mei client * If the application requested specific minimal protocol version * and the client does not support that version than * the handle state will be set to MEI_CL_STATE_VERSION_MISMATCH * but connection will be established * * \param me The mei handle * \return 0 if successful, otherwise error code */ int mei_connect(struct mei *me); /*! Open mei device and starts a session with a mei client * Provide given vtag as session parameter. * If the application requested specific minimal protocol version * and the client does not support that version than * the handle state will be set to MEI_CL_STATE_VERSION_MISMATCH * but connection will be established * * \param me The mei handle * \param vtag The vtag value * \return 0 if successful, otherwise error code */ int mei_connect_vtag(struct mei *me, uint8_t vtag); /*! Setup mei connection to non block * * \param me The mei handle * \return 0 if successful, otherwise error code */ int mei_set_nonblock(struct mei *me); /*! return file descriptor to opened handle * * \param me The mei handle * \return file descriptor or error */ int mei_get_fd(struct mei *me); /*! Read data from the mei device. * * \param me The mei handle * \param buffer A pointer to a buffer that receives the data read from the mei device. * \param len The number of bytes to be read. * \return number of byte read if successful, otherwise error code */ ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer, size_t len); /*! Writes the specified buffer to the mei device. * * \param me The mei handle * \param buffer A pointer to the buffer containing the data to be written to the mei device. * \param len The number of bytes to be written. * \return number of bytes written if successful, otherwise error code */ ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer, size_t len); /*! Request to Enable or Disable Event Notification * * \param me The mei handle * \param enable A boolean to enable or disable event notification * \return 0 if successful, otherwise error code */ int mei_notification_request(struct mei *me, bool enable); /*! Acknowledge an event and enable further notification * notification events are signaled as priority events (POLLPRI) on select/poll * * \param me The mei handle * \return 0 if successful, otherwise error code. -ENOTSUPP is returned * in case the event notification was not enabled */ int mei_notification_get(struct mei *me); /*! Obtains FW status of device * * \param me The mei handle * \param fwsts_num The FW status register number (0-5). * \param fwsts FW status to fill * \return 0 if successful, otherwise error code */ int mei_fwstatus(struct mei *me, uint32_t fwsts_num, uint32_t *fwsts); /*! Obtains TRC status of device * * \param me The mei handle * \param trc_val TRC value fill * \return 0 if successful, otherwise error code */ int mei_gettrc(struct mei *me, uint32_t *trc_val); /*! Obtains device kind * * \param me The mei handle * \param kind buffer to fill with device kind null terminated string, may be NULL. * \param kind_size Pointer to kind buffer size in bytes, updated to number of bytes filled in buffer, including null character, on out. * If buffer is NULL, required size is returned anyway. * \return 0 if successful, otherwise error code */ int mei_getkind(struct mei *me, char *kind, size_t *kind_size); /*! Set log level * * \param me The mei handle * \param log_level log level to set * \return previous log level */ uint32_t mei_set_log_level(struct mei *me, uint32_t log_level); /*! Retrieve current log level * * \param me The mei handle * \return current log level */ uint32_t mei_get_log_level(const struct mei *me); /*! Set log callback * * @deprecated Since version 1.7.0 * \param me The mei handle * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code. */ int mei_set_log_callback(struct mei *me, mei_log_callback log_callback); /*! Set log callback * * \param me The mei handle * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code. */ int mei_set_log_callback2(struct mei *me, mei_log_callback2 log_callback); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __LIBMEI_H__ */ ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/linux/mei.c�����������������������������������������������������������������0000664�0000000�0000000�00000046453�15201331742�0017142�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright(c) 2013 - 2026 Intel Corporation. All rights reserved. * * Intel Management Engine Interface (Intel MEI) Library */ #include <errno.h> #include <fcntl.h> #include <linux/limits.h> #include <linux/mei.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <unistd.h> #include <stdarg.h> #include "libmei.h" /***************************************************************************** * Intel Management Engine Interface *****************************************************************************/ #ifdef SYSLOG #ifdef ANDROID #define LOG_TAG "libmei" #include <android/log_macros.h> #define __mei_msg(fmt, ...) ALOGV(fmt, ##__VA_ARGS__) #define __mei_err(fmt, ...) ALOGE(fmt, ##__VA_ARGS__) #else /* ANDROID */ #include <syslog.h> #define __mei_msg(fmt, ...) syslog(LOG_DEBUG, fmt, ##__VA_ARGS__) #define __mei_err(fmt, ...) syslog(LOG_ERR, fmt, ##__VA_ARGS__) #endif /* ANDROID */ #else #include <stdlib.h> #define __mei_msg(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__) #define __mei_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) #endif /* SYSLOG */ #define LEGACY_CALLBACK_SET(h) ((h)->log_callback ? 1 : 0) #define STANDARD_CALLBACK_SET(h) ((h)->log_callback2 ? 1 : 0) #define mei_msg(_me, fmt, ARGS...) do { \ if ((_me)->log_level >= MEI_LOG_LEVEL_VERBOSE) { \ if (LEGACY_CALLBACK_SET(_me)) \ (_me)->log_callback(false, fmt, ##ARGS); \ else if (STANDARD_CALLBACK_SET(_me)) \ callback_print_helper((_me), false, fmt, ##ARGS); \ else \ __mei_msg(fmt, ##ARGS); \ } \ } while (0) #define mei_err(_me, fmt, ARGS...) do { \ if ((_me)->log_level > MEI_LOG_LEVEL_QUIET) { \ if (LEGACY_CALLBACK_SET(_me)) \ (_me)->log_callback(true, "me: error: " fmt, ##ARGS); \ else if (STANDARD_CALLBACK_SET(_me)) \ callback_print_helper((_me), true, fmt, ##ARGS); \ else \ __mei_err("me: error: " fmt, ##ARGS); \ } \ } while (0) #ifdef DEBUG static inline void __dump_buffer(const char *buf) { __mei_msg("%s\n", buf); } static void dump_hex_buffer(const unsigned char *buf, size_t len) { #define LINE_LEN 16 #define PBUFSZ (sizeof("00") * LINE_LEN) char pbuf[PBUFSZ]; pbuf[0] = '\0'; for (size_t j = 0; (j < PBUFSZ) && (len > 0); len--, j += sizeof("00")) snprintf(&pbuf[j], PBUFSZ - j, "%02X ", *buf++); __dump_buffer(pbuf); #undef PBUFSZ #undef LINE_LEN } static void mei_dump_hex_buffer(struct mei *me, const unsigned char *buf, size_t len) { if (me->log_level < MEI_LOG_LEVEL_VERBOSE) return; dump_hex_buffer(buf, len); } #else /* DEBUG */ static void mei_dump_hex_buffer(struct mei *me, const unsigned char *buf, size_t len) { (void)(me); (void)(buf); (void)(len); } #endif /* DEBUG */ static void callback_print_helper(struct mei *me, bool is_error, const char* args, ...) { #define DEBUG_MSG_LEN 1024 char msg[DEBUG_MSG_LEN + 1]; va_list varl; va_start(varl, args); vsnprintf(msg, DEBUG_MSG_LEN, args, varl); va_end(varl); me->log_callback2(is_error, msg); } void mei_deinit(struct mei *me) { if (!me) return; if (me->close_on_exit && me->fd != -1) close(me->fd); me->fd = -1; me->buf_size = 0; me->prot_ver = 0; me->state = MEI_CL_STATE_ZERO; me->last_err = 0; free(me->device); me->device = NULL; } static inline int __mei_errno_to_state(struct mei *me) { switch (me->last_err) { case 0: return me->state; case ENOTTY: return MEI_CL_STATE_NOT_PRESENT; case EBUSY: /* fall through */ case ENODEV: return MEI_CL_STATE_DISCONNECTED; case EOPNOTSUPP: return me->state; default: return MEI_CL_STATE_ERROR; } } int mei_get_fd(struct mei *me) { if (!me) return -EINVAL; return me->fd; } static int __mei_set_nonblock(struct mei *me) { int flags; int rc; errno = 0; flags = fcntl(me->fd, F_GETFL, 0); if (flags == -1) { me->last_err = errno; return -me->last_err; } errno = 0; rc = fcntl(me->fd, F_SETFL, flags | O_NONBLOCK); if (rc < 0) { me->last_err = errno; return -me->last_err; } return 0; } static inline int __mei_open(struct mei *me, const char *devname) { errno = 0; me->fd = open(devname, O_RDWR | O_CLOEXEC); me->last_err = errno; return me->fd == -1 ? -me->last_err : me->fd; } static inline int __mei_connect(struct mei *me, struct mei_connect_client_data *d) { int rc; errno = 0; rc = ioctl(me->fd, IOCTL_MEI_CONNECT_CLIENT, d); me->last_err = errno; return rc == -1 ? -me->last_err : 0; } static inline int __mei_connect_vtag(struct mei *me, struct mei_connect_client_data_vtag *d) { int rc; errno = 0; rc = ioctl(me->fd, IOCTL_MEI_CONNECT_CLIENT_VTAG, d); me->last_err = errno; return rc == -1 ? -me->last_err : 0; } static inline int __mei_notify_set(struct mei *me, uint32_t *enable) { int rc; errno = 0; rc = ioctl(me->fd, IOCTL_MEI_NOTIFY_SET, enable); me->last_err = errno; return rc == -1 ? -me->last_err : 0; } static inline int __mei_notify_get(struct mei *me) { uint32_t notification; int rc; errno = 0; rc = ioctl(me->fd, IOCTL_MEI_NOTIFY_GET, ¬ification); me->last_err = errno; return rc == -1 ? -me->last_err : 0; } static inline ssize_t __mei_read(struct mei *me, unsigned char *buf, size_t len) { ssize_t rc; errno = 0; rc = read(me->fd, buf, len); me->last_err = errno; return rc <= 0 ? -me->last_err : rc; } static inline ssize_t __mei_write(struct mei *me, const unsigned char *buf, size_t len) { ssize_t rc; errno = 0; rc = write(me->fd, buf, len); me->last_err = errno; return rc <= 0 ? -me->last_err : rc; } static inline int __mei_fwsts(struct mei *me, const char *device, uint32_t fwsts_num, uint32_t *fwsts) { #define FWSTS_FILENAME_LEN 33 #define FWSTS_LEN 9 #define CONV_BASE 16 char path[FWSTS_FILENAME_LEN]; int fd; char line[FWSTS_LEN]; unsigned long cnv; ssize_t len; off_t count; if (snprintf(path, FWSTS_FILENAME_LEN, "/sys/class/mei/%s/fw_status", device) < 0) return -EINVAL; path[FWSTS_FILENAME_LEN - 1] = '\0'; errno = 0; fd = open(path, O_CLOEXEC, O_RDONLY); if (fd == -1) { me->last_err = errno; return -me->last_err; } /* safe to cast to off_t: fwsts_num is a small number */ count = (off_t)fwsts_num * FWSTS_LEN; errno = 0; len = pread(fd, line, FWSTS_LEN, count); if (len == -1) { me->last_err = errno; close(fd); return -me->last_err; } close(fd); if (len < FWSTS_LEN) { me->last_err = EPROTO; return -me->last_err; } errno = 0; cnv = strtoul(line, NULL, CONV_BASE); if (errno) { me->last_err = errno; return -me->last_err; } *fwsts = cnv; return 0; #undef FWSTS_FILENAME_LEN #undef FWSTS_LEN #undef CONV_BASE } static inline int __mei_gettrc(struct mei *me, const char *device, uint32_t *trc_val) { #define TRC_FILENAME_LEN 33 #define TRC_LEN 9 #define CONV_BASE 16 char path[TRC_FILENAME_LEN]; int fd; char line[TRC_LEN]; unsigned long cnv; ssize_t len; if (snprintf(path, TRC_FILENAME_LEN, "/sys/class/mei/%s/trc", device) < 0) return -EINVAL; path[TRC_FILENAME_LEN - 1] = '\0'; errno = 0; fd = open(path, O_CLOEXEC, O_RDONLY); if (fd == -1) { me->last_err = errno; return -me->last_err; } errno = 0; len = pread(fd, line, TRC_LEN, 0); if (len == -1) { me->last_err = errno; close(fd); return -me->last_err; } close(fd); if (len < TRC_LEN) { me->last_err = EPROTO; return -me->last_err; } errno = 0; cnv = strtoul(line, NULL, CONV_BASE); if (errno) { me->last_err = errno; return -me->last_err; } *trc_val = cnv; return 0; #undef TRC_FILENAME_LEN #undef TRC_LEN #undef CONV_BASE } static inline int __mei_getkind(struct mei *me, const char *device, char *kind, size_t *kind_size) { #define KIND_FILENAME_LEN 34 #define KIND_LEN 16 char path[KIND_FILENAME_LEN]; char buf[KIND_LEN] = { 0 }; int fd; ssize_t len; if (snprintf(path, KIND_FILENAME_LEN, "/sys/class/mei/%s/kind", device) < 0) return -EINVAL; path[KIND_FILENAME_LEN - 1] = '\0'; errno = 0; fd = open(path, O_CLOEXEC, O_RDONLY); if (fd == -1) { me->last_err = errno; return -me->last_err; } errno = 0; len = pread(fd, buf, KIND_LEN, 0); if (len == -1) { me->last_err = errno; close(fd); return -me->last_err; } if (len == 0) { me->last_err = ENODATA; close(fd); return -me->last_err; } close(fd); if ((size_t)len > *kind_size || !kind) { me->last_err = ENOSPC; mei_err(me, "Insufficient buffer %zu %zd\n", *kind_size, len); *kind_size = (size_t)len; return -me->last_err; } *kind_size = (size_t)len; memcpy(kind, buf, (size_t)len); kind[len - 1] = '\0'; return 0; #undef KIND_FILENAME_LEN #undef KIND_LEN } static int __mei_init_with_log_int(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose, mei_log_callback log_callback, mei_log_callback2 log_callback2) { int rc; if (!me || !device || !guid) return -EINVAL; /* if me is uninitialized it will close wrong file descriptor */ me->fd = -1; me->close_on_exit = true; me->device = NULL; me->log_callback = log_callback; me->log_callback2 = log_callback2; mei_deinit(me); me->log_level = verbose ? MEI_LOG_LEVEL_VERBOSE : MEI_LOG_LEVEL_ERROR; mei_msg(me, "API version %u.%u\n", mei_get_api_version() >> 16 & 0xFF, mei_get_api_version() >> 8 & 0xFF); rc = __mei_open(me, device); if (rc < 0) { if (rc != -ENODEV) { mei_err(me, "Cannot establish a handle to the Intel MEI driver %.20s [%d]:%s\n", device, rc, strerror(-rc)); return rc; } mei_msg(me, "Intel MEI driver %.20s returned [%d]:%s\n", device, rc, strerror(-rc)); me->state = MEI_CL_STATE_DISABLED; } else { mei_msg(me, "Opened %.20s: fd = %d\n", device, me->fd); me->state = MEI_CL_STATE_INITIALIZED; } memcpy(&me->guid, guid, sizeof(*guid)); me->prot_ver = req_protocol_version; me->device = strdup(device); if (!me->device) { mei_deinit(me); return -ENOMEM; } return 0; } int mei_init_with_log(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose, mei_log_callback log_callback) { return __mei_init_with_log_int(me, device, guid, req_protocol_version, verbose, log_callback, NULL); } int mei_init_with_log2(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose, mei_log_callback2 log_callback) { return __mei_init_with_log_int(me, device, guid, req_protocol_version, verbose, NULL, log_callback); } int mei_init(struct mei *me, const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose) { return mei_init_with_log(me, device, guid, req_protocol_version, verbose, NULL); } static int __mei_fd_to_devname(struct mei *me, int fd) { char name[PATH_MAX]; char proc[PATH_MAX]; int ret; ssize_t sret; ret = snprintf(proc, PATH_MAX, "/proc/self/fd/%d", fd); if (ret < 0) { mei_err(me, "Proc path is bad %d\n", ret); return ret; } if (ret >= PATH_MAX) { mei_err(me, "Proc path is too long %d\n", ret); return -ENAMETOOLONG; } errno = 0; sret = readlink(proc, name, PATH_MAX); if (sret == -1) { mei_err(me, "Cannot obtain device name %d\n", errno); return -errno; } if (sret == PATH_MAX) { mei_err(me, "Cannot obtain device name, too long\n"); return -ENAMETOOLONG; } if (sret < 0 || sret > PATH_MAX) { mei_err(me, "Cannot obtain device name %zd\n", sret); return -EFAULT; } name[sret] = '\0'; me->device = strdup(name); if (!me->device) return -ENOMEM; return 0; } int mei_init_fd(struct mei *me, int fd, const uuid_le *guid, unsigned char req_protocol_version, bool verbose) { int ret; if (!me || fd < 0 || !guid) return -EINVAL; /* if me is uninitialized it will close wrong file descriptor */ me->close_on_exit = false; me->device = NULL; mei_deinit(me); me->fd = fd; me->log_callback = NULL; me->log_callback2 = NULL; me->log_level = verbose ? MEI_LOG_LEVEL_VERBOSE : MEI_LOG_LEVEL_ERROR; mei_msg(me, "API version %u.%u\n", mei_get_api_version() >> 16 & 0xFF, mei_get_api_version() >> 8 & 0xFF); memcpy(&me->guid, guid, sizeof(*guid)); me->prot_ver = req_protocol_version; ret = __mei_fd_to_devname(me, fd); if (ret) return ret; me->state = MEI_CL_STATE_INITIALIZED; return ret; } struct mei *mei_alloc(const char *device, const uuid_le *guid, unsigned char req_protocol_version, bool verbose) { struct mei *me; if (!device || !guid) return NULL; me = malloc(sizeof(struct mei)); if (!me) return NULL; if (mei_init(me, device, guid, req_protocol_version, verbose)) { free(me); return NULL; } return me; } struct mei *mei_alloc_fd(const int fd, const uuid_le *guid, unsigned char req_protocol_version, bool verbose) { struct mei *me = NULL; if (!guid || fd < 0) return NULL; me = malloc(sizeof(*me)); if (!me) return NULL; if (mei_init_fd(me, fd, guid, req_protocol_version, verbose)) { free(me); return NULL; } return me; } void mei_free(struct mei *me) { if (!me) return; mei_deinit(me); free(me); } int mei_set_nonblock(struct mei *me) { if (!me) return -EINVAL; return __mei_set_nonblock(me); } static int __int_mei_connect(struct mei *me, uint8_t vtag) { struct mei_client *cl; struct mei_connect_client_data data; struct mei_connect_client_data_vtag data_v; int rc; if (!me) return -EINVAL; if (me->state == MEI_CL_STATE_CONNECTED) { mei_err(me, "client is connected [%d]\n", me->state); return -EINVAL; } if (me->state == MEI_CL_STATE_DISABLED) { mei_err(me, "client is disabled\n"); return -EINVAL; } me->vtag = vtag; if (me->vtag) { memset(&data_v, 0, sizeof(data_v)); memcpy(&data_v.connect.in_client_uuid, &me->guid, sizeof(me->guid)); data_v.connect.vtag = me->vtag; rc = __mei_connect_vtag(me, &data_v); cl = &data_v.out_client_properties; } else { memset(&data, 0, sizeof(data)); memcpy(&data.in_client_uuid, &me->guid, sizeof(me->guid)); rc = __mei_connect(me, &data); cl = &data.out_client_properties; } if (rc < 0) { me->state = __mei_errno_to_state(me); mei_err(me, "Cannot connect to client [%d]:%s\n", rc, strerror(-rc)); return rc; } mei_msg(me, "max_message_length %d\n", cl->max_msg_length); mei_msg(me, "protocol_version %d\n", cl->protocol_version); if ((me->prot_ver > 0) && (cl->protocol_version < me->prot_ver)) { mei_err(me, "Intel MEI protocol version not supported\n"); me->state = MEI_CL_STATE_VERSION_MISMATCH; rc = -EINVAL; } else { me->buf_size = cl->max_msg_length; me->prot_ver = cl->protocol_version; me->state = MEI_CL_STATE_CONNECTED; } return rc; } int mei_connect(struct mei *me) { return __int_mei_connect(me, 0); } int mei_connect_vtag(struct mei *me, uint8_t vtag) { return __int_mei_connect(me, vtag); } ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer, size_t len) { ssize_t rc; if (!me || !buffer) return -EINVAL; if (me->state != MEI_CL_STATE_CONNECTED) { mei_err(me, "client is not connected [%d]\n", me->state); return -EINVAL; } mei_msg(me, "call read length = %zu\n", len); rc = __mei_read(me, buffer, len); if (rc < 0) { me->state = __mei_errno_to_state(me); mei_err(me, "read failed with status [%zd]:%s\n", rc, strerror(-rc)); goto out; } mei_msg(me, "read succeeded with result %zd\n", rc); mei_dump_hex_buffer(me, buffer, (size_t)rc); out: return rc; } ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer, size_t len) { ssize_t rc; if (!me || !buffer) return -EINVAL; if (me->state != MEI_CL_STATE_CONNECTED) { mei_err(me, "client is not connected [%d]\n", me->state); return -EINVAL; } mei_msg(me, "call write length = %zu\n", len); mei_dump_hex_buffer(me, buffer, len); rc = __mei_write(me, buffer, len); if (rc < 0) { me->state = __mei_errno_to_state(me); mei_err(me, "write failed with status [%zd]:%s\n", rc, strerror(-rc)); return rc; } return rc; } int mei_notification_request(struct mei *me, bool enable) { uint32_t _enable; int rc; if (!me) return -EINVAL; if (me->state != MEI_CL_STATE_CONNECTED) { mei_err(me, "client is not connected [%d]\n", me->state); return -EINVAL; } _enable = enable; rc = __mei_notify_set(me, &_enable); if (rc < 0) { me->state = __mei_errno_to_state(me); mei_err(me, "Cannot %s notification for client [%d]:%s\n", enable ? "enable" : "disable", rc, strerror(-rc)); return rc; } me->notify_en = enable; return 0; } int mei_notification_get(struct mei *me) { int rc; if (!me) return -EINVAL; if (me->state != MEI_CL_STATE_CONNECTED) { mei_err(me, "client is not connected [%d]\n", me->state); return -EINVAL; } if (!me->notify_en) return -ENOTSUP; rc = __mei_notify_get(me); if (rc < 0) { me->state = __mei_errno_to_state(me); mei_err(me, "Cannot get notification for client [%d]:%s\n", rc, strerror(-rc)); return rc; } return 0; } #define MAX_FW_STATUS_NUM 5 int mei_fwstatus(struct mei *me, uint32_t fwsts_num, uint32_t *fwsts) { char *device; int rc; if (!me || !fwsts) return -EINVAL; if (fwsts_num > MAX_FW_STATUS_NUM) { mei_err(me, "FW status number should be 0..5\n"); return -EINVAL; } if (me->device) { device = strstr(me->device, MEI_DEFAULT_DEVICE_PREFIX); if (!device) { mei_err(me, "Device does not start with '%s'\n", MEI_DEFAULT_DEVICE_PREFIX); return -EINVAL; } device += strlen(MEI_DEFAULT_DEVICE_PREFIX); } else { device = MEI_DEFAULT_DEVICE_NAME; } rc = __mei_fwsts(me, device, fwsts_num, fwsts); if (rc < 0) { mei_err(me, "Cannot get FW status [%d]:%s\n", rc, strerror(-rc)); return rc; } return 0; } int mei_gettrc(struct mei *me, uint32_t *trc_val) { char *device; int rc; if (!me || !trc_val) return -EINVAL; if (me->device) { device = strstr(me->device, MEI_DEFAULT_DEVICE_PREFIX); if (!device) { mei_err(me, "Device does not start with '%s'\n", MEI_DEFAULT_DEVICE_PREFIX); return -EINVAL; } device += strlen(MEI_DEFAULT_DEVICE_PREFIX); } else { device = MEI_DEFAULT_DEVICE_NAME; } rc = __mei_gettrc(me, device, trc_val); if (rc < 0) { mei_err(me, "Cannot get TRC value [%d]:%s\n", rc, strerror(-rc)); return rc; } return 0; } int mei_getkind(struct mei *me, char *kind, size_t *kind_size) { char *device; int rc; if (!me || !kind_size) return -EINVAL; if (me->device) { device = strstr(me->device, MEI_DEFAULT_DEVICE_PREFIX); if (!device) { mei_err(me, "Device does not start with '%s'\n", MEI_DEFAULT_DEVICE_PREFIX); return -EINVAL; } device += strlen(MEI_DEFAULT_DEVICE_PREFIX); } else { device = MEI_DEFAULT_DEVICE_NAME; } rc = __mei_getkind(me, device, kind, kind_size); if (rc < 0) { mei_err(me, "Cannot get kind value [%d]:%s\n", rc, strerror(-rc)); return rc; } return 0; } unsigned int mei_get_api_version(void) { return LIBMEI_API_VERSION; } uint32_t mei_set_log_level(struct mei *me, uint32_t log_level) { uint32_t prev_log_level; if (!me) return MEI_LOG_LEVEL_ERROR; prev_log_level = log_level; me->log_level = (log_level > MEI_LOG_LEVEL_VERBOSE) ? MEI_LOG_LEVEL_VERBOSE : log_level; return prev_log_level; } uint32_t mei_get_log_level(const struct mei *me) { if (!me) return MEI_LOG_LEVEL_ERROR; return me->log_level; } int mei_set_log_callback(struct mei *me, mei_log_callback log_callback) { if (!me) return -EINVAL; me->log_callback = log_callback; mei_msg(me, "New log callback set\n"); return 0; } int mei_set_log_callback2(struct mei *me, mei_log_callback2 log_callback) { if (!me) return -EINVAL; me->log_callback2 = log_callback; mei_msg(me, "New log callback set\n"); return 0; } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/linux/metee_linux.c���������������������������������������������������������0000664�0000000�0000000�00000040147�15201331742�0020700�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2026 Intel Corporation */ #include <errno.h> #include <fcntl.h> #include <libmei.h> #include <limits.h> #include <linux/mei.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <poll.h> #include <unistd.h> #include <stdarg.h> #include "metee.h" #include "helpers.h" #define MAX_FW_STATUS_NUM 5 #define CANCEL_PIPES_NUM 2 struct metee_linux_intl { struct mei me; int cancel_pipe[CANCEL_PIPES_NUM]; }; /* use inline function instead of macro to avoid -Waddress warning in GCC */ static inline struct mei *to_mei(PTEEHANDLE _h) __attribute__((always_inline)); static inline struct mei *to_mei(PTEEHANDLE _h) { return _h ? &((struct metee_linux_intl *)_h->handle)->me : NULL; } /* use inline function instead of macro to avoid -Waddress warning in GCC */ static inline struct metee_linux_intl *to_intl(PTEEHANDLE _h) __attribute__((always_inline)); static inline struct metee_linux_intl *to_intl(PTEEHANDLE _h) { return _h ? (struct metee_linux_intl *)_h->handle : NULL; } static inline int __mei_select(struct mei *me, int pipe_fd, bool on_read, int timeout) { int rv; struct pollfd pfd[2]; pfd[0].fd = me->fd; pfd[0].events = (on_read) ? POLLIN : POLLOUT; pfd[1].fd = pipe_fd; pfd[1].events = POLLIN; errno = 0; rv = poll(pfd, 2, timeout); if (rv < 0) return -errno; if (rv == 0) return -ETIME; if (pfd[1].revents != 0) return -ECANCELED; return 0; } static inline TEESTATUS errno2status(ssize_t err) { switch (err) { case 0 : return TEE_SUCCESS; case -ENOTTY: return TEE_CLIENT_NOT_FOUND; case -EBUSY : return TEE_BUSY; case -ENODEV: return TEE_DISCONNECTED; case -ETIME : return TEE_TIMEOUT; case -EACCES: return TEE_PERMISSION_DENIED; case -EOPNOTSUPP: return TEE_NOTSUPPORTED; case -ENODATA: return TEE_NOTSUPPORTED; case -ECANCELED: return TEE_UNABLE_TO_COMPLETE_OPERATION; case -ENOSPC: return TEE_INSUFFICIENT_BUFFER; default : return TEE_INTERNAL_ERROR; } } static inline TEESTATUS errno2status_init(ssize_t err) { switch (err) { case 0 : return TEE_SUCCESS; case -ENOENT: return TEE_DEVICE_NOT_FOUND; case -ENAMETOOLONG: return TEE_DEVICE_NOT_FOUND; case -EBUSY : return TEE_BUSY; case -ENODEV: return TEE_DEVICE_NOT_READY; case -ETIME : return TEE_TIMEOUT; case -EACCES: return TEE_PERMISSION_DENIED; default : return TEE_INTERNAL_ERROR; } } void CallbackPrintHelper(IN PTEEHANDLE handle, bool is_error, const char* args, ...) { char msg[DEBUG_MSG_LEN + 1]; va_list varl; va_start(varl, args); vsnprintf(msg, DEBUG_MSG_LEN, args, varl); va_end(varl); handle->log_callback2(is_error, msg); } static TEESTATUS TeeInitFullInt(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN TeeLogCallback log_callback, IN TeeLogCallback2 log_callback2) { struct metee_linux_intl *intl; TEESTATUS status; int rc; bool verbose = (log_level == TEE_LOG_LEVEL_VERBOSE); if (guid == NULL || handle == NULL) { return TEE_INVALID_PARAMETER; } __tee_init_handle(handle); handle->log_level = (log_level >= TEE_LOG_LEVEL_MAX) ? TEE_LOG_LEVEL_VERBOSE : log_level; handle->log_callback = log_callback; handle->log_callback2 = log_callback2; FUNC_ENTRY(handle); if (log_level >= TEE_LOG_LEVEL_MAX) { ERRPRINT(handle, "LogLevel %u is too big.\n", log_level); status = TEE_INVALID_PARAMETER; goto End; } switch (device.type) { case TEE_DEVICE_TYPE_NONE: if (device.data.path != NULL) { ERRPRINT(handle, "Path is not NULL.\n"); status = TEE_INVALID_PARAMETER; goto End; } break; case TEE_DEVICE_TYPE_PATH: if (device.data.path == NULL) { ERRPRINT(handle, "Path is NULL.\n"); status = TEE_INVALID_PARAMETER; goto End; } break; case TEE_DEVICE_TYPE_HANDLE: if (device.data.handle == TEE_INVALID_DEVICE_HANDLE) { ERRPRINT(handle, "Handle is invalid.\n"); status = TEE_INVALID_PARAMETER; goto End; } break; case TEE_DEVICE_TYPE_GUID: default: ERRPRINT(handle, "Wrong device type %u.\n", device.type); status = TEE_INVALID_PARAMETER; goto End; } intl = malloc(sizeof(struct metee_linux_intl)); if (!intl) { ERRPRINT(handle, "Cannot alloc intl structure\n"); status = TEE_INTERNAL_ERROR; goto End; } switch (device.type) { case TEE_DEVICE_TYPE_NONE: if (log_callback) rc = mei_init_with_log(&intl->me, MEI_DEFAULT_DEVICE, (uuid_le*)guid, 0, verbose, log_callback); else rc = mei_init_with_log2(&intl->me, MEI_DEFAULT_DEVICE, (uuid_le*)guid, 0, verbose, log_callback2); break; case TEE_DEVICE_TYPE_PATH: if (log_callback) rc = mei_init_with_log(&intl->me, device.data.path, (uuid_le*)guid, 0, verbose, log_callback); else rc = mei_init_with_log2(&intl->me, device.data.path, (uuid_le*)guid, 0, verbose, log_callback2); break; case TEE_DEVICE_TYPE_HANDLE: rc = mei_init_fd(&intl->me, device.data.handle, (uuid_le*)guid, 0, verbose); if (!rc) { if (log_callback) mei_set_log_callback(&intl->me, log_callback); else mei_set_log_callback2(&intl->me, log_callback2); mei_set_log_level(&intl->me, verbose); } break; default: rc = -EFAULT; break; } if (rc) { free(intl); ERRPRINT(handle, "Cannot init mei, rc = %d\n", rc); status = errno2status_init(rc); goto End; } rc = pipe(intl->cancel_pipe); if (rc) { mei_deinit(&intl->me); free(intl); ERRPRINT(handle, "Cannot init mei, rc = %d\n", rc); status = errno2status_init(rc); goto End; } handle->handle = intl; status = TEE_SUCCESS; End: return status; } TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback) { return TeeInitFullInt(handle, guid, device, log_level, log_callback, NULL); } TEESTATUS TEEAPI TeeInitFull2(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback2 log_callback) { return TeeInitFullInt(handle, guid, device, log_level, NULL, log_callback); } TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN OPTIONAL const char* device) { struct tee_device_address addr; addr.type = (device) ? TEE_DEVICE_TYPE_PATH : TEE_DEVICE_TYPE_NONE; addr.data.path = device; return TeeInitFull(handle, guid, addr, TEE_DEFAULT_LOG_LEVEL, NULL); } TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const TEE_DEVICE_HANDLE device_handle) { struct tee_device_address addr; addr.type = TEE_DEVICE_TYPE_HANDLE; addr.data.handle = device_handle; return TeeInitFull(handle, guid, addr, TEE_DEFAULT_LOG_LEVEL, NULL); } TEESTATUS TEEAPI TeeConnect(IN OUT PTEEHANDLE handle) { struct mei *me = to_mei(handle); TEESTATUS status; int rc; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me) { ERRPRINT(handle, "One of the parameters was illegal\n"); status = TEE_INVALID_PARAMETER; goto End; } rc = mei_connect(me); if (rc) { ERRPRINT(handle, "Cannot establish a handle to the Intel MEI driver\n"); status = errno2status(rc); goto End; } handle->maxMsgLen = me->buf_size; handle->protcolVer = me->prot_ver; status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout) { struct mei *me = to_mei(handle); struct metee_linux_intl *intl = to_intl(handle); int ltimeout; TEESTATUS status; ssize_t rc; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me || !buffer || !bufferSize) { ERRPRINT(handle, "One of the parameters was illegal\n"); status = TEE_INVALID_PARAMETER; goto End; } if (timeout > INT_MAX) { ERRPRINT(handle, "Timeout is too big %u > %d \n", timeout, INT_MAX); status = TEE_INVALID_PARAMETER; goto End; } if (me->state != MEI_CL_STATE_CONNECTED) { ERRPRINT(handle, "The client is not connected\n"); status = TEE_DISCONNECTED; goto End; } DBGPRINT(handle, "call read length = %zd\n", bufferSize); ltimeout = (timeout) ? (int)timeout : -1; rc = __mei_select(me, intl->cancel_pipe[0], true, ltimeout); if (rc) { status = errno2status(rc); ERRPRINT(handle, "select failed with status %zd %s\n", rc, strerror(-rc)); goto End; } rc = mei_recv_msg(me, buffer, bufferSize); if (rc < 0) { status = errno2status(rc); ERRPRINT(handle, "read failed with status %zd %s\n", rc, strerror(-rc)); goto End; } status = TEE_SUCCESS; DBGPRINT(handle, "read succeeded with result %zd\n", rc); if (pNumOfBytesRead) *pNumOfBytesRead = (size_t)rc; End: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout) { struct mei *me = to_mei(handle); struct metee_linux_intl *intl = to_intl(handle); int ltimeout; TEESTATUS status; ssize_t rc; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me || !buffer || !bufferSize) { ERRPRINT(handle, "One of the parameters was illegal\n"); status = TEE_INVALID_PARAMETER; goto End; } if (timeout > INT_MAX) { ERRPRINT(handle, "Timeout is too big %u > %d \n", timeout, INT_MAX); status = TEE_INVALID_PARAMETER; goto End; } if (me->state != MEI_CL_STATE_CONNECTED) { ERRPRINT(handle, "The client is not connected\n"); status = TEE_DISCONNECTED; goto End; } DBGPRINT(handle, "call write length = %zd\n", bufferSize); ltimeout = (timeout) ? (int)timeout : -1; rc = __mei_select(me, intl->cancel_pipe[0], false, ltimeout); if (rc) { status = errno2status(rc); ERRPRINT(handle, "select failed with status %zd %s\n", rc, strerror(-rc)); goto End; } rc = mei_send_msg(me, buffer, bufferSize); if (rc < 0) { status = errno2status(rc); ERRPRINT(handle, "write failed with status %zd %s\n", rc, strerror(-rc)); goto End; } if (numberOfBytesWritten) *numberOfBytesWritten = (size_t)rc; status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle, IN uint32_t fwStatusNum, OUT uint32_t *fwStatus) { struct mei *me = to_mei(handle); TEESTATUS status; uint32_t fwsts; int rc; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me || !fwStatus) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto End; } if (fwStatusNum > MAX_FW_STATUS_NUM) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "fwStatusNum should be 0..5\n"); goto End; } rc = mei_fwstatus(me, fwStatusNum, &fwsts); if (rc < 0) { status = errno2status(rc); ERRPRINT(handle, "fw status failed with status %d %s\n", rc, strerror(-rc)); goto End; } *fwStatus = fwsts; status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t* trc_val) { struct mei* me = to_mei(handle); TEESTATUS status; uint32_t trc; int rc; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me || !trc_val) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto End; } rc = mei_gettrc(me, &trc); if (rc < 0) { status = errno2status(rc); ERRPRINT(handle, "TRC get failed with status %d %s\n", rc, strerror(-rc)); goto End; } *trc_val = trc; status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } static void __TeeCancelIO(PTEEHANDLE handle) { struct metee_linux_intl* intl = to_intl(handle); const char buf[] = "X"; if (write(intl->cancel_pipe[1], buf, sizeof(buf)) < 0) { ERRPRINT(handle, "Pipe write failed\n"); } } void TEEAPI TeeCancelIO(IN PTEEHANDLE handle) { struct metee_linux_intl* intl = to_intl(handle); FUNC_ENTRY(handle); if (intl) { __TeeCancelIO(handle); } FUNC_EXIT(handle, TEE_SUCCESS); } void TEEAPI TeeDisconnect(PTEEHANDLE handle) { struct metee_linux_intl *intl = to_intl(handle); if (!handle) { return; } FUNC_ENTRY(handle); if (intl) { __TeeCancelIO(handle); mei_deinit(&intl->me); close(intl->cancel_pipe[0]); close(intl->cancel_pipe[1]); free(intl); handle->handle = NULL; } FUNC_EXIT(handle, TEE_SUCCESS); } TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle) { struct mei *me = to_mei(handle); if (!handle) { return TEE_INVALID_PARAMETER; } if (!me) { DBGPRINT(handle, "Internal structure is not initialized\n"); return TEE_INVALID_DEVICE_HANDLE; } return me->fd; } TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion) { struct mei *me = to_mei(handle); TEESTATUS status; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me || !driverVersion) { ERRPRINT(handle, "One of the parameters was illegal\n"); status = TEE_INVALID_PARAMETER; goto End; } status = TEE_NOTSUPPORTED; End: FUNC_EXIT(handle, status); return status; } uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level) { struct mei *me = to_mei(handle); uint32_t prev_log_level = TEE_LOG_LEVEL_ERROR; if (!handle) { return prev_log_level; } FUNC_ENTRY(handle); if (!me) { ERRPRINT(handle, "Illegal handle\n"); goto End; } prev_log_level = handle->log_level; handle->log_level = (log_level > TEE_LOG_LEVEL_VERBOSE) ? TEE_LOG_LEVEL_VERBOSE : log_level; mei_set_log_level(me, handle->log_level); End: FUNC_EXIT(handle, prev_log_level); return prev_log_level; } uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle) { uint32_t prev_log_level = TEE_LOG_LEVEL_ERROR; if (!handle) { return prev_log_level; } FUNC_ENTRY(handle); prev_log_level = handle->log_level; FUNC_EXIT(handle, prev_log_level); return prev_log_level; } TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback) { struct mei *me = to_mei(handle); TEESTATUS status; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (handle->log_callback2) { ERRPRINT(handle, "Standard callback already in use\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } handle->log_callback = log_callback; mei_set_log_callback(me, log_callback); status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeSetLogCallback2(IN const PTEEHANDLE handle, TeeLogCallback2 log_callback) { struct mei *me = to_mei(handle); TEESTATUS status; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (handle->log_callback) { ERRPRINT(handle, "Legacy callback already in use\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } handle->log_callback2 = log_callback; mei_set_log_callback2(me, log_callback); status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } uint32_t TEEAPI TeeGetMaxMsgLen(IN const PTEEHANDLE handle) { if (!handle) { return 0; } return (uint32_t)handle->maxMsgLen; } uint8_t TEEAPI TeeGetProtocolVer(IN const PTEEHANDLE handle) { if (!handle) { return 0; } return handle->protcolVer; } TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size_t *kindSize) { struct mei* me = to_mei(handle); TEESTATUS status; int rc; if (!handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (!me || !kindSize) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto End; } rc = mei_getkind(me, kind, kindSize); if (rc < 0) { status = errno2status(rc); if (status == TEE_INSUFFICIENT_BUFFER) { DBGPRINT(handle, "Insufficient buffer %zu\n", *kindSize); } else { ERRPRINT(handle, "kind get failed with status %d %s\n", rc, strerror(-rc)); } goto End; } status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/uefi/�����������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0016001�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/uefi/heci_core.c������������������������������������������������������������0000664�0000000�0000000�00000053363�15201331742�0020077�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024 Intel Corporation */ #include <Uefi.h> #include <Library/BaseLib.h> #include <Library/UefiLib.h> #include <Library/BaseMemoryLib.h> #include <Library/UefiBootServicesTableLib.h> #include <Library/IoLib.h> #include "metee.h" #include "helpers.h" #include "metee_efi.h" #include "heci_core.h" #include "pci_utils.h" #pragma pack(1) /// /// H_CSR - Host Control Status Register, default offset 04h /// ME_CSR_HA - ME Control Status Register (Host Access), default offset 0Ch /// typedef union { UINT32 Data; struct { UINT32 IntEnable : 1; ///< 0 - Host/ME Interrupt Enable UINT32 IntStatus : 1; ///< 1 - Host/ME Interrupt Status UINT32 IntGenerate : 1; ///< 2 - Host/ME Interrupt Generate UINT32 Ready : 1; ///< 3 - Host/ME Ready UINT32 Reset : 1; ///< 4 - Host/ME Reset UINT32 Reserved : 3; ///< 7:5 - Reserved UINT32 CBReadPointer : 8; ///< 15:8 - Host/ME Circular Buffer Read Pointer UINT32 CBWritePointer : 8; ///< 23:16 - Host/ME Circular Buffer Write Pointer UINT32 CBDepth : 8; ///< 31:24 - Host/ME Circular Buffer Depth } Fields; } HECI_CONTROL_STATUS_REGISTER; typedef union { UINT32 Data; struct { /** This is the logical address of the Intel ME client of the message. This address is assigned during ME firmware initialization. **/ UINT32 FwAddress : 8; /** This is the logical address of the Host client of the message. This address is assigned when the host client registers itself with the Host MEI driver. **/ UINT32 HostAddress : 8; /** This is the message length in bytes, not including the MEI_MESSAGE_HEADER. A value of 0 indicates no additional bytes are part of the message. **/ UINT32 Length : 9; UINT32 Reserved : 6; UINT32 MessageComplete : 1; ///< Indicates the last message of the list } Fields; } HECI_MESSAGE_HEADER; #pragma pack() // // Timeout values based on HPET // #define HECI_INIT_TIMEOUT 15000000 ///< 15sec timeout in microseconds #define HECI_READ_TIMEOUT 5000000 ///< 5sec timeout in microseconds #define HECI_SEND_TIMEOUT 5000000 ///< 5sec timeout in microseconds #define HECI_CB_OVERFLOW 0xFFFFFFFF ///< Circular buffer overflow /** Return number of filled slots in HECI circular buffer. @param[in] ControlStatusRegister FW Control Status Register @retval FilledSlots Number of filled slots in circular buffer @retval HECI_CB_OVERFLOW Circular buffer overflow has occurred **/ static UINT32 GetFilledSlots( IN HECI_CONTROL_STATUS_REGISTER ControlStatusRegister) { UINT8 FilledSlots; FilledSlots = (INT8)ControlStatusRegister.Fields.CBWritePointer - (INT8)ControlStatusRegister.Fields.CBReadPointer; return (FilledSlots > (UINT8)ControlStatusRegister.Fields.CBDepth) ? HECI_CB_OVERFLOW : FilledSlots; } #define DelayExecutionFlow gBS->Stall #define TIMER_STEP 1000 /** Checks if FW is ready for communication over the HECI interface. @param[in] Handle The HECI Handle to be accessed. @param[in] HeciMemBar HECI Memory BAR @param[in] Timeout Timeout value in microseconds @retval TRUE FW is ready @retval FALSE FW is not ready **/ static BOOLEAN IsMeReady( IN struct METEE_EFI_IMPL *Handle, IN UINTN HeciMemBar, IN UINT32 Timeout) { HECI_CONTROL_STATUS_REGISTER HeciCsrMeHra; while (Timeout > TIMER_STEP) { HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); /// /// Check for reset first and then for FW Ready /// if (HeciCsrMeHra.Fields.Reset) { return FALSE; } else if (HeciCsrMeHra.Fields.Ready) { return TRUE; } DelayExecutionFlow(TIMER_STEP); Timeout -= TIMER_STEP; } DBGPRINT(Handle->TeeHandle, "HECI Interface ERROR: Timeout due to ME_RDY bit not set after %d seconds\n", Timeout); return FALSE; } /** Function forces a reinit of the heci interface by following the reset heci interface via host algorithm in HPS section 4.1.1.1 @param[in] Handle The HECI Handle to be accessed. @retval EFI_SUCCESS Interface reset successful @retval EFI_TIMEOUT ME is not ready **/ EFI_STATUS EFIAPI ResetHeciInterface( IN struct METEE_EFI_IMPL *Handle) { EFI_STATUS status = EFI_UNSUPPORTED; HECI_CONTROL_STATUS_REGISTER HeciCsrHost; HECI_CONTROL_STATUS_REGISTER HeciCsrMeHra; UINT32 Timeout = HECI_INIT_TIMEOUT; UINT64 HeciMemBar; FUNC_ENTRY(Handle->TeeHandle); EFIPRINT(Handle->TeeHandle, "Resetting interface\n"); /// /// Make sure that HECI device BAR is correct and device is enabled. /// HeciMemBar = CheckAndFixHeciForAccess(Handle); if (HeciMemBar == 0) { EFIPRINT(Handle->TeeHandle, "HeciMemBar = 0\n"); status = EFI_DEVICE_ERROR; goto End; } /// /// Enable Reset /// HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); EFIPRINT(Handle->TeeHandle, "Step1 Enable Host Reset : H_CSR = 0x%08X\n", HeciCsrHost.Data); if (!HeciCsrHost.Fields.Reset) { HeciCsrHost.Fields.Reset = 1; HeciCsrHost.Fields.IntGenerate = 1; MmioWrite32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR, HeciCsrHost.Data); } /// /// Make sure that the reset started /// EFIPRINT(Handle->TeeHandle, "Step2 Wait for reset started: H_CSR = 0x%08X\n", HeciCsrHost.Data); do { if (Timeout < TIMER_STEP) { EFIPRINT(Handle->TeeHandle, "IsHeciTimeout"); status = EFI_TIMEOUT; goto End; } EFIPRINT(Handle->TeeHandle, "Wait iteration Timeout left %d, TimerStep %d\n", Timeout, TIMER_STEP); DelayExecutionFlow(TIMER_STEP); Timeout -= TIMER_STEP; HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); EFIPRINT(Handle->TeeHandle, "Value after wait: H_CSR = 0x%08X\n", HeciCsrHost.Data); } while (HeciCsrHost.Fields.Ready == 1); /// /// Wait for ME to perform reset /// HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); EFIPRINT(Handle->TeeHandle, "Step3 Wait for ME reset: ME_CSR_HA = 0x%08X\n", HeciCsrMeHra.Data); do { if (Timeout < TIMER_STEP) { EFIPRINT(Handle->TeeHandle, "Step3 ME has failed to reset Heci: ME_CSR_HA = 0x%08X\n", HeciCsrMeHra.Data); status = EFI_TIMEOUT; goto End; } DelayExecutionFlow(TIMER_STEP); Timeout -= TIMER_STEP; HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); } while (HeciCsrMeHra.Fields.Ready == 0); /// /// Enable host side interface. Host SW writes the value read back to the H_CSR register. /// This clears the H_IS and bit in H_CSR to 0 /// HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); HeciCsrHost.Fields.Reset = 0; HeciCsrHost.Fields.IntGenerate = 1; HeciCsrHost.Fields.Ready = 1; MmioWrite32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR, HeciCsrHost.Data); status = EFI_SUCCESS; End: FUNC_EXIT(Handle->TeeHandle, status); return status; } /** Function to pull one message packet off the HECI circular buffer up to its capacity. Corresponds to HECI HPS (part of) section 4.2.4. BIOS does not rely on Interrupt Status bit, since this bit can be set due to several reasons: a) FW has finished reading data from H_CSR b) FW has finished writing data to ME_CSR c) Reset has occurred Because of above - additional checks must be conducted in order to prevent misinterpretations. @param[in] Handle The HECI Handle to be accessed. @param[in] HeciMemBar HECI Memory BAR. @param[in] Timeout Timeout value for first Dword to appear in circular buffer. @param[out] MessageHeader Pointer to message header buffer. @param[in] MessageData Pointer to receive buffer. @param[in, out] BufferLength On input is the size of the caller's buffer in bytes. On output is the size of the data copied to the buffer. @param[out] PacketSize Size of the packet in bytes. This might be greater than buffer size. @retval EFI_SUCCESS One message packet read. @retval EFI_DEVICE_ERROR The circular buffer is overflowed or transaction error. @retval EFI_NO_RESPONSE The circular buffer is empty @retval EFI_TIMEOUT Failed to receive a full message on time @retval EFI_BUFFER_TOO_SMALL Message packet is larger than caller's buffer **/ static EFI_STATUS HeciPacketRead( IN struct METEE_EFI_IMPL *Handle, IN UINTN HeciMemBar, IN UINT32 Timeout, OUT HECI_MESSAGE_HEADER *MessageHeader, OUT UINT32 *MessageData, IN OUT UINT32 *BufferLength, OUT UINT32 *PacketSize) { EFI_STATUS Status; UINT32 Index; UINT32 FilledSlots; UINT32 LengthInDwords; UINT32 TempBuffer; UINT32 ByteCount; HECI_CONTROL_STATUS_REGISTER HeciCsrMeHra; HECI_CONTROL_STATUS_REGISTER HeciCsrHost; *PacketSize = 0; Status = EFI_SUCCESS; HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); FilledSlots = GetFilledSlots(HeciCsrMeHra); /// /// For BLOCKING read, wait until data appears in the CB or timeout occurs /// if (Timeout != 0) { while (FilledSlots == 0) { if (Timeout < TIMER_STEP) { return EFI_TIMEOUT; } DelayExecutionFlow(TIMER_STEP); Timeout -= TIMER_STEP; HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); FilledSlots = GetFilledSlots(HeciCsrMeHra); } } /// /// Check for empty and overflowed CB /// if (FilledSlots == 0) { *BufferLength = 0; return EFI_NO_RESPONSE; } else if (FilledSlots == HECI_CB_OVERFLOW) { *BufferLength = 0; return EFI_DEVICE_ERROR; } /// /// Eat the HECI Message header /// MessageHeader->Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CB_RW); /// /// Compute required message length in DWORDS /// LengthInDwords = ((MessageHeader->Fields.Length + 3) / 4); if (LengthInDwords > HeciCsrMeHra.Fields.CBDepth) { /// /// Make sure that the message does not overflow the circular buffer. /// *BufferLength = 0; return EFI_DEVICE_ERROR; } /// /// Wait until whole message appears in circular buffer. /// Timeout = HECI_READ_TIMEOUT; do { HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); if (Timeout < TIMER_STEP) { return EFI_TIMEOUT; } DelayExecutionFlow(TIMER_STEP); Timeout -= TIMER_STEP; } while (GetFilledSlots(HeciCsrMeHra) < LengthInDwords); /// /// Update status to signal if buffer can hold the message /// if ((MessageHeader->Fields.Length) <= *BufferLength) { Status = EFI_SUCCESS; } else { Status = EFI_BUFFER_TOO_SMALL; } /// /// Copy as much bytes as there is space left in the message buffer. /// Excessive bytes will be dismissed. /// ByteCount = 0; for (Index = 0; Index < LengthInDwords; Index++) { TempBuffer = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CB_RW); CopyMem(&MessageData[Index], &TempBuffer, MIN(sizeof(TempBuffer), *BufferLength)); ByteCount += MIN(sizeof(TempBuffer), *BufferLength); *BufferLength -= MIN(sizeof(TempBuffer), *BufferLength); } *BufferLength = ByteCount; *PacketSize = MessageHeader->Fields.Length; /// /// Read Handle->Hw.RegisterOffset.ME_CSR_HA. If the ME_RDY bit is 0, then an ME reset occurred during the /// transaction and the message should be discarded as bad data may have been retrieved /// from the host's circular buffer /// HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); if (HeciCsrMeHra.Fields.Ready == 0) { *BufferLength = 0; *PacketSize = 0; return EFI_NOT_READY; } /// /// Set Interrupt Generate bit and clear Interrupt Status bit if there are no more messages in the buffer. /// HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); if (GetFilledSlots(HeciCsrMeHra) == 0) { HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); HeciCsrHost.Fields.IntGenerate = 1; HeciCsrHost.Fields.IntStatus = 1; MmioWrite32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR, HeciCsrHost.Data); HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); } return Status; } /** Reads a message from FW through HECI. @param[in] Handle The HECI Handle to be accessed. @param[in] Blocking Used to determine if the read is BLOCKING or NON_BLOCKING. @param[in, out] MessageBody Pointer to a buffer used to receive a message. @param[in, out] Length Pointer to the length of the buffer on input and the length of the message on return. (in bytes) @retval EFI_SUCCESS One message packet read. @retval EFI_DEVICE_ERROR Failed to initialize HECI @retval EFI_NOT_READY HECI is not ready for communication @retval EFI_TIMEOUT Failed to receive a full message on time @retval EFI_NO_RESPONSE No response from FW @retval EFI_BUFFER_TOO_SMALL The caller's buffer was not large enough **/ EFI_STATUS EFIAPI HeciReceive( IN struct METEE_EFI_IMPL *Handle, IN UINT32 Blocking, IN OUT UINT32 *MessageBody, IN OUT UINT32 *Length) { EFI_STATUS status = EFI_UNSUPPORTED; UINT64 HeciMemBar; HECI_MESSAGE_HEADER PacketHeader; UINT32 TotalLength; UINT32 PacketSize; UINT32 PacketBuffer; UINT32 ReadTimeout; UINT32 InitTimeout; UINT32 InputLength; BOOLEAN FirstPacket = TRUE; InputLength = *Length; PacketHeader.Data = 0; TotalLength = 0; PacketBuffer = InputLength; FUNC_ENTRY(Handle->TeeHandle); /// /// Make sure that HECI device BAR is correct and device is enabled. /// HeciMemBar = CheckAndFixHeciForAccess(Handle); if (HeciMemBar == 0) { EFIPRINT(Handle->TeeHandle, "HeciMemBar = 0\n"); status = EFI_DEVICE_ERROR; goto End; } if (Blocking) { InitTimeout = HECI_INIT_TIMEOUT; ReadTimeout = HECI_READ_TIMEOUT; } else { InitTimeout = 0; ReadTimeout = 0; } if (!IsMeReady(Handle, HeciMemBar, InitTimeout)) { // // Return as CB will be empty after reset and FW will not put any data // EFIPRINT(Handle->TeeHandle, "FW Not Ready\n"); status = EFI_ABORTED; goto End; } // // Read until MessageComplete bit is set // while (!PacketHeader.Fields.MessageComplete) { status = HeciPacketRead( Handle, HeciMemBar, ReadTimeout, &PacketHeader, (UINT32 *)&MessageBody[TotalLength / 4], &PacketBuffer, &PacketSize); if (status != EFI_NO_RESPONSE) { EFIPRINT(Handle->TeeHandle, "Got msg: Status %d, Data %08X\n", status, PacketHeader.Data); }; if (FirstPacket) { EFIPRINT(Handle->TeeHandle, "HeciReceive: Host Client Id: %d FW Client Id: %d\n", PacketHeader.Fields.HostAddress, PacketHeader.Fields.FwAddress); FirstPacket = FALSE; } /// /// If timeout occurred we need to reset the interface to clear the data that could possibly come later. /// Also buffer overflow and transaction errors will require a reset. /// We need to continue read even if buffer too small to clear the data and signal the buffer size. /// if (EFI_ERROR(status) && status != EFI_BUFFER_TOO_SMALL) { if (status != EFI_NO_RESPONSE) { EFIPRINT(Handle->TeeHandle, "FW Not Ready\n"); status = EFI_ABORTED; goto End; } *Length = TotalLength; if (!(status == EFI_NO_RESPONSE && Blocking == NON_BLOCKING)) { // // NO_RESPONSE is expected for NON_BLOCKING ReadMsg. // EFIPRINT(Handle->TeeHandle, "NO_RESPONSE is expected for NON_BLOCKING ReadMsg.\n"); } goto End; } /// /// Track the length of what we have read so far /// TotalLength += PacketSize; /// /// To do message size calculations we are using 3 different variables: /// PacketBuffer - on input -> space left in the buffer, on output -> number of bytes written to buffer /// Length - max buffer size /// TotalLength - Total message size -> sum of all bytes in multiple packets /// if (TotalLength < *Length) { PacketBuffer = *Length - TotalLength; } else { PacketBuffer = 0; } /// /// If this was a NON-BLOCKING message and it is a multipacket message, we need to change the /// parameter to BLOCKING because it will take a non-zero value of time until a new packet appears /// ReadTimeout = HECI_READ_TIMEOUT; } *Length = TotalLength; status = EFI_SUCCESS; End: FUNC_EXIT(Handle->TeeHandle, status); return status; } /** Function sends one message packet through the HECI circular buffer Corresponds to HECI HPS (part of) section 4.2.3 @param[in] HeciMemBar HECI Memory BAR. @param[in] MessageHeader Pointer to the message header. @param[in] MessageData Pointer to the actual message data. @retval EFI_SUCCESS One message packet sent @retval EFI_ABORTED Fatal error has occurred during transmission of the message @retval EFI_DEVICE_ERROR Unrecoverable fatal error has occurred during transmission of the message @retval EFI_TIMEOUT CSME failed to empty the circular buffer @retval EFI_NOT_READY Fatal error has occurred during transmission of the message **/ static EFI_STATUS HeciPacketWrite( IN struct METEE_EFI_IMPL *Handle, IN UINTN HeciMemBar, IN HECI_MESSAGE_HEADER *MessageHeader, IN UINT32 *MessageData) { UINT32 Timeout = HECI_SEND_TIMEOUT; UINT32 Index; UINT32 LengthInDwords; HECI_CONTROL_STATUS_REGISTER HeciCsrHost; HECI_CONTROL_STATUS_REGISTER HeciCsrMeHra; /// /// Compute message length in DWORDS /// LengthInDwords = ((MessageHeader->Fields.Length + 3) / 4); /// /// Wait until there is sufficient room in the circular buffer /// Must have room for message and message header /// HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); while ((LengthInDwords + 1) > (HeciCsrHost.Fields.CBDepth - GetFilledSlots(HeciCsrHost))) { if (Timeout < TIMER_STEP) { DBGPRINT(Handle->TeeHandle, "EFI_TIMEOUT due to circular buffer never emptied after %d seconds waiting", HECI_SEND_TIMEOUT); return EFI_TIMEOUT; } DelayExecutionFlow(TIMER_STEP); Timeout -= TIMER_STEP; HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); } /// /// Write Message Header /// MmioWrite32(HeciMemBar + Handle->Hw.RegisterOffset.H_CB_WW, MessageHeader->Data); /// /// Write Message Body /// for (Index = 0; Index < LengthInDwords; Index++) { MmioWrite32(HeciMemBar + Handle->Hw.RegisterOffset.H_CB_WW, MessageData[Index]); } /// /// Set Interrupt Generate bit /// HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); HeciCsrHost.Fields.IntGenerate = 1; MmioWrite32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR, HeciCsrHost.Data); /// /// Test if FW Ready bit is set to 1, if set to 0 a fatal error occurred during /// the transmission of this message. /// HeciCsrMeHra.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.ME_CSR_HA); if (HeciCsrMeHra.Fields.Ready == 0) { return EFI_NOT_READY; } return EFI_SUCCESS; } /** Function sends one message (of any length) through the HECI circular buffer. @param[in] Handle The HECI Handle to be accessed. @param[in] Message Pointer to the message data to be sent. @param[in] Length Length of the message in bytes. @param[in] HostAddress The address of the host processor. @param[in] FwAddress Address of the FW subsystem the message is being sent to. @retval EFI_SUCCESS One message packet sent. @retval EFI_DEVICE_ERROR Failed to initialize HECI @retval EFI_NOT_READY HECI is not ready for communication @retval EFI_TIMEOUT FW failed to empty the circular buffer @retval EFI_UNSUPPORTED Current FW mode doesn't support send this message through this HECI **/ EFI_STATUS EFIAPI HeciSend( IN struct METEE_EFI_IMPL *Handle, IN UINT32 *Message, IN UINT32 Length, IN UINT8 HostAddress, IN UINT8 FwAddress) { EFI_STATUS status = EFI_UNSUPPORTED; HECI_MESSAGE_HEADER MessageHeader; HECI_CONTROL_STATUS_REGISTER HeciCsrHost; UINT32 CircularBufferDepth; UINT32 SendLength; UINT32 BytesLeft; UINT64 HeciMemBar; EFIPRINT(Handle->TeeHandle, "HeciSend: Host Client Id: %d FW Client Id: %d\n", HostAddress, FwAddress); /// /// Make sure that HECI device BAR is correct and device is enabled. /// HeciMemBar = CheckAndFixHeciForAccess(Handle); if (HeciMemBar == 0) { EFIPRINT(Handle->TeeHandle, "HeciMemBar = 0\n"); status = EFI_DEVICE_ERROR; goto End; } /// /// Make sure that HECI is ready for communication /// if (!IsMeReady(Handle, HeciMemBar, HECI_INIT_TIMEOUT)) { EFIPRINT(Handle->TeeHandle, "FW Not Ready\n"); status = EFI_ABORTED; goto End; } /// /// Set up memory mapped registers /// HeciCsrHost.Data = MmioRead32(HeciMemBar + Handle->Hw.RegisterOffset.H_CSR); /// /// Grab Circular Buffer length and convert it from Dword to bytes /// CircularBufferDepth = 4 * HeciCsrHost.Fields.CBDepth; /// /// Prepare message header /// MessageHeader.Data = 0; MessageHeader.Fields.FwAddress = FwAddress; MessageHeader.Fields.HostAddress = HostAddress; BytesLeft = Length; /// /// Break message up into CB-sized packets and loop until completely sent /// while (BytesLeft) { /// /// Set the Message Complete bit if this is our last packet in the message. /// Needs to be less or equal to CB depth minus one Dword for HECI header. /// if (BytesLeft <= CircularBufferDepth - sizeof(MessageHeader)) { MessageHeader.Fields.MessageComplete = 1; } /// /// Calculate length for Message Header: /// It will be the smaller value of circular buffer or remaining message. /// SendLength = MIN(CircularBufferDepth - sizeof(MessageHeader), BytesLeft); MessageHeader.Fields.Length = SendLength; /// /// Send the current packet /// EFIPRINT(Handle->TeeHandle, "Send msg Data: %08X\n", MessageHeader.Data); status = HeciPacketWrite(Handle, HeciMemBar, &MessageHeader, (UINT32 *)((UINTN)Message + (Length - BytesLeft))); if (EFI_ERROR(status)) { EFIPRINT(Handle->TeeHandle, "FW Not Ready\n"); status = EFI_ABORTED; goto End; } /// /// Update the length information /// BytesLeft -= SendLength; } End: FUNC_EXIT(Handle->TeeHandle, status); return status; } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/uefi/heci_core.h������������������������������������������������������������0000664�0000000�0000000�00000004761�15201331742�0020102�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������ /* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024 Intel Corporation */ #ifndef HECI_CORE_H_ #define HECI_CORE_H_ #include "metee.h" struct METEE_EFI_IMPL; #define NON_BLOCKING 0 #define BLOCKING 1 /** Function forces a reinit of the heci interface by following the reset heci interface via host algorithm in HPS section 4.1.1.1 @param[in] Handle The HECI handle to be accessed. @retval EFI_SUCCESS Interface reset successful @retval EFI_TIMEOUT ME is not ready **/ EFI_STATUS EFIAPI ResetHeciInterface( IN struct METEE_EFI_IMPL *Handle); /** Function sends one message (of any length) through the HECI circular buffer. @param[in] Handle HECI handle to be accessed. @param[in] Message Pointer to the message data to be sent. @param[in] Length Length of the message in bytes. @param[in] HostAddress The address of the host processor. @param[in] MeAddress Address of the ME subsystem the message is being sent to. @retval EFI_SUCCESS One message packet sent. @retval EFI_DEVICE_ERROR Failed to initialize HECI @retval EFI_NOT_READY HECI is not ready for communication @retval EFI_TIMEOUT FW failed to empty the circular buffer @retval EFI_UNSUPPORTED Current ME mode doesn't support send this message through this HECI **/ EFI_STATUS EFIAPI HeciSend( IN struct METEE_EFI_IMPL *Handle, IN UINT32 *Message, IN UINT32 Length, IN UINT8 HostAddress, IN UINT8 MeAddress); /** Reads a message from FW through HECI. @param[in] Handle HECI handle to be accessed. @param[in] Blocking Used to determine if the read is BLOCKING or NON_BLOCKING. @param[in, out] MessageBody Pointer to a buffer used to receive a message. @param[in, out] Length Pointer to the length of the buffer on input and the length of the message on return. (in bytes) @retval EFI_SUCCESS One message packet read. @retval EFI_DEVICE_ERROR Failed to initialize HECI @retval EFI_NOT_READY HECI is not ready for communication @retval EFI_TIMEOUT Failed to receive a full message on time @retval EFI_NO_RESPONSE No response from FW @retval EFI_BUFFER_TOO_SMALL The caller's buffer was not large enough **/ EFI_STATUS EFIAPI HeciReceive( IN struct METEE_EFI_IMPL *Handle, IN UINT32 Blocking, IN OUT UINT32 *MessageBody, IN OUT UINT32 *Length); #endif // HECI_CORE_H_���������������intel-metee-67ff323/src/uefi/heci_efi.c�������������������������������������������������������������0000664�0000000�0000000�00000066275�15201331742�0017720�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024-2026 Intel Corporation */ #include <Uefi.h> #include <Library/UefiLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/BaseMemoryLib.h> #include <Library/BaseLib.h> #include <Library/PciSegmentLib.h> #include <Library/IoLib.h> #include <Library/UefiBootServicesTableLib.h> #include "metee.h" #include "helpers.h" #include "metee_efi.h" #include "heci_efi.h" #include "pci_utils.h" #include "heci_core.h" #define BIOS_FIXED_HOST_ADDR 0 #define HECI_HBM_MSG_ADDR 0x00 #define HECI_TIMEOUT_STALL_SEC (40 * 1000 * 1000) ///< 40 seconds #pragma pack(1) typedef struct _HBM_CLIENT_PROP_MSG { UINT8 Command; UINT8 Address; UINT8 Resv[2]; } HBM_CLIENT_PROP_MSG; typedef struct _HBM_CLIENT_PROP_MSG_REPLY { UINT8 CmdReply; UINT8 Address; UINT8 Status; UINT8 Resv; GUID ProtocolName; UINT8 ProtocolVersion; UINT8 MaximumConnections; UINT8 FixedAddress; UINT8 SingleRecvBuffer; UINT32 MaxMessageLength; } HBM_CLIENT_PROP_MSG_REPLY; #pragma pack() #define TEE_MAX_FW_CLIENTS 256 struct HeciDeviceLibrary { struct HECI_HW_BDF Key; struct STATE { BOOLEAN IsValid; UINT32 ResetGeneration; /** Link Reset counter for given device */ UINT8 HostClientIds[TEE_MAX_FW_CLIENTS]; struct { HECI_CLIENT_PROPERTIES ClientProperties; BOOLEAN IsValid; } Clients[TEE_MAX_FW_CLIENTS]; /** Available clients for given device */ } State; }; #define CONF_HECI_MAX_HECI_DEVICES_IN_THE_SYSTEM 4 #define HECI_DEVICE_UNINITIALIZED 0xFFFFFFFF static struct HeciDeviceLibrary gHeciDeviceLibrary[CONF_HECI_MAX_HECI_DEVICES_IN_THE_SYSTEM] = { {{ HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED}, {0, 0}}, {{ HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED}, {0, 0}}, {{ HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED}, {0, 0}}, {{ HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED, HECI_DEVICE_UNINITIALIZED}, {0, 0}}, }; static struct HeciDeviceLibrary * GetHeciLibrary( IN struct HECI_HW_BDF * Key ) { UINT32 ind = 0; /* Find existing */ for (; ind<CONF_HECI_MAX_HECI_DEVICES_IN_THE_SYSTEM; ++ind) { if (Key->Segment == gHeciDeviceLibrary[ind].Key.Segment && Key->Bus == gHeciDeviceLibrary[ind].Key.Bus && Key->Device == gHeciDeviceLibrary[ind].Key.Device && Key->Function == gHeciDeviceLibrary[ind].Key.Function ) { return &gHeciDeviceLibrary[ind]; } } /* Allocate new slot */ for (ind=0; ind<CONF_HECI_MAX_HECI_DEVICES_IN_THE_SYSTEM; ++ind) { if (HECI_DEVICE_UNINITIALIZED == gHeciDeviceLibrary[ind].Key.Segment && HECI_DEVICE_UNINITIALIZED == gHeciDeviceLibrary[ind].Key.Bus && HECI_DEVICE_UNINITIALIZED == gHeciDeviceLibrary[ind].Key.Device && HECI_DEVICE_UNINITIALIZED == gHeciDeviceLibrary[ind].Key.Function ) { gHeciDeviceLibrary[ind].Key = *Key; gHeciDeviceLibrary[ind].State.ResetGeneration = 0; gHeciDeviceLibrary[ind].State.IsValid = 0; SetMem(gHeciDeviceLibrary[ind].State.HostClientIds, sizeof(gHeciDeviceLibrary[ind].State.HostClientIds), 0x0); SetMem(gHeciDeviceLibrary[ind].State.Clients, sizeof(gHeciDeviceLibrary[ind].State.Clients), 0x0); return &gHeciDeviceLibrary[ind]; } } return NULL; } static EFI_STATUS heciReadMsg( IN struct METEE_EFI_IMPL *Handle, IN UINT32 Blocking, IN UINT32 *MessageBody, IN UINT32 MessageBodyLenBytes, OUT UINT32 *BytesRead) { EFI_STATUS status = EFI_UNSUPPORTED; struct HeciDeviceLibrary * lib = NULL; UINT32 length = MessageBodyLenBytes; FUNC_ENTRY(Handle->TeeHandle); status = HeciReceive(Handle, Blocking, MessageBody, &length); if (EFI_ERROR(status)) { *BytesRead = 0; } else { *BytesRead = length; } if (status == EFI_ABORTED) { lib = GetHeciLibrary(&Handle->Hw.Bdf); if (lib == NULL) { DBGPRINT(Handle->TeeHandle, "Library not found\n"); status = EFI_OUT_OF_RESOURCES; } else { lib->State.IsValid = FALSE; Handle->HeciClientConnection.connected = FALSE; status = EFI_MEDIA_CHANGED; } } FUNC_EXIT(Handle->TeeHandle, status); return status; } static EFI_STATUS heciSendMsg( IN struct METEE_EFI_IMPL *Handle, IN UINT32 *Message, IN UINT32 Length, IN UINT8 HostAddress, IN UINT8 MeAddress) { EFI_STATUS status = EFI_UNSUPPORTED; struct HeciDeviceLibrary * lib = NULL; FUNC_ENTRY(Handle->TeeHandle); status = HeciSend(Handle, Message, Length, HostAddress, MeAddress); if (status == EFI_ABORTED) { lib = GetHeciLibrary(&Handle->Hw.Bdf); if (lib == NULL) { DBGPRINT(Handle->TeeHandle, "Library not found\n"); status = EFI_OUT_OF_RESOURCES; } else { lib->State.IsValid = FALSE; Handle->HeciClientConnection.connected = FALSE; status = EFI_MEDIA_CHANGED; } } FUNC_EXIT(Handle->TeeHandle, status); return status; } static EFI_STATUS heciReset( IN struct METEE_EFI_IMPL *Handle) { EFI_STATUS status = EFI_UNSUPPORTED; FUNC_ENTRY(Handle->TeeHandle); status = ResetHeciInterface(Handle); FUNC_EXIT(Handle->TeeHandle, status); return status; } EFI_STATUS EfiTeeHeciFwStatus( IN struct METEE_EFI_IMPL *Handle, IN UINT32 fwStatusNum, OUT UINT32 *fwStatus) { UINT64 HeciMemBar; EFI_STATUS status = EFI_UNSUPPORTED; UINT32 FwStatusOffset = 0; FUNC_ENTRY(Handle->TeeHandle); FwStatusOffset = Handle->Hw.FwStatus.FW_STS[fwStatusNum]; EFIPRINT(Handle->TeeHandle, "Reading FW_STS%d at offset 0x%d\n", fwStatusNum, FwStatusOffset); if (Handle->Hw.FwStatus.ResidesInConfigSpace) { *fwStatus = PciSegmentRead32(HeciPciCfgBase(Handle) + FwStatusOffset); } else { HeciMemBar = CheckAndFixHeciForAccess(Handle); EFIPRINT(Handle->TeeHandle, "Base 0x%p\n", HeciMemBar); if (HeciMemBar == 0) { status = EFI_DEVICE_ERROR; goto End; } *fwStatus = MmioRead32(HeciMemBar + FwStatusOffset); } status = EFI_SUCCESS; End: FUNC_EXIT(Handle->TeeHandle, status); return status; } EFI_STATUS EfiTeeHeciGetTrc( IN struct METEE_EFI_IMPL *Handle, OUT UINT32 *trcVal) { EFI_STATUS status = EFI_UNSUPPORTED; UINT64 HeciMemBar = 0; FUNC_ENTRY(Handle->TeeHandle); HeciMemBar = CheckAndFixHeciForAccess(Handle); EFIPRINT(Handle->TeeHandle, "Base 0x%p\n", HeciMemBar); if (HeciMemBar == 0) { DBGPRINT(Handle->TeeHandle, "CheckAndFixHeciForAccess failed\n"); status = EFI_DEVICE_ERROR; goto End; } *trcVal = MmioRead32(HeciMemBar + Handle->Hw.TrcOffset); status = EFI_SUCCESS; End: FUNC_EXIT(Handle->TeeHandle, status); return status; } EFI_STATUS EfiTeeHeciUninitialize( IN struct METEE_EFI_IMPL *Handle) { EFI_STATUS status = EFI_UNSUPPORTED; HBM_CLIENT_DISCONNECT_REQUEST disconnectMsg; HBM_CLIENT_DISCONNECT_RESPONSE disconnectMsgReply; UINT32 msgReplyLen = 0; HECI_CLIENT_CONNECTION *client = &Handle->HeciClientConnection; struct HeciDeviceLibrary * lib = NULL; FUNC_ENTRY(Handle->TeeHandle); DBGPRINT(Handle->TeeHandle, "####Heci Uninitialize ####\n"); lib = GetHeciLibrary(&Handle->Hw.Bdf); if (lib != NULL) { DBGPRINT(Handle->TeeHandle, "Release Host Client Id: %d\n", client->HostClientId); lib->State.HostClientIds[client->HostClientId] = 0; } if (client->properties.FixedAddress != 0) { DBGPRINT(Handle->TeeHandle, "######CONNECTION CLOSED SUCCESSFULLY######: Fixed client\n"); status = EFI_SUCCESS; goto End; } if (client->connected == FALSE) { DBGPRINT(Handle->TeeHandle, "Handle is not connected\n"); status = EFI_SUCCESS; goto End; } SetMem(&disconnectMsg, sizeof(disconnectMsg), 0x0); SetMem(&disconnectMsgReply, sizeof(disconnectMsgReply), 0x0); disconnectMsg.Command = CLIENT_DISCONNECT_REQ_CMD; disconnectMsg.MEAddress = client->properties.Address; disconnectMsg.HostAddress = client->HostClientId; DBGPRINT(Handle->TeeHandle, "####Prior to Heci-SendMsg: Command: %02X, Host Client Id: %d, FW Client Id: %d\n", disconnectMsg.Command, disconnectMsg.HostAddress, disconnectMsg.MEAddress); status = heciSendMsg(Handle, (UINT32 *)&disconnectMsg, (UINT32)sizeof(disconnectMsg), (UINT8)BIOS_FIXED_HOST_ADDR, (UINT8)HECI_HBM_MSG_ADDR); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "####Failed to send HBM_CLIENT_DISCONNECT_REQUEST. Status: %llu\n", (unsigned long long)status); goto End; } status = heciReadMsg(Handle, BLOCKING, (UINT32 *)&disconnectMsgReply, sizeof(disconnectMsgReply), &msgReplyLen); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "####Failed with ReadMsg, Status: %llu.\n", (unsigned long long)status); goto End; } DBGPRINT(Handle->TeeHandle, "#### disconnectMsgReply Command %02X , Status: %02X.\n", disconnectMsgReply.Command, disconnectMsgReply.Status); if (CLIENT_DISCONNECT_RES_CMD != disconnectMsgReply.Command) { DBGPRINT(Handle->TeeHandle, "####Unexpected disconnect message reply command\n"); status = EFI_PROTOCOL_ERROR; goto End; } if (0 != disconnectMsgReply.Status) { DBGPRINT(Handle->TeeHandle, "####Unexpected disconnect message reply status\n"); status = EFI_PROTOCOL_ERROR; goto End; } DBGPRINT(Handle->TeeHandle, "####SUCCESSFULLY DISCONNECT FROM INTERFACE####\n"); status = EFI_SUCCESS; End: client->connected = FALSE; client->HostClientId = 0; FUNC_EXIT(Handle->TeeHandle, status); return status; } static EFI_STATUS heciFwToHostFlowControl( IN struct METEE_EFI_IMPL *Handle, IN HECI_CLIENT_CONNECTION *client) { EFI_STATUS status = EFI_UNSUPPORTED; HBM_FLOW_CONTROL flowCtrlMsg; UINT32 msgLen = 0; FUNC_ENTRY(Handle->TeeHandle); DBGPRINT(Handle->TeeHandle, "####FW to Host flow control####\n"); if (NULL == client) { status = EFI_INVALID_PARAMETER; goto End; } if (client->properties.FixedAddress != 0) { DBGPRINT(Handle->TeeHandle, "####Fixed: Exiting FW to Host flow control####\n"); status = EFI_SUCCESS; goto End; } DBGPRINT(Handle->TeeHandle, "####First get flow control from FW\n"); SetMem(&flowCtrlMsg, msgLen, 0x0); status = heciReadMsg(Handle, BLOCKING, (UINT32 *)&flowCtrlMsg, sizeof(HBM_FLOW_CONTROL), &msgLen); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "#####Flow control: wait for FW failed with status: %llu.\n", (unsigned long long)status); goto End; } End: DBGPRINT(Handle->TeeHandle, "####Exiting FW to Host flow control####\n"); FUNC_EXIT(Handle->TeeHandle, status); return status; } static EFI_STATUS heciHostToSecFlowControl( IN struct METEE_EFI_IMPL *Handle, IN HECI_CLIENT_CONNECTION *client, IN UINT8 secAddress) { EFI_STATUS status = EFI_UNSUPPORTED; HBM_FLOW_CONTROL flowCtrlMsg; FUNC_ENTRY(Handle->TeeHandle); DBGPRINT(Handle->TeeHandle, "####Host to Sec flow control####\n"); if (NULL == client) { status = EFI_INVALID_PARAMETER; goto End; } if (client->properties.FixedAddress != 0) { DBGPRINT(Handle->TeeHandle, "####Fixed: Exiting Host to Sec flow control####\n"); status = EFI_SUCCESS; goto End; } // Send flow control to FW SetMem(&flowCtrlMsg, sizeof(flowCtrlMsg), 0x0); flowCtrlMsg.Command = FLOW_CONTROL_CMD; flowCtrlMsg.HostAddress = client->HostClientId; flowCtrlMsg.MEAddress = secAddress; status = heciSendMsg(Handle, (UINT32 *)&flowCtrlMsg, sizeof(flowCtrlMsg), BIOS_FIXED_HOST_ADDR, HECI_HBM_MSG_ADDR); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "#####Flow control: send to FW failed with status: %llu.\n", (unsigned long long)status); goto End; } End: DBGPRINT(Handle->TeeHandle, "####Exiting Host to FW flow control####\n"); FUNC_EXIT(Handle->TeeHandle, status); return status; } static EFI_STATUS HeciDeviceEnumerateClients( IN struct METEE_EFI_IMPL *Handle, IN OUT struct HeciDeviceLibrary * HeciLib ) { EFI_STATUS status = EFI_UNSUPPORTED; HBM_HOST_ENUMERATION_REQUEST enumMsg; HBM_HOST_ENUMERATION_RESPONSE enumMsgReply; HBM_CLIENT_PROP_MSG propMsg; HBM_CLIENT_PROP_MSG_REPLY propMsgReply; UINT32 msgReplyLen = 0; FUNC_ENTRY(Handle->TeeHandle); if (HeciLib->State.IsValid) { status = EFI_SUCCESS; goto End; } // will make all open handles invalid HeciLib->State.ResetGeneration += 1; status = heciReset(Handle); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Failed to send HECI reset. Status: %llu\n", (unsigned long long)status); status = EFI_DEVICE_ERROR; goto End; } SetMem(HeciLib->State.HostClientIds, sizeof(HeciLib->State.HostClientIds), 0x0); SetMem(HeciLib->State.Clients, sizeof(HeciLib->State.Clients), 0x0); SetMem(&enumMsg, sizeof(enumMsg), 0x0); SetMem(&enumMsgReply, sizeof(enumMsgReply), 0x0); enumMsg.Command = HOST_ENUM_REQ_CMD; for (UINT32 i = 0; i < MAX_CONNECT_RETRIES; ++i) { DBGPRINT(Handle->TeeHandle, "HECI connect client attempt %u.\n", i); status = heciSendMsg(Handle, (UINT32 *)&enumMsg, sizeof(enumMsg), BIOS_FIXED_HOST_ADDR, HECI_HBM_MSG_ADDR); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Failed to send HBM_HOST_ENUMERATION_REQUEST.\n"); goto End; } status = heciReadMsg(Handle, BLOCKING, (UINT32 *)&enumMsgReply, sizeof(HBM_HOST_ENUMERATION_RESPONSE), &msgReplyLen); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Failed to read HBM_HOST_ENUMERATION_REQUEST. Status: %llu\n", (unsigned long long)status); if (EFI_TIMEOUT == status) { continue; } goto End; } break; // efiStatus is EFI_SUCCESS } if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Failed to read HBM_HOST_ENUMERATION_REQUEST. Status: %llu.\n", (unsigned long long)status); goto End; } DBGPRINT(Handle->TeeHandle, "HBM_HOST_ENUMERATION_RESPONSE: [Command: %d]\n", enumMsgReply.Command); if (enumMsgReply.Command != HOST_ENUM_RES_CMD) { DBGPRINT(Handle->TeeHandle, "HBM enum got invalid reply: %u\n", enumMsgReply.Command); status = EFI_PROTOCOL_ERROR; goto End; } #define TEE_CLIENTS_IS_CLIENT_EXIST(bitmap, inx) ((bitmap[inx / 8] & (1 << (inx % 8))) != 0) SetMem(&propMsg, sizeof(propMsg), 0x0); propMsg.Command = HOST_CLIENT_PROPERTIES_REQ_CMD; for (UINT16 enumIdx = 1; enumIdx < TEE_MAX_FW_CLIENTS; ++enumIdx) { if (!TEE_CLIENTS_IS_CLIENT_EXIST(enumMsgReply.ValidAddresses, enumIdx)) { continue; } propMsg.Address = (UINT8)enumIdx; status = heciSendMsg(Handle, (UINT32 *)&propMsg, sizeof(propMsg), BIOS_FIXED_HOST_ADDR, HECI_HBM_MSG_ADDR); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Failed to send HBM_CLIENT_PROP_MSG. Status: %llu\n", (unsigned long long)status); goto End; } SetMem(&propMsgReply, sizeof(HBM_CLIENT_PROP_MSG_REPLY), 0x0); status = heciReadMsg(Handle, BLOCKING, (UINT32 *)&propMsgReply, sizeof(HBM_CLIENT_PROP_MSG_REPLY), &msgReplyLen); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "heciReadMsg failed to read HBM_CLIENT_PROP_MSG response. Status: %llu\n", (unsigned long long)status); goto End; } if (propMsgReply.CmdReply != HOST_CLIENT_PROPERTIES_RES_CMD) { DBGPRINT(Handle->TeeHandle, "Not HBM_CLIENT_PROP_MSG response command: %d\n", propMsgReply.CmdReply); goto End; } if (propMsgReply.Status != 0) { DBGPRINT(Handle->TeeHandle, "propMsgReply.Status: %d\n", propMsgReply.Status); continue; } HeciLib->State.Clients[enumIdx].IsValid = TRUE; HeciLib->State.Clients[enumIdx].ClientProperties.ProtocolName = propMsgReply.ProtocolName; HeciLib->State.Clients[enumIdx].ClientProperties.ProtocolVersion = propMsgReply.ProtocolVersion; HeciLib->State.Clients[enumIdx].ClientProperties.Address = propMsgReply.Address; HeciLib->State.Clients[enumIdx].ClientProperties.SingleReceiveBuffer = propMsgReply.SingleRecvBuffer; HeciLib->State.Clients[enumIdx].ClientProperties.MaxMessageLength = propMsgReply.MaxMessageLength; HeciLib->State.Clients[enumIdx].ClientProperties.FixedAddress = propMsgReply.FixedAddress; HeciLib->State.Clients[enumIdx].ClientProperties.MaxNumberOfConnections = propMsgReply.MaximumConnections; DBGPRINT(Handle->TeeHandle, "####:%u - Guid:%08x-%04x-%04x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x.\n", enumIdx, propMsgReply.ProtocolName.Data1, propMsgReply.ProtocolName.Data2, propMsgReply.ProtocolName.Data3, propMsgReply.ProtocolName.Data4[0], propMsgReply.ProtocolName.Data4[1], propMsgReply.ProtocolName.Data4[2], propMsgReply.ProtocolName.Data4[3], propMsgReply.ProtocolName.Data4[4], propMsgReply.ProtocolName.Data4[5], propMsgReply.ProtocolName.Data4[6], propMsgReply.ProtocolName.Data4[7]); } HeciLib->State.IsValid = TRUE; status = EFI_SUCCESS; End: FUNC_EXIT(Handle->TeeHandle, status); return status; } EFI_STATUS EfiTeeHeciConnectClient( IN struct METEE_EFI_IMPL *Handle) { EFI_STATUS status = EFI_UNSUPPORTED; HBM_CLIENT_CONNECT_REQUEST connectMsg; HBM_CLIENT_CONNECT_RESPONSE connectMsgReply; UINT32 msgReplyLen; UINT32 ind; UINT32 host_client_id; HECI_CLIENT_CONNECTION *client = &Handle->HeciClientConnection; struct HeciDeviceLibrary * lib = NULL; FUNC_ENTRY(Handle->TeeHandle); if (client->connected) { DBGPRINT(Handle->TeeHandle, "Already connected\n"); // TODO check Win impl status = EFI_UNSUPPORTED; goto End; } lib = GetHeciLibrary(&Handle->Hw.Bdf); if (lib == NULL) { DBGPRINT(Handle->TeeHandle, "Increase CONF_HECI_MAX_HECI_DEVICES_IN_THE_SYSTEM value\n"); status = EFI_OUT_OF_RESOURCES; goto End; } status = HeciDeviceEnumerateClients(Handle, lib); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Could not HeciDeviceEnumerateClients, Status: %llu\n", (unsigned long long)status); status = EFI_DEVICE_ERROR; goto End; } SetMem(&client->properties, sizeof(client->properties), 0x0); for (ind=0; ind<TEE_MAX_FW_CLIENTS; ++ind) { if (CompareMem(&Handle->ClientGuid, &lib->State.Clients[ind].ClientProperties.ProtocolName, sizeof(GUID)) == 0) { DBGPRINT(Handle->TeeHandle, "#### Match\n"); DBGPRINT(Handle->TeeHandle, "Ind: %d , Address: %u, ProtocolVersion: %u, MaximumConnections: %u, FixedAddress: %u, SingleRecvBuffer: %u, MaxMessageLength: %u.\n", ind, lib->State.Clients[ind].ClientProperties.Address, lib->State.Clients[ind].ClientProperties.ProtocolVersion, lib->State.Clients[ind].ClientProperties.MaxNumberOfConnections, lib->State.Clients[ind].ClientProperties.FixedAddress, lib->State.Clients[ind].ClientProperties.SingleReceiveBuffer, lib->State.Clients[ind].ClientProperties.MaxMessageLength); break; } } if (ind == TEE_MAX_FW_CLIENTS) { DBGPRINT(Handle->TeeHandle, "FW client not found\n"); status = EFI_NOT_FOUND; goto End; } /* find first available Host Client Id */ for (host_client_id=1; host_client_id<TEE_MAX_FW_CLIENTS; ++host_client_id) { if (lib->State.HostClientIds[host_client_id] == 0) { DBGPRINT(Handle->TeeHandle, "Host Client Id: %d\n", host_client_id); break; } } if (host_client_id == TEE_MAX_FW_CLIENTS) { DBGPRINT(Handle->TeeHandle, "Max client count reached\n"); status = EFI_DEVICE_ERROR; goto End; } if (lib->State.Clients[ind].ClientProperties.FixedAddress != 0) { DBGPRINT(Handle->TeeHandle, "######Fixed client######\n"); client->properties.Address = lib->State.Clients[ind].ClientProperties.FixedAddress; status = EFI_SUCCESS; goto Connected; } /* Now try to connect to the heci interface. */ SetMem(&connectMsg, sizeof(connectMsg), 0x0); SetMem(&connectMsgReply, sizeof(connectMsgReply), 0x0); connectMsg.Command = CLIENT_CONNECT_REQ_CMD; connectMsg.MEAddress = lib->State.Clients[ind].ClientProperties.Address; connectMsg.HostAddress = (UINT8)host_client_id; EFIPRINT(Handle->TeeHandle, "Before CLIENT_CONNECT_REQ_CMD\n"); status = heciSendMsg(Handle, (UINT32 *)&connectMsg, sizeof(connectMsg), BIOS_FIXED_HOST_ADDR, HECI_HBM_MSG_ADDR); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Connect Send failed with status: %llu.\n", (unsigned long long)status); goto End; } status = heciReadMsg(Handle, BLOCKING, (UINT32 *)&connectMsgReply, sizeof(HBM_CLIENT_CONNECT_RESPONSE), &msgReplyLen); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Connect Recv failed with status: %llu.\n", (unsigned long long)status); goto End; } if (connectMsgReply.Command != CLIENT_CONNECT_RES_CMD) { DBGPRINT(Handle->TeeHandle, "Connect got invalid reply: %u\n", connectMsgReply.Command); goto End; } DBGPRINT(Handle->TeeHandle, "Connect message reply status: %d\n", connectMsgReply.Status); if ((CCS_SUCCESS == connectMsgReply.Status) || (CCS_ALREADY_STARTED == connectMsgReply.Status)) { DBGPRINT(Handle->TeeHandle, "######CONNECTION SETUP SUCCESSFULLY######\n"); } else { DBGPRINT(Handle->TeeHandle, "####Failed to setup connection.\n"); status = EFI_PROTOCOL_ERROR; goto End; } status = heciFwToHostFlowControl(Handle, client); if (EFI_ERROR(status)) { goto End; } Connected: lib->State.HostClientIds[host_client_id] = 1; client->properties = lib->State.Clients[ind].ClientProperties; client->connected = TRUE; client->ResetGeneration = lib->State.ResetGeneration; client->HostClientId = (UINT8)host_client_id; DBGPRINT(Handle->TeeHandle, "Connection established: Host Client Id: %d, FW Client Id: %d\n", client->HostClientId, lib->State.Clients[ind].ClientProperties.Address); End: FUNC_EXIT(Handle->TeeHandle, status); return status; } EFI_STATUS EfiTeeHeciSendMessage( IN struct METEE_EFI_IMPL *Handle, IN const UINT8 *buffer, IN UINT32 bufferLength, OUT UINT32 *BytesWritten, IN UINT32 timeout) { EFI_STATUS status = EFI_UNSUPPORTED; UINT8 fwAddress = 0; UINT8 hostAddress = 0; struct HeciDeviceLibrary * lib = NULL; HECI_CLIENT_CONNECTION *client = &Handle->HeciClientConnection; FUNC_ENTRY(Handle->TeeHandle); if ((NULL == buffer) || (0 == bufferLength) || (BytesWritten == NULL)) { status = EFI_INVALID_PARAMETER; goto End; } if (bufferLength > client->properties.MaxMessageLength) { status = EFI_BUFFER_TOO_SMALL; goto End; } if (client->connected == FALSE) { DBGPRINT(Handle->TeeHandle, "Handle is not connected\n"); status = EFI_MEDIA_CHANGED; goto End; } lib = GetHeciLibrary(&Handle->Hw.Bdf); if (lib == NULL) { DBGPRINT(Handle->TeeHandle, "Library not found\n"); status = EFI_OUT_OF_RESOURCES; goto End; } if (lib->State.IsValid == FALSE) { DBGPRINT(Handle->TeeHandle, "Library is invalid, LR required, Handle will become invalid\n"); Handle->HeciClientConnection.connected = FALSE; status = EFI_MEDIA_CHANGED; goto End; } if (Handle->HeciClientConnection.ResetGeneration != lib->State.ResetGeneration) { DBGPRINT(Handle->TeeHandle, "Handle is invalid, %d %d\n", Handle->HeciClientConnection.ResetGeneration, lib->State.ResetGeneration); Handle->HeciClientConnection.connected = FALSE; status = EFI_MEDIA_CHANGED; goto End; } fwAddress = client->properties.Address; status = heciHostToSecFlowControl(Handle, client, fwAddress); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "heciHostToSecFlowControl Failed. Status: %llu", (unsigned long long)status); goto End; } // Fixed Address expects HostAddress to be 0 hostAddress = (client->properties.FixedAddress != 0) ? BIOS_FIXED_HOST_ADDR : client->HostClientId; EFIPRINT(Handle->TeeHandle, "bufferLength: %d, Host Client Id: %d, FW Client Id: %d\n", bufferLength, hostAddress, fwAddress); status = heciSendMsg(Handle, (UINT32 *)buffer, bufferLength, hostAddress, fwAddress); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "SendMessage: failed to send message. Status: %llu.", (unsigned long long)status); goto End; } *BytesWritten = bufferLength; status = EFI_SUCCESS; End: FUNC_EXIT(Handle->TeeHandle, status); return status; } EFI_STATUS EfiTeeHeciReceiveMessage( IN struct METEE_EFI_IMPL *Handle, OUT UINT8 *Buffer, IN UINT32 BufferSize, OUT UINT32 *NumOfBytesRead, IN UINT32 timeout) { EFI_STATUS status = EFI_UNSUPPORTED; HECI_CLIENT_CONNECTION *client = &Handle->HeciClientConnection; UINT32 bytes_read = 0; UINT8 messageId = 0; FUNC_ENTRY(Handle->TeeHandle); if ((Buffer == NULL) || (0 == BufferSize) || (NumOfBytesRead == NULL)) { status = EFI_INVALID_PARAMETER; goto End; } if (BufferSize > client->properties.MaxMessageLength) { status = EFI_INVALID_PARAMETER; goto End; } if (client->connected == FALSE) { DBGPRINT(Handle->TeeHandle, "Handle is not connected\n"); status = EFI_MEDIA_CHANGED; goto End; } DBGPRINT(Handle->TeeHandle, "\nprintout client properties\n"); DBGPRINT(Handle->TeeHandle, "properties.guid:%x-%x-%x-%x-%x-%x-%x-%x-%x-%x-%x\n", client->properties.ProtocolName.Data1, client->properties.ProtocolName.Data2, client->properties.ProtocolName.Data3, client->properties.ProtocolName.Data4[0], client->properties.ProtocolName.Data4[1], client->properties.ProtocolName.Data4[2], client->properties.ProtocolName.Data4[3], client->properties.ProtocolName.Data4[4], client->properties.ProtocolName.Data4[5], client->properties.ProtocolName.Data4[6], client->properties.ProtocolName.Data4[7]); DBGPRINT(Handle->TeeHandle, "properties.ProtocolVersion: %d\n", client->properties.ProtocolVersion); DBGPRINT(Handle->TeeHandle, "properties.MaxNumberOfConnections: %d\n", client->properties.MaxNumberOfConnections); DBGPRINT(Handle->TeeHandle, "properties.Address: %d\n", client->properties.Address); DBGPRINT(Handle->TeeHandle, "properties.SingleReceiveBuffer: %x\n", client->properties.SingleReceiveBuffer); DBGPRINT(Handle->TeeHandle, "properties.MaxMessageLength: %d\n", client->properties.MaxMessageLength); DBGPRINT(Handle->TeeHandle, "properties.FixedAddress: %d\n", client->properties.FixedAddress); DBGPRINT(Handle->TeeHandle, "handle: %x\n", client->handle); SetMem(Buffer, BufferSize, 0x0); status = heciReadMsg(Handle, BLOCKING, (UINT32 *)Buffer, BufferSize, &bytes_read); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "\nReadMsg: first reply read failed. bytesRead: %d. Status: %llu\n", bytes_read, (unsigned long long)status); goto End; } // Currently the EFI HECI wrapper does not seem to differentiate between client responses // directed to the client connection, and flow control responses directed to the host driver. // Because of this limitation, we have to filter out flow control messages. This creates a // limitation on the HECI client responses. We have to be careful not to expect a message with // size HECI_FLOW_CTRL_MSG_LEN and response type FLOW_CONTROL_CMD. messageId = Buffer[0]; if ((HECI_FLOW_CTRL_MSG_LEN == bytes_read) && (FLOW_CONTROL_CMD == messageId)) { // The first reply message we get is flow control from FW. SetMem(Buffer, BufferSize, 0x0); status = heciReadMsg(Handle, BLOCKING, (UINT32 *)Buffer, BufferSize, &bytes_read); if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "heciReadMsg. Status: %llu\n", (unsigned long long)status); if (EFI_TIMEOUT == status) { DBGPRINT(Handle->TeeHandle, "Detected EFI_TIMEOUT.\n"); gBS->Stall(HECI_TIMEOUT_STALL_SEC); SetMem(Buffer, BufferSize, 0x0); status = heciReadMsg(Handle, BLOCKING, (UINT32 *)Buffer, BufferSize, &bytes_read); } if (EFI_ERROR(status)) { DBGPRINT(Handle->TeeHandle, "Retry failed. Status: %llu\n", (unsigned long long)status); goto End; } } *NumOfBytesRead = bytes_read; status = EFI_SUCCESS; goto End; } *NumOfBytesRead = bytes_read; // Continue to recv flow control message #define HECI1_DEVICE 0 if (HECI1_DEVICE == Handle->Hw.Bdf.Function) { EFIPRINT(Handle->TeeHandle, "FixedAddress: %d\n", client->properties.FixedAddress); status = heciFwToHostFlowControl(Handle, client); DBGPRINT(Handle->TeeHandle, "heciFwToHostFlowControl. Status: %llu\n", (unsigned long long)status); goto End; } status = EFI_SUCCESS; End: FUNC_EXIT(Handle->TeeHandle, status); return status; } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/uefi/heci_efi.h�������������������������������������������������������������0000664�0000000�0000000�00000001624�15201331742�0017710�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024-2025 Intel Corporation */ #ifndef HECI_EFI_H_ #define HECI_EFI_H_ #include "metee_efi.h" EFI_STATUS EfiTeeHeciConnectClient( IN struct METEE_EFI_IMPL *Handle); EFI_STATUS EfiTeeHeciReceiveMessage( IN struct METEE_EFI_IMPL *Handle, OUT UINT8 *Buffer, IN UINT32 BufferSize, OUT UINT32 *NumOfBytesRead, IN UINT32 timeout); EFI_STATUS EfiTeeHeciSendMessage( IN struct METEE_EFI_IMPL *Handle, IN const UINT8 *buffer, IN UINT32 bufferLength, OUT UINT32 *BytesWritten, IN UINT32 timeout); EFI_STATUS EfiTeeHeciFwStatus( IN struct METEE_EFI_IMPL *Handle, IN UINT32 fwStatusNum, OUT UINT32 *fwStatus); EFI_STATUS EfiTeeHeciGetTrc( IN struct METEE_EFI_IMPL *Handle, OUT UINT32 *trcVal); EFI_STATUS EfiTeeHeciUninitialize( IN struct METEE_EFI_IMPL *Handle); #endif // HECI_EFI_H_������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/uefi/metee_efi.c������������������������������������������������������������0000664�0000000�0000000�00000052331�15201331742�0020073�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024-2026 Intel Corporation */ #ifdef METEE_EFI_STDLIB_SUPPORT #include <stdio.h> #endif #include <Uefi.h> #include <Library/UefiLib.h> #include <Library/BaseLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/BaseMemoryLib.h> #include <Library/PrintLib.h> #include <Library/UefiBootServicesTableLib.h> #include <Library/UefiRuntimeServicesTableLib.h> #include "metee.h" #include "metee_efi.h" #include "heci_efi.h" #include "helpers.h" static inline struct METEE_EFI_IMPL *to_int(PTEEHANDLE _h) { return _h ? (struct METEE_EFI_IMPL *)_h->handle : NULL; } #define DEFAULT_OFFSET_H_CB_WW 0x0 #define DEFAULT_OFFSET_H_CSR 0x4 #define DEFAULT_OFFSET_ME_CB_RW 0x8 #define DEFAULT_OFFSET_ME_CSR_HA 0xC #define FW_STS1 0x40 #define FW_STS2 0x48 #define FW_STS3 0x60 #define FW_STS4 0x64 #define FW_STS5 0x68 #define FW_STS6 0x6C #define GSC_FSTS_OFF 0xC00 static struct HECI_HW HwInfoPch( IN UINT32 segment, IN UINT32 bus, IN UINT32 device, IN UINT32 function) { #define ME_TRC 0x30 struct HECI_HW hw_info = { {/* Bdf */ segment, bus, device, function}, {/* RegisterOffset */ DEFAULT_OFFSET_H_CB_WW, DEFAULT_OFFSET_H_CSR, DEFAULT_OFFSET_ME_CB_RW, DEFAULT_OFFSET_ME_CSR_HA, 0x0}, {/* FwStatus */ {FW_STS1, FW_STS2, FW_STS3, FW_STS4, FW_STS5, FW_STS6}, TRUE}, ME_TRC, }; return hw_info; } static struct HECI_HW HwInfoGfxGsc( IN UINT32 segment, IN UINT32 bus, IN UINT32 device, IN UINT32 function) { #define GFX_GSC_BASE_ADDRESS_OFFSET 0x374000 struct HECI_HW hw_info = { {/* Bdf */ segment, bus, device, function}, {/* RegisterOffset */ DEFAULT_OFFSET_H_CB_WW, DEFAULT_OFFSET_H_CSR, DEFAULT_OFFSET_ME_CB_RW, DEFAULT_OFFSET_ME_CSR_HA, GFX_GSC_BASE_ADDRESS_OFFSET}, {/* FwStatus */ {GSC_FSTS_OFF | FW_STS1, GSC_FSTS_OFF | FW_STS2, GSC_FSTS_OFF | FW_STS3, GSC_FSTS_OFF | FW_STS4, GSC_FSTS_OFF | FW_STS5, GSC_FSTS_OFF | FW_STS6}, FALSE}, 0x0, }; return hw_info; } void CallbackPrintHelper(IN PTEEHANDLE handle, bool is_error, const char* args, ...) { char msg[DEBUG_MSG_LEN + 1]; VA_LIST varl; VA_START(varl, args); #ifdef METEE_EFI_STDLIB_SUPPORT vsnprintf(msg, DEBUG_MSG_LEN, args, varl); #else AsciiVSPrint(msg, DEBUG_MSG_LEN, args, varl); #endif VA_END(varl); handle->log_callback2(is_error, msg); } static TEESTATUS SetHwInfo( IN const struct tee_device_address *device, OUT struct METEE_EFI_IMPL *Handle) { TEESTATUS status = TEE_INVALID_PARAMETER; FUNC_ENTRY(Handle->TeeHandle); switch (device->data.bdf.hw_type) { case HECI_HW_TYPE_PCH: Handle->Hw = HwInfoPch(device->data.bdf.value.segment, device->data.bdf.value.bus, device->data.bdf.value.device, device->data.bdf.value.function); DBGPRINT(Handle->TeeHandle, "******** HECI_HW_TYPE_PCH\n"); break; case HECI_HW_TYPE_GFX_GSC: Handle->Hw = HwInfoGfxGsc(device->data.bdf.value.segment, device->data.bdf.value.bus, device->data.bdf.value.device, device->data.bdf.value.function); DBGPRINT(Handle->TeeHandle, "******** HECI_HW_TYPE_GFX_GSC\n"); break; default: DBGPRINT(Handle->TeeHandle, "******** Unsupported device kind %d\n", device->data.bdf.hw_type); status = TEE_INVALID_PARAMETER; goto End; } status = TEE_SUCCESS; End: FUNC_EXIT(Handle->TeeHandle, status); return status; } /*! Initializes TEE_DEVICE_TYPE_BDF connection specific properties * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device HECI device Bus Device Function * \param impl_handle pointer to place where to store internal handle pointer * \return 0 if successful, otherwise error code */ static TEESTATUS TeeInitFullTypeEfiDevice( IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const struct tee_device_address *device, OUT void **impl_handle) { TEESTATUS status = TEE_INTERNAL_ERROR; struct METEE_EFI_IMPL *efi_impl = NULL; FUNC_ENTRY(handle); efi_impl = (struct METEE_EFI_IMPL *)AllocateZeroPool(sizeof(struct METEE_EFI_IMPL)); if (efi_impl == NULL) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "Can't allocate memory for internal struct"); goto Cleanup; } efi_impl->TeeHandle = handle; efi_impl->ClientGuid = *guid; efi_impl->State = METEE_CLIENT_STATE_NONE; efi_impl->HwType = device->data.bdf.hw_type; status = SetHwInfo(device, efi_impl); if (status != TEE_SUCCESS) { FreePool(efi_impl); goto Cleanup; } *impl_handle = efi_impl; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } /*! Initializes a TEE connection * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device device address structure * \param log_level log level to set (from enum tee_log_level) * \param log_callback pointer to function to run for log write, set NULL to use built-in function (deprecated) * \param log_callback2 pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code */ static TEESTATUS TeeInitFullInt( IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const struct tee_device_address device, IN uint32_t log_level, IN TeeLogCallback log_callback, IN TeeLogCallback2 log_callback2 ) { TEESTATUS status = TEE_INTERNAL_ERROR; struct tee_device_address default_device = device; if (NULL == guid) { return TEE_INVALID_PARAMETER; } if (handle == NULL) { return TEE_INVALID_PARAMETER; } __tee_init_handle(handle); handle->log_level = (log_level >= TEE_LOG_LEVEL_MAX) ? TEE_LOG_LEVEL_VERBOSE : log_level; handle->log_callback = log_callback; handle->log_callback2 = log_callback2; FUNC_ENTRY(handle); if (log_level >= TEE_LOG_LEVEL_MAX) { ERRPRINT(handle, "LogLevel %u is too big.\n", log_level); status = TEE_INVALID_PARAMETER; goto Cleanup; } switch (device.type) { case TEE_DEVICE_TYPE_NONE: if ( device.data.bdf.value.segment != 0 || device.data.bdf.value.bus != 0 || device.data.bdf.value.device != 0 || device.data.bdf.value.function != 0) { ERRPRINT(handle, "BDF is set.\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } // CSME HECI by default #define PCI_DEVICE_NUMBER_PCH_HECI1 22 default_device.data.bdf.hw_type = HECI_HW_TYPE_PCH; default_device.data.bdf.value.segment = 0; default_device.data.bdf.value.bus = 0; default_device.data.bdf.value.device = PCI_DEVICE_NUMBER_PCH_HECI1; default_device.data.bdf.value.function = 0; status = TeeInitFullTypeEfiDevice(handle, guid, &default_device, &handle->handle); if (TEE_SUCCESS != status) { goto Cleanup; } break; case TEE_DEVICE_TYPE_BDF: status = TeeInitFullTypeEfiDevice(handle, guid, &device, &handle->handle); if (TEE_SUCCESS != status) { goto Cleanup; } break; default: ERRPRINT(handle, "Wrong device type %u.\n", device.type); status = TEE_INVALID_PARAMETER; goto Cleanup; break; } Cleanup: if (TEE_SUCCESS != status) { if (handle->handle) { FreePool(handle->handle); } } FUNC_EXIT(handle, status); return status; } TEESTATUS TEEAPI TeeInitFull(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback log_callback) { return TeeInitFullInt(handle, guid, device, log_level, log_callback, NULL); } TEESTATUS TEEAPI TeeInitFull2(IN OUT PTEEHANDLE handle, IN const GUID* guid, IN const struct tee_device_address device, IN uint32_t log_level, IN OPTIONAL TeeLogCallback2 log_callback) { return TeeInitFullInt(handle, guid, device, log_level, NULL, log_callback); } /*! Initializes a TEE connection * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device optional device path, set NULL to use default * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeInit(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN OPTIONAL const char *device) { return TEE_NOTSUPPORTED; } /*! Initializes a TEE connection * \param handle A handle to the TEE device. All subsequent calls to the lib's functions * must be with this handle * \param guid GUID of the FW client that want to start a session * \param device_handle open file handle * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeInitHandle(IN OUT PTEEHANDLE handle, IN const GUID *guid, IN const TEE_DEVICE_HANDLE device_handle) { return TEE_NOTSUPPORTED; } /*! Connects to the TEE driver and starts a session * \param handle A handle to the TEE device * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeConnect(OUT PTEEHANDLE handle) { struct METEE_EFI_IMPL *impl_handle = to_int(handle); TEESTATUS status; EFI_STATUS efi_status; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto Cleanup; } if (impl_handle->State == METEE_CLIENT_STATE_CONNECTED) { status = TEE_INTERNAL_ERROR; ERRPRINT(handle, "The client is already connected\n"); goto Cleanup; } efi_status = EfiTeeHeciConnectClient(impl_handle); if (EFI_ERROR(efi_status)) { switch (efi_status) { case EFI_NO_RESPONSE: status = TEE_DEVICE_NOT_READY; break; case EFI_PROTOCOL_ERROR: status = TEE_UNABLE_TO_COMPLETE_OPERATION; break; case EFI_NOT_FOUND: status = TEE_CLIENT_NOT_FOUND; break; default: status = TEE_INTERNAL_ERROR; break; } goto Cleanup; } impl_handle->State = METEE_CLIENT_STATE_CONNECTED; handle->maxMsgLen = impl_handle->HeciClientConnection.properties.MaxMessageLength; handle->protcolVer = impl_handle->HeciClientConnection.properties.ProtocolVersion; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } /*! Read data from the TEE device synchronously. * \param handle The handle of the session to read from. * \param buffer A pointer to a buffer that receives the data read from the TEE device. * \param bufferSize The number of bytes to be read. * \param pNumOfBytesRead A pointer to the variable that receives the number of bytes read, * ignored if set to NULL. * \param timeout The timeout to complete read in milliseconds, zero for infinite * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeRead(IN PTEEHANDLE handle, IN OUT void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *pNumOfBytesRead, IN OPTIONAL uint32_t timeout) { struct METEE_EFI_IMPL *impl_handle = to_int(handle); TEESTATUS status; EFI_STATUS efi_status; UINT32 bytesRead = 0; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); // EfiTeeHeciReceiveMessage works only with uint32_t if (NULL == impl_handle || NULL == buffer || 0 == bufferSize || bufferSize > 0xFFFFFFFF) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto End; } if (impl_handle->State != METEE_CLIENT_STATE_CONNECTED) { status = TEE_DISCONNECTED; ERRPRINT(handle, "The client is not connected\n"); goto End; } efi_status = EfiTeeHeciReceiveMessage(impl_handle, buffer, (UINT32)bufferSize, &bytesRead, timeout); if (EFI_ERROR(efi_status)) { if (efi_status == EFI_MEDIA_CHANGED) { status = TEE_DISCONNECTED; } else { status = TEE_INTERNAL_ERROR; } goto End; } if (pNumOfBytesRead != NULL) { *pNumOfBytesRead = bytesRead; } status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } /*! Writes the specified buffer to the TEE device synchronously. * \param handle The handle of the session to write to. * \param buffer A pointer to the buffer containing the data to be written to the TEE device. * \param bufferSize The number of bytes to be written. * \param numberOfBytesWritten A pointer to the variable that receives the number of bytes written, * ignored if set to NULL. * \param timeout The timeout to complete write in milliseconds, zero for infinite * \return 0 if successful, otherwise error code */ TEESTATUS TEEAPI TeeWrite(IN PTEEHANDLE handle, IN const void *buffer, IN size_t bufferSize, OUT OPTIONAL size_t *numberOfBytesWritten, IN OPTIONAL uint32_t timeout) { struct METEE_EFI_IMPL *impl_handle = to_int(handle); TEESTATUS status; EFI_STATUS efi_status; UINT32 bytesWritten = 0; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); // EfiTeeHeciSendMessage works only with uint32_t if (NULL == impl_handle || NULL == buffer || 0 == bufferSize || bufferSize > 0xFFFFFFFF) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal"); goto End; } if (impl_handle->State != METEE_CLIENT_STATE_CONNECTED) { status = TEE_DISCONNECTED; ERRPRINT(handle, "The client is not connected"); goto End; } efi_status = EfiTeeHeciSendMessage(impl_handle, buffer, (UINT32)bufferSize, &bytesWritten, timeout); if (EFI_ERROR(efi_status)) { if (efi_status == EFI_MEDIA_CHANGED) { status = TEE_DISCONNECTED; } else { status = TEE_INTERNAL_ERROR; } goto End; } if (numberOfBytesWritten != NULL) { *numberOfBytesWritten = bytesWritten; } status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } /*! Retrieves specified FW status register. * \param handle The handle of the session. * \param fwStatusNum The FW status register number (0-5). * \param fwStatus The memory to store obtained FW status. * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeFWStatus(IN PTEEHANDLE handle, IN uint32_t fwStatusNum, OUT uint32_t *fwStatus) { TEESTATUS status; EFI_STATUS efi_status; struct METEE_EFI_IMPL *impl_handle = to_int(handle); if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == fwStatus) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto End; } if (fwStatusNum >= HECI_FW_STS_COUNT) { status = TEE_INVALID_PARAMETER; goto End; } efi_status = EfiTeeHeciFwStatus(impl_handle, fwStatusNum, fwStatus); if (EFI_ERROR(efi_status)) { status = TEE_INTERNAL_ERROR; goto End; } status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } /*! Retrieves TRC register. * \param handle The handle of the session. * \param trc_val The memory to store obtained TRC value. * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeGetTRC(IN PTEEHANDLE handle, OUT uint32_t *trc_val) { TEESTATUS status; EFI_STATUS efi_status; struct METEE_EFI_IMPL *impl_handle = to_int(handle); if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == trc_val) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal\n"); goto End; } if (impl_handle->Hw.TrcOffset == 0x0) { status = TEE_NOTSUPPORTED; goto End; } efi_status = EfiTeeHeciGetTrc(impl_handle, trc_val); if (EFI_ERROR(efi_status)) { status = TEE_INTERNAL_ERROR; goto End; } status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } /*! Closes the session to TEE driver * Make sure that you call this function as soon as you are done with the device, * as other clients might be blocked until the session is closed. * \param handle The handle of the session to close. */ void TEEAPI TeeDisconnect(IN PTEEHANDLE handle) { struct METEE_EFI_IMPL *impl_handle = to_int(handle); if (NULL == handle) { return; } FUNC_ENTRY(handle); if (NULL == impl_handle) { goto Cleanup; } EfiTeeHeciUninitialize(impl_handle); FreePool(impl_handle); impl_handle = NULL; Cleanup: FUNC_EXIT(handle, 0); } /*! Returns handle of TEE device * Obtains HECI device handle on Windows and mei device file descriptor on Linux * \param handle The handle of the session. * \return device handle */ TEE_DEVICE_HANDLE TEEAPI TeeGetDeviceHandle(IN PTEEHANDLE handle) { return TEE_INVALID_DEVICE_HANDLE; } /*! Obtains version of the TEE device driver * Not implemented on Linux * \param handle The handle of the session. * \param driverVersion Pointer to driver version struct * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI GetDriverVersion(IN PTEEHANDLE handle, IN OUT teeDriverVersion_t *driverVersion) { return TEE_NOTSUPPORTED; } /*! Set log level * * \param handle The handle of the session. * \param log_level log level to set * \return previous log level */ uint32_t TEEAPI TeeSetLogLevel(IN PTEEHANDLE handle, IN uint32_t log_level) { uint32_t prev_log_level = TEE_LOG_LEVEL_QUIET; if (NULL == handle) { return prev_log_level; } FUNC_ENTRY(handle); prev_log_level = handle->log_level; handle->log_level = (log_level > TEE_LOG_LEVEL_VERBOSE) ? TEE_LOG_LEVEL_VERBOSE : log_level; FUNC_EXIT(handle, prev_log_level); return prev_log_level; } /*! Retrieve current log level * * \param handle The handle of the session. * \return current log level */ uint32_t TEEAPI TeeGetLogLevel(IN const PTEEHANDLE handle) { uint32_t prev_log_level = TEE_LOG_LEVEL_QUIET; if (NULL == handle) { return prev_log_level; } FUNC_ENTRY(handle); prev_log_level = handle->log_level; FUNC_EXIT(handle, prev_log_level); return prev_log_level; } /*! Set log callback * @deprecated Since version 6.0 * \param handle The handle of the session. * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeSetLogCallback(IN const PTEEHANDLE handle, TeeLogCallback log_callback) { struct METEE_EFI_IMPL *impl_handle = to_int(handle); TEESTATUS status; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal"); goto Cleanup; } if (handle->log_callback2) { ERRPRINT(handle, "Standard callback already in use\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } handle->log_callback = log_callback; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } /*! Set log callback * * \param handle The handle of the session. * \param log_callback pointer to function to run for log write, set NULL to use built-in function * \return 0 if successful, otherwise error code. */ TEESTATUS TEEAPI TeeSetLogCallback2(IN const PTEEHANDLE handle, TeeLogCallback2 log_callback) { struct METEE_EFI_IMPL *impl_handle = to_int(handle); TEESTATUS status; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); if (NULL == impl_handle) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal"); goto Cleanup; } if (handle->log_callback) { ERRPRINT(handle, "Legacy callback already in use\n"); status = TEE_INVALID_PARAMETER; goto Cleanup; } handle->log_callback2 = log_callback; status = TEE_SUCCESS; Cleanup: FUNC_EXIT(handle, status); return status; } uint32_t TEEAPI TeeGetMaxMsgLen(IN const PTEEHANDLE handle) { if (NULL == handle) { return 0; } return (uint32_t)handle->maxMsgLen; } uint8_t TEEAPI TeeGetProtocolVer(IN const PTEEHANDLE handle) { if (NULL == handle) { return 0; } return handle->protcolVer; } typedef enum TEEDRIVER_PLATFORM_KIND_ { TEEDRIVER_PLATFORM_KIND_MEI = 0, TEEDRIVER_PLATFORM_KIND_IOE = 1, TEEDRIVER_PLATFORM_KIND_GSC = 2, TEEDRIVER_PLATFORM_KIND_MAX = 3, } TEEDRIVER_PLATFORM_KIND; #define HECI1_IOE_SKU_BIT_START 0 #define HECI1_IOE_SKU_BIT_NUMS 4 #define HECI1_IOE_SKU_BIT_MASK (((1 << HECI1_IOE_SKU_BIT_NUMS) - 1) << HECI1_IOE_SKU_BIT_START) #define HECI1_IOE_SKU 0x1 #define HECI1_FW_STS3 2 TEESTATUS TEEAPI TeeGetKind(IN PTEEHANDLE handle, IN OUT char *kind, IN OUT size_t *kindSize) { CHAR8* propertyMap[TEEDRIVER_PLATFORM_KIND_MAX] = { "mei", "ioe", "gscfi", }; TEESTATUS status; EFI_STATUS efi_status; UINT32 fw_sts3; UINT32 kind_ind = 0; UINTN kind_len; if (NULL == handle) { return TEE_INVALID_PARAMETER; } FUNC_ENTRY(handle); struct METEE_EFI_IMPL *impl_handle = to_int(handle); if (NULL == impl_handle || NULL == kindSize) { status = TEE_INVALID_PARAMETER; ERRPRINT(handle, "One of the parameters was illegal"); goto End; } if (impl_handle->HwType == HECI_HW_TYPE_PCH) { efi_status = EfiTeeHeciFwStatus(impl_handle, HECI1_FW_STS3, &fw_sts3); if (EFI_ERROR(efi_status)) { ERRPRINT(handle, "Failed to retrieve FW Status %d\n", efi_status); status = TEE_INTERNAL_ERROR; goto End; } kind_ind = ((fw_sts3 & HECI1_IOE_SKU_BIT_MASK) == HECI1_IOE_SKU) ? TEEDRIVER_PLATFORM_KIND_IOE : TEEDRIVER_PLATFORM_KIND_MEI; } else { kind_ind = TEEDRIVER_PLATFORM_KIND_GSC; } kind_len = AsciiStrLen(propertyMap[kind_ind]) + 1; if (kind_len > *kindSize || NULL == kind) { DBGPRINT(handle, "Insufficient buffer %d %d\n", *kindSize, kind_len); *kindSize = kind_len; status = TEE_INSUFFICIENT_BUFFER; goto End; } CopyMem(kind, propertyMap[kind_ind], kind_len); *kindSize = kind_len; status = TEE_SUCCESS; End: FUNC_EXIT(handle, status); return status; } void TEEAPI TeeCancelIO(IN PTEEHANDLE handle) { }�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/uefi/metee_efi.h������������������������������������������������������������0000664�0000000�0000000�00000012660�15201331742�0020101�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024 Intel Corporation */ #ifndef METEE_EFI_H_ #define METEE_EFI_H_ enum METEE_CLIENT_STATE { METEE_CLIENT_STATE_NONE, METEE_CLIENT_STATE_CONNECTED, METEE_CLIENT_STATE_FAILED }; #define MAX_CONNECT_RETRIES 3 #define HECI_FLOW_CTRL_MSG_LEN 8 /** * HECI HW Section */ /** * HECI addresses and defines */ /** * register bits - H_CSR */ #define H_CBD 0xFF000000 /** Host Circular Buffer Depth */ #define H_CBWP 0x00FF0000 /** Host Circular Buffer Write Pointer */ #define H_CBRP 0x0000FF00 /** Host Circular Buffer Read Pointer */ #define H_RST 0x00000010 /** Host Reset */ #define H_RDY 0x00000008 /** Host Ready */ #define H_IG 0x00000004 /** Host Interrupt Generate */ #define H_IS 0x00000002 /** Host Interrupt Status */ #define H_IE 0x00000001 /** Host Interrupt Enable */ /** * register bits - ME_CSR_HA */ #define ME_CBD_HRA 0xFF000000 /** ME Circular Buffer Depth Host Read Access */ #define ME_CBWP_HRA 0x00FF0000 /** ME Circular Buffer Write Pointer Host Read Access */ #define ME_CBRP_HRA 0x0000FF00 /** ME Circular Buffer Read Pointer Host Read Access */ #define ME_RST_HRA 0x00000010 /** ME Reset Host Read Access */ #define ME_RDY_HRA 0x00000008 /** ME Ready Host Read Access */ #define ME_IG_HRA 0x00000004 /** ME Interrupt Generate Host Read Access */ #define ME_IS_HRA 0x00000002 /** ME Interrupt Status Host Read Access */ #define ME_IE_HRA 0x00000001 /** ME Interrupt Enable Host Read Access */ /** * HECI BUS Interface Section */ #define HOST_ENUM_REQ_CMD 0x04 #define HOST_ENUM_RES_CMD 0x84 #define HOST_CLIENT_PROPERTIES_REQ_CMD 0x05 #define HOST_CLIENT_PROPERTIES_RES_CMD 0x85 #define CLIENT_CONNECT_REQ_CMD 0x06 #define CLIENT_CONNECT_RES_CMD 0x86 #define CLIENT_DISCONNECT_REQ_CMD 0x07 #define CLIENT_DISCONNECT_RES_CMD 0x87 #define FLOW_CONTROL_CMD 0x08 #pragma pack(1) typedef struct _HBM_HOST_ENUMERATION_REQUEST { UINT8 Command; UINT8 ClientReqBits; UINT8 Reserved[2]; } HBM_HOST_ENUMERATION_REQUEST; typedef struct _HBM_HOST_ENUMERATION_RESPONSE { UINT8 Command; UINT8 Reserved[3]; UINT8 ValidAddresses[32]; } HBM_HOST_ENUMERATION_RESPONSE; typedef struct _HBM_CLIENT_CONNECT_REQUEST { UINT8 Command; UINT8 MEAddress; UINT8 HostAddress; UINT8 Reserved; } HBM_CLIENT_CONNECT_REQUEST; typedef struct _HBM_CLIENT_CONNECT_RESPONSE { UINT8 Command; UINT8 MEAddress; UINT8 HostAddress; UINT8 Status; } HBM_CLIENT_CONNECT_RESPONSE; typedef struct _HBM_CLIENT_DISCONNECT_REQUEST { UINT8 Command; UINT8 MEAddress; UINT8 HostAddress; UINT8 Reserved[1]; } HBM_CLIENT_DISCONNECT_REQUEST; typedef struct _HBM_CLIENT_DISCONNECT_RESPONSE { UINT8 Command; UINT8 MEAddress; UINT8 HostAddress; UINT8 Status; UINT32 Pad; } HBM_CLIENT_DISCONNECT_RESPONSE; typedef enum _CLIENT_CONNECT_STATUS { CCS_SUCCESS = 0x00, CCS_ALREADY_STARTED = 0x02, } CLIENT_CONNECT_STATUS; typedef struct _HBM_FLOW_CONTROL { UINT8 Command; UINT8 MEAddress; UINT8 HostAddress; UINT8 Reserved[5]; } HBM_FLOW_CONTROL; typedef struct _HECI_CLIENT_PROPERTIES { GUID ProtocolName; UINT8 ProtocolVersion; UINT8 MaxNumberOfConnections; UINT8 Address; UINT8 SingleReceiveBuffer; UINT32 MaxMessageLength; UINT8 FixedAddress; } HECI_CLIENT_PROPERTIES; typedef struct _HECI_CLIENT_CONNECTION { HECI_CLIENT_PROPERTIES properties; UINT32 ResetGeneration; /** Should match device Link Reset */ UINT32 handle; BOOLEAN connected; UINT8 HostClientId; } HECI_CLIENT_CONNECTION; #pragma pack() #define HECI_FW_STS_COUNT 6 struct HECI_HW_BDF { UINT32 Segment; /** HECI device Segment */ UINT32 Bus; /** HECI device Bus */ UINT32 Device; /** HECI device Device */ UINT32 Function; /** HECI device Function */ }; struct HECI_HW { struct HECI_HW_BDF Bdf; struct RegisterOffset { UINT32 H_CB_WW; /** Host Circular Buffer Write Window */ UINT32 H_CSR; /** Host Control Status */ UINT32 ME_CB_RW; /** ME Circular Buffer Read Window */ UINT32 ME_CSR_HA; /** ME Control Status Host Access */ UINT32 BaseAddressOffset; /** HECI registers offset inside device MMIO */ } RegisterOffset; struct FwStatus { UINT32 FW_STS[HECI_FW_STS_COUNT]; /** FW status registers offsets */ BOOLEAN ResidesInConfigSpace; /** FW status resides in config space or MMIO */ } FwStatus; UINT32 TrcOffset; /** TRC register offset */ }; struct _TEEHANDLE; struct METEE_EFI_IMPL { struct _TEEHANDLE *TeeHandle; GUID ClientGuid; /** Client GUID */ enum METEE_CLIENT_STATE State; /** The client state */ HECI_CLIENT_CONNECTION HeciClientConnection; /** HECI EFI Connection information */ struct HECI_HW Hw; /** HECI HW information */ enum HECI_HW_TYPE HwType; /** HECI HW type */ }; #define HECI_EFI_PRINT_BDF_STR "[HECI %d:%d:%d:%d] " #define HECI_EFI_PRINT_BDF_VAL Handle->Hw.Bdf.Segment, Handle->Hw.Bdf.Bus, Handle->Hw.Bdf.Device, Handle->Hw.Bdf.Function #define EFIPRINT(Handle, fmt, ...) DBGPRINT(Handle, HECI_EFI_PRINT_BDF_STR fmt, HECI_EFI_PRINT_BDF_VAL, ##__VA_ARGS__); #endif // METEE_EFI_H_ ��������������������������������������������������������������������������������intel-metee-67ff323/src/uefi/pci_utils.c������������������������������������������������������������0000664�0000000�0000000�00000004266�15201331742�0020150�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024 Intel Corporation */ #include <Uefi.h> #include <Library/BaseLib.h> #include <Library/UefiLib.h> #include <Library/PciSegmentLib.h> #include <IndustryStandard/Pci22.h> #include "metee.h" #include "metee_efi.h" #include "heci_efi.h" #include "helpers.h" /** Get HECI controller address that can be passed to the PCI Segment Library functions. @param[in] Handle The HECI Handle to be accessed. @retval HECI controller address in PCI Segment Library representation **/ UINT64 HeciPciCfgBase( IN struct METEE_EFI_IMPL *Handle) { return PCI_SEGMENT_LIB_ADDRESS( Handle->Hw.Bdf.Segment, Handle->Hw.Bdf.Bus, Handle->Hw.Bdf.Device, Handle->Hw.Bdf.Function, 0); } /** This function provides a standard way to verify the HECI cmd and MBAR regs in its PCI cfg space are setup properly. @param[in] Handle The HECI Handle to be accessed. @retval HeciMemBar HECI Memory BAR. 0 - invalid BAR value returned. **/ UINT64 CheckAndFixHeciForAccess( IN struct METEE_EFI_IMPL *Handle) { UINT64 HeciBaseAddress; UINT64 MemBar; UINT32 LowPart; UINT64 HiPart; #define B_PCI_BAR_MEMORY_TYPE_64 0x4 HeciBaseAddress = HeciPciCfgBase(Handle); if (HeciBaseAddress == 0) { EFIPRINT(Handle->TeeHandle, "HeciPciCfgBase is 0\n"); return 0; } EFIPRINT(Handle->TeeHandle, "HeciBaseAddress 0x%p\n", HeciBaseAddress); /// /// Check for HECI PCI device availability /// if (PciSegmentRead16(HeciBaseAddress + PCI_DEVICE_ID_OFFSET) == 0xFFFF) { EFIPRINT(Handle->TeeHandle, "is not enabled in this phase\n"); return 0; } LowPart = PciSegmentRead32(HeciBaseAddress + PCI_BASE_ADDRESSREG_OFFSET); HiPart = (UINT64)PciSegmentRead32(HeciBaseAddress + (PCI_BASE_ADDRESSREG_OFFSET + 4)); MemBar = LowPart & 0xFFFFFFF0; if ((LowPart & B_PCI_BAR_MEMORY_TYPE_64) == B_PCI_BAR_MEMORY_TYPE_64) { MemBar += LShiftU64(HiPart, 32); } if (MemBar == 0) { EFIPRINT(Handle->TeeHandle, "MMIO Bar for isn't programmed in this phase\n"); return 0; } /// /// Enable HECI MSE /// PciSegmentOr8(HeciBaseAddress + PCI_COMMAND_OFFSET, EFI_PCI_COMMAND_MEMORY_SPACE); return MemBar + Handle->Hw.RegisterOffset.BaseAddressOffset; } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/src/uefi/pci_utils.h������������������������������������������������������������0000664�0000000�0000000�00000001474�15201331742�0020153�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2024 Intel Corporation */ #ifndef HECI_PCI_UTILS_H_ #define HECI_PCI_UTILS_H_ struct METEE_EFI_IMPL; #include <Uefi.h> /** Get HECI controller address that can be passed to the PCI Segment Library functions. @param[in] Handle The HECI Handle to be accessed. @retval HECI controller address in PCI Segment Library representation **/ UINT64 HeciPciCfgBase( IN struct METEE_EFI_IMPL *Handle); /** This function provides a standard way to verify the HECI cmd and MBAR regs in its PCI cfg space are setup properly. @param[in] Handle The HECI Handle to be accessed. @retval HeciMemBar HECI Memory BAR. 0 - invalid BAR value returned. **/ UINT64 CheckAndFixHeciForAccess( IN struct METEE_EFI_IMPL *Handle); #endif // HECI_PCI_UTILS_H_����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/��������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15201331742�0015424�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/AMTHI.h�������������������������������������������������������������������0000664�0000000�0000000�00000004412�15201331742�0016440�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2019 Intel Corporation */ #ifndef __AMTHI_H #define __AMTHI_H #include <windows.h> static const UINT32 BIOS_VERSION_LEN = 65; static const UINT32 VERSIONS_NUMBER = 50; static const UINT32 UNICODE_STRING_LEN = 20; typedef unsigned int PT_STATUS; typedef unsigned int AMT_STATUS; #pragma pack(1) typedef struct _AMT_UNICODE_STRING { UINT16 Length; UINT8 String[UNICODE_STRING_LEN]; } AMT_UNICODE_STRING; typedef struct _AMT_VERSION_TYPE { AMT_UNICODE_STRING Description; AMT_UNICODE_STRING Version; }AMT_VERSION_TYPE; typedef struct _PTHI_VERSION { UINT8 MajorNumber; UINT8 MinorNumber; } PTHI_VERSION; typedef struct _CODE_VERSIONS { UINT8 BiosVersion[BIOS_VERSION_LEN]; UINT32 VersionsCount; AMT_VERSION_TYPE Versions[VERSIONS_NUMBER]; } CODE_VERSIONS; typedef struct _COMMAND_FMT { union { UINT32 val; struct { UINT32 Operation : 23; UINT32 IsResponse : 1; UINT32 Class : 8; } fields; } cmd; } COMMAND_FMT; typedef struct _AMT_ANSI_STRING { UINT16 Length; CHAR* Buffer; }AMT_ANSI_STRING; typedef struct _PTHI_MESSAGE_HEADER { PTHI_VERSION Version; UINT16 Reserved; COMMAND_FMT Command; UINT32 Length; } PTHI_MESSAGE_HEADER; typedef struct _CFG_GET_CODE_VERSIONS_RESPONSE { PTHI_MESSAGE_HEADER Header; AMT_STATUS Status; CODE_VERSIONS CodeVersions; } CFG_GET_CODE_VERSIONS_RESPONSE; const UINT32 CODE_VERSIONS_REQUEST = 0x0400001A; const UINT32 CODE_VERSIONS_RESPONSE = 0x0480001A; const PTHI_MESSAGE_HEADER GET_CODE_VERSION_HEADER = { {1,1},0,{CODE_VERSIONS_REQUEST},0 }; typedef struct { UINT8 Command; UINT8 ByteCount; UINT8 SubCommand; UINT8 VersionNumber; } AMT_GetMngMacAddress_Request; typedef struct { UINT8 Command; UINT8 ByteCount; UINT8 SubCommand; UINT8 VersionNumber; AMT_STATUS Status; UINT8 Address[6]; // returned upon success only } AMT_GetMngMacAddress_Response; #pragma pack() #endif������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/CMakeLists.txt������������������������������������������������������������0000664�0000000�0000000�00000003610�15201331742�0020164�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2014-2025 Intel Corporation cmake_minimum_required(VERSION 3.15) project(metee_test) set(CMAKE_CXX_STANDARD 11) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest-src) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/googletest-src DESTINATION ${CMAKE_CURRENT_BINARY_DIR} ) else(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest-src) # Download and unpack googletest at configure time configure_file(gtest.cmake.in googletest-download/CMakeLists.txt) execute_process( COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) if(result) message(FATAL_ERROR "CMake step for googletest failed: ${result}") endif() execute_process( COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) if(result) message(FATAL_ERROR "Build step for googletest failed: ${result}") endif() endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest-src) # Prevent overriding the parent project's compiler/linker settings on Windows set(gtest_force_shared_crt ON CACHE BOOL "" FORCE ) # Add googletest directly to our build. This defines the gtest and gtest_main # targets. add_subdirectory( ${CMAKE_CURRENT_BINARY_DIR}/googletest-src ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL ) add_executable(${PROJECT_NAME} Main.cpp metee_test.cpp meteepp_test.cpp $<$<BOOL:${WIN32}>:${CMAKE_SOURCE_DIR}/src/Windows/metee_winhelpers.c> ) if(NOT CONSOLE_OUTPUT) target_compile_definitions(${PROJECT_NAME} PRIVATE -DSYSLOG) endif() target_link_libraries(${PROJECT_NAME} metee gtest_main gmock_main) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/Windows ) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) ������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/MKHI.h��������������������������������������������������������������������0000664�0000000�0000000�00000003555�15201331742�0016335�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2019 Intel Corporation */ #pragma pack(1) #define GEN_GET_MKHI_VERSION_CMD 0x01 #define GEN_GET_FW_VERSION_CMD 0x02 // Typedef for GroupID typedef enum { MKHI_CBM_GROUP_ID = 0, MKHI_PM_GROUP_ID, MKHI_PWD_GROUP_ID, MKHI_FWCAPS_GROUP_ID, MKHI_APP_GROUP_ID, // Reserved (no longer used). MKHI_FWUPDATE_GROUP_ID, // This is for manufacturing downgrade MKHI_FIRMWARE_UPDATE_GROUP_ID, MKHI_BIST_GROUP_ID, MKHI_MDES_GROUP_ID, MKHI_ME_DBG_GROUP_ID, MKHI_MAX_GROUP_ID, MKHI_GEN_GROUP_ID = 0xFF }MKHI_GROUP_ID; //MKHI host message header. This header is part of HECI message sent from MEBx via //Host Configuration Interface (HCI). ME Configuration Manager or Power Configuration //Manager also include this header with appropriate fields set as part of the //response message to the HCI. typedef union _MKHI_MESSAGE_HEADER { uint32_t Data; struct { uint32_t GroupId : 8; uint32_t Command : 7; uint32_t IsResponse : 1; uint32_t Reserved : 8; uint32_t Result : 8; }Fields; }MKHI_MESSAGE_HEADER; static_assert(sizeof(MKHI_MESSAGE_HEADER) == 4, "MKHI header should be 4 bytes exactly!"); typedef struct _GEN_GET_FW_VERSION { MKHI_MESSAGE_HEADER Header; }GEN_GET_FW_VERSION; typedef struct _FW_VERSION { uint32_t CodeMinor : 16; uint32_t CodeMajor : 16; uint32_t CodeBuildNo : 16; uint32_t CodeHotFix : 16; uint32_t NFTPMinor : 16; uint32_t NFTPMajor : 16; uint32_t NFTPBuildNo : 16; uint32_t NFTPHotFix : 16; }FW_VERSION; typedef struct _GET_FW_VERSION_ACK_DATA { FW_VERSION FWVersion; }GET_FW_VERSION_ACK_DATA; typedef struct _GEN_GET_FW_VERSION_ACK { MKHI_MESSAGE_HEADER Header; GET_FW_VERSION_ACK_DATA Data; }GEN_GET_FW_VERSION_ACK; DEFINE_GUID(GUID_DEVINTERFACE_MKHI, 0x8e6a6715, 0x9abc, 0x4043, 0x88, 0xef, 0x9e, 0x39, 0xc6, 0xf6, 0x3e, 0x0f); #pragma pack()���������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/Main.cpp������������������������������������������������������������������0000664�0000000�0000000�00000000340�15201331742�0017011�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2019 Intel Corporation */ #include "metee_test.h" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/gtest.cmake.in������������������������������������������������������������0000664�0000000�0000000�00000001024�15201331742�0020156�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2014-2022 Intel Corporation cmake_minimum_required(VERSION 3.1) project(googletest-download NONE) include(ExternalProject) ExternalProject_Add(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG release-1.12.1 SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" ) ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/metee_test.cpp������������������������������������������������������������0000664�0000000�0000000�00000046423�15201331742�0020277�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2025 Intel Corporation */ #include <vector> #include <chrono> #include <thread> #include <climits> #include <fstream> #include "metee_test.h" #ifdef WIN32 extern "C" { #include "public.h" #include "metee_win.h" } #endif // WIN32 DEFINE_GUID(GUID_NON_EXISTS_CLIENT, 0x85eb8fa6, 0xbdd, 0x4d01, 0xbe, 0xc4, 0xa5, 0x97, 0x43, 0x4e, 0xd7, 0x62); #define CONNECT_RETRIES 3 void TEEAPI CompletionRoutine(TEESTATUS status, size_t numberOfBytesTransfered) { std::cout << "operation ended with status " << status << ". Num bytes transferred " << numberOfBytesTransfered << std::endl; } #define SUCCESS TEE_SUCCESS // Retrieve the system error message for the last-error code #ifdef WIN32 std::string GetErrorString(unsigned long LastError) { LPVOID lpMsgBuf; FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_IGNORE_INSERTS, L"%0", LastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpMsgBuf, 0, NULL); std::string ErrorMessage((LPCSTR)lpMsgBuf); ErrorMessage.erase(ErrorMessage.find('\n')); //error string from system comes with a new line character. return ErrorMessage; } #else std::string GetErrorString(unsigned long LastError) { return strerror(LastError); } #endif // WIN32 // Open MEI with default path #ifdef WIN32 void MeTeeFDTEST::OpenMEI() { DWORD status; char devicePath[MAX_PATH] = {0}; TEEHANDLE handle; __tee_init_handle(&handle); deviceHandle = TEE_INVALID_DEVICE_HANDLE; status = GetDevicePath(&handle, &GUID_DEVINTERFACE_HECI, devicePath, MAX_PATH); if (status) return; deviceHandle = CreateFileA(devicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); } void MeTeeFDTEST::CloseMEI() { CloseHandle(deviceHandle); } #else #define MEI_DEFAULT_DEVICE "/dev/mei0" #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> void MeTeeFDTEST::OpenMEI() { deviceHandle = open(MEI_DEFAULT_DEVICE, O_RDWR | O_CLOEXEC); } void MeTeeFDTEST::CloseMEI() { close(deviceHandle); } #endif // WIN32 TEESTATUS ConnectRetry(PTEEHANDLE handle) { TEESTATUS status; int retry = CONNECT_RETRIES; while (retry--) { status = TeeConnect(handle); if (status != TEE_BUSY && status != TEE_UNABLE_TO_COMPLETE_OPERATION) /* windows return this error on busy */ break; printf("Client is busy, retrying\n"); std::this_thread::sleep_for(std::chrono::seconds(2)); } return status; } /* Send GetVersion Command to HCI / MKHI 1) Open Connection to MKHI 2) Send GetVersion Req Command 3) Receive GetVersion Resp Command 4) Check for Valid Resp 5) Close Connection */ TEST_P(MeTeeDataNTEST, PROD_MKHI_SimpleGetVersion) { size_t NumberOfBytes = 0; std::vector <char> MaxResponse; GEN_GET_FW_VERSION_ACK* pResponseMessage; //max length for this client is 2048 MaxResponse.resize(TeeGetMaxMsgLen(&_handle) * sizeof(char)); ASSERT_EQ(SUCCESS, TeeWrite(&_handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), &NumberOfBytes, 0)); ASSERT_EQ(sizeof(GEN_GET_FW_VERSION), NumberOfBytes); ASSERT_EQ(SUCCESS, TeeRead(&_handle, &MaxResponse[0], TeeGetMaxMsgLen(&_handle), &NumberOfBytes, 0)); pResponseMessage = (GEN_GET_FW_VERSION_ACK*)(&MaxResponse[0]); ASSERT_EQ(SUCCESS, pResponseMessage->Header.Fields.Result); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeMajor); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeBuildNo); } TEST_P(MeTeeDataNTEST, PROD_MKHI_GetMaxMsgLen) { ASSERT_NE(0, TeeGetMaxMsgLen(&_handle)); } TEST_P(MeTeeDataNTEST, PROD_MKHI_GetProtocolVer) { TeeGetProtocolVer(&_handle); } /* Check too big timeouts on read and write */ TEST_P(MeTeeDataNTEST, PROD_MKHI_BadTimeout) { size_t NumberOfBytes = 0; char buf[10]; ASSERT_EQ(TEE_INVALID_PARAMETER, TeeWrite(&_handle, buf, 10, &NumberOfBytes, (uint32_t)INT_MAX + 1)); ASSERT_EQ(TEE_INVALID_PARAMETER, TeeRead(&_handle, buf, 10, &NumberOfBytes, (uint32_t)INT_MAX + 1)); } /* Set log level 1) Init metee handle 2) Get log level 3) Change log level 4) Check for valid log levels */ TEST_P(MeTeeOpenTEST, PROD_MKHI_SetLogLevel) { uint32_t orig_log_level, prev_log_level, new_log_level; orig_log_level = TeeGetLogLevel(&_handle); prev_log_level = TeeSetLogLevel(&_handle, TEE_LOG_LEVEL_VERBOSE); new_log_level = TeeGetLogLevel(&_handle); ASSERT_EQ(orig_log_level, prev_log_level); ASSERT_EQ(new_log_level, TEE_LOG_LEVEL_VERBOSE); prev_log_level = TeeSetLogLevel(&_handle, orig_log_level); ASSERT_EQ(prev_log_level, TEE_LOG_LEVEL_VERBOSE); new_log_level = TeeGetLogLevel(&_handle); ASSERT_EQ(orig_log_level, new_log_level); } void MeTeeTEST_Log(bool is_error, const char* fmt, ...) { EXPECT_EQ(is_error, true); EXPECT_STREQ(fmt, "TEELIB: (%s:%s():%d) TestTestTest"); } TEST_P(MeTeeOpenTEST, PROD_MKHI_SetLogCallback) { uint32_t prev_log_level; TEESTATUS status; prev_log_level = TeeSetLogLevel(&_handle, TEE_LOG_LEVEL_ERROR); status = TeeSetLogCallback(&_handle, MeTeeTEST_Log); EXPECT_EQ(SUCCESS, status); ERRPRINT(&_handle, "TestTestTest"); status = TeeSetLogCallback(&_handle, NULL); EXPECT_EQ(SUCCESS, status); ERRPRINT(&_handle, "NotReal"); TeeSetLogLevel(&_handle, prev_log_level); } TEST_P(MeTeeOpenTEST, PROD_MKHI_GetMaxMsgLen) { ASSERT_EQ(0, TeeGetMaxMsgLen(&_handle)); } TEST_P(MeTeeOpenTEST, PROD_MKHI_GetProtocolVer) { ASSERT_EQ(0, TeeGetProtocolVer(&_handle)); } /* * Blocking read from side thread cancelled by disconnect from the main thread */ TEST_P(MeTeeDataNTEST, PROD_MKHI_InterruptRead) { TEEHANDLE Handle = _handle; std::thread thr; thr = std::thread([Handle]() { std::vector <char> MaxResponse; size_t NumberOfBytes = 0; MaxResponse.resize(TeeGetMaxMsgLen((PTEEHANDLE) &Handle) * sizeof(char)); EXPECT_EQ(TEE_UNABLE_TO_COMPLETE_OPERATION, TeeRead((PTEEHANDLE) &Handle, &MaxResponse[0], TeeGetMaxMsgLen((PTEEHANDLE)&Handle), &NumberOfBytes, 0)); }); thr.detach(); std::this_thread::sleep_for(std::chrono::seconds(1)); } /* Send GetVersion Command to MKHI with timeout and fd > 1024 1) Open 2000 file descriptors 2) Open Connection to MKHI 3) Send GetVersion Req Command 4) Receive GetVersion Resp Command 5) Check for Valid Resp 6) Close Connection */ TEST_P(MeTee1000OpenTEST, PROD_MKHI_1000HandlesGetVersion) { TEEHANDLE Handle = TEEHANDLE_ZERO; size_t NumberOfBytes = 0; struct MeTeeTESTParams intf = GetParam(); std::vector <char> MaxResponse; GEN_GET_FW_VERSION_ACK* pResponseMessage; //max length for this client is 2048 TEESTATUS status; status = TestTeeInitGUID(&Handle, intf.client, intf.device); if (status == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); ASSERT_EQ(SUCCESS, status); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&Handle)); ASSERT_EQ(SUCCESS, ConnectRetry(&Handle)); MaxResponse.resize(TeeGetMaxMsgLen(&Handle) * sizeof(char)); ASSERT_EQ(SUCCESS, TeeWrite(&Handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), &NumberOfBytes, 1000)); ASSERT_EQ(sizeof(GEN_GET_FW_VERSION), NumberOfBytes); ASSERT_EQ(SUCCESS, TeeRead(&Handle, &MaxResponse[0], TeeGetMaxMsgLen(&Handle), &NumberOfBytes, 1000)); pResponseMessage = (GEN_GET_FW_VERSION_ACK*)(&MaxResponse[0]); ASSERT_EQ(SUCCESS, pResponseMessage->Header.Fields.Result); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeMajor); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeBuildNo); TeeDisconnect(&Handle); EXPECT_EQ(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&Handle)); } /* Send stress of GetVersion Command to HCI / MKHI 1) Open Connection to MKHI 2) Send GetVersion Req Command 3) Receive GetVersion Resp Command 4) Check for Valid Resp 5) Close Connection */ TEST_P(MeTeeDataNTEST, PROD_MKHI_SimpleGetVersionStress) { size_t NumberOfBytes = 0; std::vector <char> MaxResponse; GEN_GET_FW_VERSION_ACK* pResponseMessage; //max length for this client is 2048 MaxResponse.resize(TeeGetMaxMsgLen(&_handle) * sizeof(char)); for (unsigned int i = 0; i < 1000; i++) { ASSERT_EQ(SUCCESS, TeeWrite(&_handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), &NumberOfBytes, 0)); ASSERT_EQ(sizeof(GEN_GET_FW_VERSION), NumberOfBytes); ASSERT_EQ(SUCCESS, TeeRead(&_handle, &MaxResponse[0], TeeGetMaxMsgLen(&_handle), &NumberOfBytes, 0)); pResponseMessage = (GEN_GET_FW_VERSION_ACK*)(&MaxResponse[0]); ASSERT_EQ(SUCCESS, pResponseMessage->Header.Fields.Result); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeMajor); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeBuildNo); } } #ifndef WIN32 /* Send pending write stress 1) Connect to a client(MKHI) 2) Send stress of valid Write Command (async using TeeWrite) 3) Call Disconnect() */ TEST_P(MeTeeDataNTEST, PROD_MKHI_PendingWriteStress) { size_t NumberOfBytes = 0; for (unsigned int i = 0; i < 51; i++) EXPECT_EQ(SUCCESS, TeeWrite(&_handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), &NumberOfBytes, 1000)); for (unsigned int i = 0; i < 2; i++) EXPECT_EQ(TEE_TIMEOUT, TeeWrite(&_handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), &NumberOfBytes, 1000)); } #endif // not WIN32 TEST_P(MeTeeDataNTEST, PROD_MKHI_SimpleGetVersionNULLReturn) { std::vector <char> MaxResponse; GEN_GET_FW_VERSION_ACK* pResponseMessage; //max length for this client is 2048 MaxResponse.resize(TeeGetMaxMsgLen(&_handle) * sizeof(char)); ASSERT_EQ(SUCCESS, TeeWrite(&_handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), NULL, 0)); ASSERT_EQ(SUCCESS, TeeRead(&_handle, &MaxResponse[0], TeeGetMaxMsgLen(&_handle), NULL, 0)); pResponseMessage = (GEN_GET_FW_VERSION_ACK*)(&MaxResponse[0]); ASSERT_EQ(SUCCESS, pResponseMessage->Header.Fields.Result); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeMajor); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeBuildNo); } /* Wait for timeout on recv data without send 1) Open Connection to MKHI 2) Receive timeout on GetVersion Resp Command 3) Close Connection */ TEST_P(MeTeeDataNTEST, PROD_MKHI_TimeoutGetVersion) { size_t NumberOfBytes = 0; std::vector <char> MaxResponse; MaxResponse.resize(TeeGetMaxMsgLen(&_handle) * sizeof(char)); EXPECT_EQ(TEE_TIMEOUT, TeeRead(&_handle, &MaxResponse[0], TeeGetMaxMsgLen(&_handle), &NumberOfBytes, 1000)); } /* Obtain FW status 1) Receive FW status 2) Check for Valid Resp */ TEST_P(MeTeeOpenTEST, PROD_MKHI_GetFWStatus) { uint32_t fwStatusNum; uint32_t fwStatus; //FWSTS1 fwStatusNum = 0; ASSERT_EQ(SUCCESS, TeeFWStatus(&_handle, fwStatusNum, &fwStatus)); EXPECT_NE(0, fwStatus); //FWSTS2 fwStatusNum = 1; ASSERT_EQ(SUCCESS, TeeFWStatus(&_handle, fwStatusNum, &fwStatus)); EXPECT_NE(0, fwStatus); //Invalid input fwStatusNum = 6; ASSERT_EQ(TEE_INVALID_PARAMETER, TeeFWStatus(&_handle, fwStatusNum, &fwStatus)); fwStatusNum = UINT_MAX; ASSERT_EQ(TEE_INVALID_PARAMETER, TeeFWStatus(&_handle, fwStatusNum, &fwStatus)); fwStatusNum = 1; ASSERT_EQ(TEE_INVALID_PARAMETER, TeeFWStatus(NULL, fwStatusNum, &fwStatus)); ASSERT_EQ(TEE_INVALID_PARAMETER, TeeFWStatus(&_handle, fwStatusNum, NULL)); ASSERT_EQ(TEE_INVALID_PARAMETER, TeeFWStatus(NULL, fwStatusNum, NULL)); } /* * GetTRC API * 1) Receive TRC * 2) Check for bad input */ TEST_P(MeTeeOpenTEST, PROD_MKHI_GetTRC) { uint32_t trcVal; EXPECT_THAT(TeeGetTRC(&_handle, &trcVal), testing::AnyOf(testing::Eq(TEE_SUCCESS), testing::Eq(TEE_NOTSUPPORTED))); //Invalid input ASSERT_EQ(TEE_INVALID_PARAMETER, TeeGetTRC(NULL, &trcVal)); ASSERT_EQ(TEE_INVALID_PARAMETER, TeeGetTRC(&_handle, NULL)); } TEST_P(MeTeeOpenTEST, PROD_MKHI_DoubleConnect) { ASSERT_EQ(SUCCESS, ConnectRetry(&_handle)); ASSERT_EQ(TEE_INTERNAL_ERROR, ConnectRetry(&_handle)); } TEST_P(MeTeeOpenTEST, PROD_MKHI_WriteReadNoConnect) { size_t NumberOfBytes = 0; std::vector <char> MaxResponse; ASSERT_EQ(TEE_DISCONNECTED, TeeWrite(&_handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), &NumberOfBytes, 0)); MaxResponse.resize(1); ASSERT_EQ(TEE_DISCONNECTED, TeeRead(&_handle, &MaxResponse[0], 1, &NumberOfBytes, 0)); } TEST_P(MeTeeTEST, PROD_N_TestConnectToNullUuid) { TEEHANDLE handle = TEEHANDLE_ZERO; struct MeTeeTESTParams intf = GetParam(); ASSERT_EQ(TEE_INVALID_PARAMETER, TestTeeInitGUID(&handle, NULL, intf.device)); } TEST_P(MeTeeTEST, PROD_N_TestConnectToNonExistsUuid) { TEEHANDLE handle = TEEHANDLE_ZERO; struct MeTeeTESTParams intf = GetParam(); TEESTATUS status; status = TestTeeInitGUID(&handle, &GUID_NON_EXISTS_CLIENT, intf.device); if (status == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); ASSERT_EQ(TEE_SUCCESS, status); ASSERT_EQ(TEE_CLIENT_NOT_FOUND, ConnectRetry(&handle)); TeeDisconnect(&handle); EXPECT_EQ(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&handle)); } TEST_P(MeTeeTEST, PROD_N_TestLongDevicePath) { TEEHANDLE handle = TEEHANDLE_ZERO; const char *longPath = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; ASSERT_EQ(TEE_DEVICE_NOT_FOUND, TeeInit(&handle, &GUID_NON_EXISTS_CLIENT, longPath)); } TEST_P(MeTeeTEST, PROD_N_TestLongClientPath) { TEEHANDLE handle = TEEHANDLE_ZERO; struct MeTeeTESTParams intf = GetParam(); TEESTATUS status; const char *longPath = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; status = TestTeeInitGUID(&handle, (const GUID*)longPath, intf.device); if (status == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); ASSERT_EQ(TEE_SUCCESS, status); ASSERT_EQ(TEE_CLIENT_NOT_FOUND, ConnectRetry(&handle)); } TEST_P(MeTeeTEST, PROD_N_TestGetMeiKind) { TEEHANDLE handle = TEEHANDLE_ZERO; struct MeTeeTESTParams intf = GetParam(); char kind[64]; size_t kind_size = sizeof(kind); TEESTATUS status; status = TestTeeInitGUID(&handle, &GUID_NON_EXISTS_CLIENT, intf.device); ASSERT_EQ(TEE_SUCCESS, status); status = TeeGetKind(&handle, kind, &kind_size); ASSERT_TRUE(status == TEE_SUCCESS || status == TEE_NOTSUPPORTED); TeeDisconnect(&handle); EXPECT_EQ(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&handle)); } TEST_P(MeTeeOpenTEST, PROD_N_TestGetDriverVersion) { teeDriverVersion_t ver = {0, 0, 0, 0}; #ifdef WIN32 ASSERT_EQ(TEE_SUCCESS, GetDriverVersion(&_handle, &ver)); EXPECT_NE(ver.major, 0); // All other may be zero #else // WIN32 ASSERT_EQ(TEE_NOTSUPPORTED, GetDriverVersion(&_handle, &ver)); #endif // WIN32 } TEST_P(MeTeeOpenTEST, PROD_N_TestGetDriverVersion_NullParam) { ASSERT_EQ(TEE_INVALID_PARAMETER, GetDriverVersion(&_handle, NULL)); } #ifdef WIN32 TEST_P(MeTeeTEST, PROD_N_TestConnectByPath) { struct MeTeeTESTParams intf = GetParam(); TEESTATUS status; char devicePath[MAX_PATH] = {0}; TEEHANDLE handle; __tee_init_handle(&handle); status = GetDevicePath(&handle, (intf.device) ? intf.device : &GUID_DEVINTERFACE_HECI, devicePath, MAX_PATH); if (status) GTEST_SKIP(); ASSERT_EQ(TEE_SUCCESS, TeeInit(&handle, intf.client, devicePath)); TeeDisconnect(&handle); EXPECT_EQ(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&handle)); } #endif // WIN32 TEST_P(MeTeeTEST, PROD_N_TestConnectByWrongPath) { TEEHANDLE handle = TEEHANDLE_ZERO; ASSERT_EQ(TEE_DEVICE_NOT_FOUND, TeeInit(&handle, &GUID_NON_EXISTS_CLIENT, "\\NO_SUCH_DEVICE")); } TEST_P(MeTeeDataNTEST, PROD_N_TestFWUNullBufferWrite) { size_t numOfBytes = 0; ASSERT_EQ(TEE_INVALID_PARAMETER, TeeWrite(&_handle, NULL, 1024, &numOfBytes, 0)); } TEST_P(MeTeeDataNTEST, PROD_N_TestFWUZeroBufferSizeWrite) { size_t numOfBytes = 0; std::vector<unsigned char> buf(1024); ASSERT_EQ(TEE_INVALID_PARAMETER, TeeWrite(&_handle, &buf[0], 0, &numOfBytes, 0)); } TEST_P(MeTeeDataNTEST, PROD_N_TestFWUBiggerThenMtuWrite) { size_t numOfBytes = 0; std::vector<unsigned char> buf(TeeGetMaxMsgLen(&_handle) + 10); ASSERT_EQ(TEE_INTERNAL_ERROR, TeeWrite(&_handle, &buf[0], buf.size(), &numOfBytes, 0)); } #ifdef WIN32 TEST_P(MeTeeDataNTEST, PROD_N_TestSmallBufferRead) { size_t WriteNumberOfBytes = 0; size_t NumberOfBytes = 0; std::vector<char> MaxResponse; const size_t Len = 1; MaxResponse.resize(Len); ASSERT_EQ(SUCCESS, TeeWrite(&_handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), &WriteNumberOfBytes, 0)); ASSERT_EQ(sizeof(GEN_GET_FW_VERSION), WriteNumberOfBytes); ASSERT_EQ(TEE_INSUFFICIENT_BUFFER, TeeRead(&_handle, &MaxResponse[0], Len, &NumberOfBytes, 0)); } #endif // WIN32 TEST_P(MeTeeFDTEST, PROD_MKHI_SimpleGetVersion) { TEEHANDLE Handle = TEEHANDLE_ZERO; size_t NumberOfBytes = 0; struct MeTeeTESTParams intf = GetParam(); std::vector <char> MaxResponse; GEN_GET_FW_VERSION_ACK* pResponseMessage; //max length for this client is 2048 TEESTATUS status; status = TeeInitHandle(&Handle, intf.client, deviceHandle); ASSERT_EQ(SUCCESS, status); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&Handle)); ASSERT_EQ(SUCCESS, ConnectRetry(&Handle)); MaxResponse.resize(TeeGetMaxMsgLen(&Handle) * sizeof(char)); ASSERT_EQ(SUCCESS, TeeWrite(&Handle, &MkhiRequest, sizeof(GEN_GET_FW_VERSION), &NumberOfBytes, 0)); ASSERT_EQ(sizeof(GEN_GET_FW_VERSION), NumberOfBytes); ASSERT_EQ(SUCCESS, TeeRead(&Handle, &MaxResponse[0], TeeGetMaxMsgLen(&Handle), &NumberOfBytes, 0)); pResponseMessage = (GEN_GET_FW_VERSION_ACK*)(&MaxResponse[0]); ASSERT_EQ(SUCCESS, pResponseMessage->Header.Fields.Result); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeMajor); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeBuildNo); TeeDisconnect(&Handle); EXPECT_EQ(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&Handle)); } TEST_P(MeTeeFDTEST, PROD_MKHI_GetFWStatus) { TEEHANDLE Handle = TEEHANDLE_ZERO; uint32_t fwStatusNum; uint32_t fwStatus; struct MeTeeTESTParams intf = GetParam(); TEESTATUS status; status = TeeInitHandle(&Handle, intf.client, deviceHandle); ASSERT_EQ(TEE_SUCCESS, status); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&Handle)); //FWSTS1 fwStatusNum = 0; ASSERT_EQ(SUCCESS, TeeFWStatus(&Handle, fwStatusNum, &fwStatus)); EXPECT_NE(0, fwStatus); TeeDisconnect(&Handle); EXPECT_EQ(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&Handle)); } struct MeTeeTESTParams interfaces[1] = { {"PCH", NULL, &GUID_DEVINTERFACE_MKHI}}; INSTANTIATE_TEST_SUITE_P(MeTeeTESTInstance, MeTeeTEST, testing::ValuesIn(interfaces), [](const testing::TestParamInfo<MeTeeTEST::ParamType>& info) { return info.param.name; }); INSTANTIATE_TEST_SUITE_P(MeTeeOpenTESTInstance, MeTeeOpenTEST, testing::ValuesIn(interfaces), [](const testing::TestParamInfo<MeTeeTEST::ParamType>& info) { return info.param.name; }); INSTANTIATE_TEST_SUITE_P(MeTeeDataNTESTInstance, MeTeeDataNTEST, testing::ValuesIn(interfaces), [](const testing::TestParamInfo<MeTeeDataNTEST::ParamType>& info) { return info.param.name; }); INSTANTIATE_TEST_SUITE_P(MeTeeFDTESTInstance, MeTeeFDTEST, testing::ValuesIn(interfaces), [](const testing::TestParamInfo<MeTeeFDTEST::ParamType>& info) { return info.param.name; }); INSTANTIATE_TEST_SUITE_P(MeTee1000OpenTESTInstance, MeTee1000OpenTEST, testing::ValuesIn(interfaces), [](const testing::TestParamInfo<MeTee1000OpenTEST::ParamType>& info) { return info.param.name; }); ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/metee_test.h��������������������������������������������������������������0000664�0000000�0000000�00000022502�15201331742�0017734�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2014-2025 Intel Corporation */ #include <memory.h> #include <string> #include <fstream> #include <chrono> #include <thread> #include <vector> #include <climits> #include "gtest/gtest.h" #include <gmock/gmock.h> #include "metee.h" #include "meteepp.h" #include "helpers.h" #ifdef WIN32 #include <windows.h> #else #define ERROR_INVALID_HANDLE -ENOTTY #define ERROR_NOT_FOUND -ENODEV #define INVALID_HANDLE_VALUE ((void*)0) #include <sys/resource.h> #endif // WIN32 #include "MKHI.h" std::string GetErrorString(unsigned long LastError); TEESTATUS ConnectRetry(PTEEHANDLE handle); //Print Expected and Ectual in Hex. namespace testing { namespace internal { inline void PrintTo(unsigned long n, ::std::ostream* os) { (*os) << "0x" << std::hex << n << " " << (GetErrorString(n)); } } } #ifdef _WIN32 inline TEESTATUS TestTeeInitGUID(PTEEHANDLE handle, const GUID *guid, const GUID *device) { if (device != NULL) return TeeInitGUID(handle, guid, device); else return TeeInit(handle, guid, NULL); } #else /* _WIN32 */ inline TEESTATUS TestTeeInitGUID(PTEEHANDLE handle, const GUID *guid, const GUID *device) { return TeeInit(handle, guid, NULL); } #endif /* _WIN32 */ struct MeTeeTESTParams { const char *name; const GUID *device; const GUID *client; }; class MeTeeTEST : public ::testing::TestWithParam<struct MeTeeTESTParams>{ public: MeTeeTEST() { // initialization code here } void SetUp() { #ifdef _DEBUG printf("Enter ProdTests SetUp\n"); #endif MkhiRequest.Header.Fields.Command = GEN_GET_FW_VERSION_CMD; MkhiRequest.Header.Fields.GroupId = MKHI_GEN_GROUP_ID; MkhiRequest.Header.Fields.IsResponse = 0; #ifdef _DEBUG printf("Exit ProdTests SetUp\n"); #endif } void TearDown() { #ifdef _DEBUG printf("Enter ProdTests TearDown\n"); #endif std::this_thread::sleep_for(std::chrono::milliseconds(100)); //Is it helping? #ifdef _DEBUG printf("Exit ProdTests TearDown\n"); #endif } ~MeTeeTEST() { // cleanup any pending stuff, but no exceptions allowed } GEN_GET_FW_VERSION MkhiRequest; }; class MeTeePPTEST : public ::testing::TestWithParam<struct MeTeeTESTParams> { public: MeTeePPTEST() { // initialization code here } void SetUp() { GEN_GET_FW_VERSION req; #ifdef _DEBUG printf("Enter ProdTests SetUp\n"); #endif req.Header.Fields.Command = GEN_GET_FW_VERSION_CMD; req.Header.Fields.GroupId = MKHI_GEN_GROUP_ID; req.Header.Fields.IsResponse = 0; auto ptr = reinterpret_cast<uint8_t*>(&req); MkhiRequest = std::vector<uint8_t>(ptr, ptr + sizeof(GEN_GET_FW_VERSION)); #ifdef _DEBUG printf("Exit ProdTests SetUp\n"); #endif } void TearDown() { #ifdef _DEBUG printf("Enter ProdTests TearDown\n"); #endif std::this_thread::sleep_for(std::chrono::milliseconds(100)); #ifdef _DEBUG printf("Exit ProdTests TearDown\n"); #endif } ~MeTeePPTEST() { // cleanup any pending stuff, but no exceptions allowed } std::vector<uint8_t> MkhiRequest; }; class MeTeeFDTEST : public ::testing::TestWithParam<struct MeTeeTESTParams> { public: MeTeeFDTEST() : deviceHandle(TEE_INVALID_DEVICE_HANDLE) { // initialization code here } void SetUp() { OpenMEI(); if (deviceHandle == TEE_INVALID_DEVICE_HANDLE) GTEST_SKIP(); MkhiRequest.Header.Fields.Command = GEN_GET_FW_VERSION_CMD; MkhiRequest.Header.Fields.GroupId = MKHI_GEN_GROUP_ID; MkhiRequest.Header.Fields.IsResponse = 0; } void TearDown() { CloseMEI(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); //Is it helping? } ~MeTeeFDTEST() { // cleanup any pending stuff, but no exceptions allowed } GEN_GET_FW_VERSION MkhiRequest; private: void OpenMEI(); void CloseMEI(); public: TEE_DEVICE_HANDLE deviceHandle; }; class MeTeeOpenTEST : public ::testing::TestWithParam<struct MeTeeTESTParams> { public: MeTeeOpenTEST() { // initialization code here __tee_init_handle(&_handle); } void SetUp() { struct MeTeeTESTParams intf = GetParam(); TEESTATUS status; _handle.handle = NULL; status = TestTeeInitGUID(&_handle, intf.client, intf.device); if (status == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); ASSERT_EQ(TEE_SUCCESS, status); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&_handle)); MkhiRequest.Header.Fields.Command = GEN_GET_FW_VERSION_CMD; MkhiRequest.Header.Fields.GroupId = MKHI_GEN_GROUP_ID; MkhiRequest.Header.Fields.IsResponse = 0; } void TearDown() { TeeDisconnect(&_handle); //Is this helping? std::this_thread::sleep_for(std::chrono::milliseconds(100)); } ~MeTeeOpenTEST() { // cleanup any pending stuff, but no exceptions allowed } TEEHANDLE _handle; GEN_GET_FW_VERSION MkhiRequest; }; class MeTeeDataNTEST : public ::testing::TestWithParam<struct MeTeeTESTParams> { public: MeTeeDataNTEST() { // initialization code here __tee_init_handle(&_handle); } void SetUp() { struct MeTeeTESTParams intf = GetParam(); TEESTATUS status; #ifdef _DEBUG printf("Enter ProdTests SetUp\n"); #endif _handle.handle = NULL; status = TestTeeInitGUID(&_handle, intf.client, intf.device); if (status == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); ASSERT_EQ(TEE_SUCCESS, status); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, TeeGetDeviceHandle(&_handle)); ASSERT_EQ(TEE_SUCCESS, ConnectRetry(&_handle)); MkhiRequest.Header.Fields.Command = GEN_GET_FW_VERSION_CMD; MkhiRequest.Header.Fields.GroupId = MKHI_GEN_GROUP_ID; MkhiRequest.Header.Fields.IsResponse = 0; #ifdef _DEBUG printf("Exit ProdTests SetUp\n"); #endif } void TearDown() { #ifdef _DEBUG printf("Enter ProdTests TearDown\n"); #endif TeeDisconnect(&_handle); //Is this helping? std::this_thread::sleep_for(std::chrono::milliseconds(100)); #ifdef _DEBUG printf("Exit ProdTests TearDown\n"); #endif } ~MeTeeDataNTEST() { // cleanup any pending stuff, but no exceptions allowed } TEEHANDLE _handle; GEN_GET_FW_VERSION MkhiRequest; }; class MeTee1000OpenTEST : public ::testing::TestWithParam<struct MeTeeTESTParams>{ public: MeTee1000OpenTEST() { // initialization code here } void SetUp() { #ifdef _DEBUG printf("Enter MeTee1000OpenTEST SetUp\n"); #endif MkhiRequest.Header.Fields.Command = GEN_GET_FW_VERSION_CMD; MkhiRequest.Header.Fields.GroupId = MKHI_GEN_GROUP_ID; MkhiRequest.Header.Fields.IsResponse = 0; #ifdef __linux__ struct rlimit limit; limit.rlim_cur = 2048; limit.rlim_max = 2048; errno = 0; if (setrlimit(RLIMIT_NOFILE, &limit) != 0) FAIL() << "setrlimit() failed with errno=" << errno; #endif // __linux__ for (int g = 0; g <= 199; g++) { v.push_back(std::thread([g]() { int base = g * 10; int i = 0; std::ofstream file0; std::string name0 = "example_" + std::to_string(base) + ".txt"; std::ofstream file1; std::string name1 = "example_" + std::to_string(base + 1) + ".txt"; std::ofstream file2; std::string name2 = "example_" + std::to_string(base + 2) + ".txt"; std::ofstream file3; std::string name3 = "example_" + std::to_string(base + 3) + ".txt"; std::ofstream file4; std::string name4 = "example_" + std::to_string(base + 4) + ".txt"; std::ofstream file5; std::string name5 = "example_" + std::to_string(base + 5) + ".txt"; std::ofstream file6; std::string name6 = "example_" + std::to_string(base + 6) + ".txt"; std::ofstream file7; std::string name7 = "example_" + std::to_string(base + 7) + ".txt"; std::ofstream file8; std::string name8 = "example_" + std::to_string(base + 8) + ".txt"; std::ofstream file9; std::string name9 = "example_" + std::to_string(base + 9) + ".txt"; file0.open(name0); file1.open(name1); file2.open(name2); file3.open(name3); file4.open(name4); file5.open(name5); file6.open(name6); file7.open(name7); file8.open(name8); file9.open(name9); while (i++ < 5) { file0 << "Writing to " << name0 << std::endl; file1 << "Writing to " << name1 << std::endl; file2 << "Writing to " << name2 << std::endl; file3 << "Writing to " << name3 << std::endl; file4 << "Writing to " << name4 << std::endl; file5 << "Writing to " << name5 << std::endl; file6 << "Writing to " << name6 << std::endl; file7 << "Writing to " << name7 << std::endl; file8 << "Writing to " << name8 << std::endl; file9 << "Writing to " << name9 << std::endl; std::this_thread::sleep_for(std::chrono::seconds(5)); } file0.close(); file1.close(); file2.close(); file3.close(); file4.close(); file5.close(); file6.close(); file7.close(); file8.close(); file9.close(); remove(name0.c_str()); remove(name1.c_str()); remove(name2.c_str()); remove(name3.c_str()); remove(name4.c_str()); remove(name5.c_str()); remove(name6.c_str()); remove(name7.c_str()); remove(name8.c_str()); remove(name9.c_str()); })); } std::this_thread::sleep_for(std::chrono::seconds(5)); #ifdef _DEBUG printf("Exit MeTee1000OpenTEST SetUp\n"); #endif } void TearDown() { #ifdef _DEBUG printf("Enter MeTee1000OpenTEST TearDown\n"); #endif for (std::vector<std::thread>::iterator it = v.begin(); it != v.end(); it++) it->std::thread::join(); std::this_thread::sleep_for(std::chrono::milliseconds(100)); //Is it helping? #ifdef _DEBUG printf("Exit MeTee1000OpenTEST TearDown\n"); #endif } ~MeTee1000OpenTEST() { // cleanup any pending stuff, but no exceptions allowed } GEN_GET_FW_VERSION MkhiRequest; std::vector<std::thread> v; }; ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/tests/meteepp_test.cpp����������������������������������������������������������0000664�0000000�0000000�00000007570�15201331742�0020637�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������/* SPDX-License-Identifier: Apache-2.0 */ /* * Copyright (C) 2021-2025 Intel Corporation */ #include "metee_test.h" DEFINE_GUID(GUID_NON_EXISTS_CLIENT, 0x85eb8fa6, 0xbdd, 0x4d01, 0xbe, 0xc4, 0xa5, 0x97, 0x43, 0x4e, 0xd7, 0x62); TEST_P(MeTeePPTEST, PROD_MKHI_SimpleGetVersion) { struct MeTeeTESTParams intf = GetParam(); std::vector<uint8_t> MaxResponse; GEN_GET_FW_VERSION_ACK* pResponseMessage; for (int i = 1; i < 2; i++) { try { intel::security::metee metee(*intf.client); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, metee.device_handle()); metee.connect(); ASSERT_EQ(MkhiRequest.size(), metee.write(MkhiRequest, 0)); MaxResponse = metee.read(0); ASSERT_LE(sizeof(GEN_GET_FW_VERSION_ACK), MaxResponse.size()); pResponseMessage = reinterpret_cast<GEN_GET_FW_VERSION_ACK*>(MaxResponse.data()); ASSERT_EQ(TEE_SUCCESS, pResponseMessage->Header.Fields.Result); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeMajor); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeBuildNo); } catch(const intel::security::metee_exception &ex){ if (ex.code().value() == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); FAIL() << "Excepton: " << ex.what(); } } } TEST_P(MeTeePPTEST, PROD_N_Kind) { struct MeTeeTESTParams intf = GetParam(); try { intel::security::metee metee(*intf.client); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, metee.device_handle()); ASSERT_GE(metee.kind().length(), 0); } catch (const intel::security::metee_exception& ex) { if (ex.code().value() == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); if (ex.code().value() != TEE_NOTSUPPORTED) FAIL() << "Excepton: " << ex.what(); } } TEST_P(MeTeePPTEST, PROD_MKHI_InitFull) { struct MeTeeTESTParams intf = GetParam(); std::vector<uint8_t> MaxResponse; GEN_GET_FW_VERSION_ACK* pResponseMessage; try { struct tee_device_address device = {tee_device_address::TEE_DEVICE_TYPE_NONE, { NULL }}; intel::security::metee metee(*intf.client, device, TEE_LOG_LEVEL_VERBOSE); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, metee.device_handle()); metee.connect(); } catch (const intel::security::metee_exception& ex) { if (ex.code().value() == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); FAIL() << "Excepton: " << ex.what(); } } TEST_P(MeTeePPTEST, PROD_N_TestConnectToNonExistsUuid) { struct MeTeeTESTParams intf = GetParam(); try { intel::security::metee metee(GUID_NON_EXISTS_CLIENT); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, metee.device_handle()); metee.connect(); } catch (const intel::security::metee_exception& ex) { if (ex.code().value() == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); if (ex.code().value() == TEE_CLIENT_NOT_FOUND) return; FAIL() << "Excepton: " << ex.what(); } FAIL(); } TEST_P(MeTeePPTEST, PROD_MKHI_MoveSemantics) { struct MeTeeTESTParams intf = GetParam(); std::vector<uint8_t> MaxResponse; GEN_GET_FW_VERSION_ACK* pResponseMessage; intel::security::metee metee2; try { intel::security::metee metee(*intf.client); ASSERT_NE(TEE_INVALID_DEVICE_HANDLE, metee.device_handle()); metee.connect(); metee2 = std::move(metee); } catch (const intel::security::metee_exception& ex) { if (ex.code().value() == TEE_DEVICE_NOT_FOUND) GTEST_SKIP(); FAIL() << "Excepton: " << ex.what(); } ASSERT_EQ(MkhiRequest.size(), metee2.write(MkhiRequest, 0)); MaxResponse = metee2.read(0); ASSERT_LE(sizeof(GEN_GET_FW_VERSION_ACK), MaxResponse.size()); pResponseMessage = reinterpret_cast<GEN_GET_FW_VERSION_ACK*>(MaxResponse.data()); ASSERT_EQ(TEE_SUCCESS, pResponseMessage->Header.Fields.Result); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeMajor); EXPECT_NE(0, pResponseMessage->Data.FWVersion.CodeBuildNo); } static struct MeTeeTESTParams interfaces[1] = { {"PCH", NULL, &GUID_DEVINTERFACE_MKHI}}; INSTANTIATE_TEST_SUITE_P(MeTeePPTESTInstance, MeTeePPTEST, testing::ValuesIn(interfaces), [](const testing::TestParamInfo<MeTeePPTEST::ParamType>& info) { return info.param.name; });����������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/version.cmake�������������������������������������������������������������������0000664�0000000�0000000�00000001242�15201331742�0016750�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2014-2025 Intel Corporation file(READ VERSION VER_FILE) string(STRIP "${VER_FILE}" VER_FILE) string(REPLACE "." ";" VER_LIST ${VER_FILE}) list(GET VER_LIST 0 TEE_VERSION_MAJOR) list(GET VER_LIST 1 TEE_VERSION_MINOR) list(GET VER_LIST 2 TEE_VERSION_PATCH) list(LENGTH VER_LIST VER_LIST_LEN) if(VER_LIST_LEN EQUAL 4) list(GET VER_LIST 3 TEE_VERSION_BUILD) else() set(TEE_VERSION_BUILD 0) endif() set(TEE_VERSION_STRING ${TEE_VERSION_MAJOR}.${TEE_VERSION_MINOR}.${TEE_VERSION_PATCH}.${TEE_VERSION_BUILD}) set(TEE_VERSION_COMM ${TEE_VERSION_MAJOR},${TEE_VERSION_MINOR},${TEE_VERSION_PATCH},${TEE_VERSION_BUILD})��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������intel-metee-67ff323/win32.cmake���������������������������������������������������������������������0000664�0000000�0000000�00000003137�15201331742�0016232�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2014-2024 Intel Corporation if(BUILD_MSVC_RUNTIME_STATIC) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") endif() set(TEE_SOURCES src/Windows/metee_win.c src/Windows/metee_winhelpers.c ${PROJECT_BINARY_DIR}/metee.rc ) add_library(${PROJECT_NAME} ${TEE_SOURCES}) target_link_libraries(${PROJECT_NAME} CfgMgr32.lib) target_compile_definitions(${PROJECT_NAME} PRIVATE UNICODE _UNICODE $<$<BOOL:BUILD_SHARED_LIBS>:METEE_DLL> $<$<BOOL:BUILD_SHARED_LIBS>:METEE_DLL_EXPORT> ) if(NOT CONSOLE_OUTPUT) target_compile_definitions(${PROJECT_NAME} PRIVATE -DSYSLOG) endif() configure_file ( "${PROJECT_SOURCE_DIR}/src/Windows/metee.rc.in" "${PROJECT_BINARY_DIR}/metee.rc" ) # Secure compile flags target_compile_options(${PROJECT_NAME} PRIVATE /GS /sdl) # More warnings and warning-as-error target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX ) set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/Zi" ) set_target_properties(${PROJECT_NAME} PROPERTIES PDB_NAME "${PROJECT_NAME}" PDB_NAME_DEBUG "${PROJECT_NAME}" COMPILE_PDB_NAME "${PROJECT_NAME}" COMPILE_PDB_NAME_DEBUG "${PROJECT_NAME}" ) if(${BUILD_SHARED_LIBS}) install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL) else() install(FILES "$<TARGET_FILE_DIR:${PROJECT_NAME}>/${PROJECT_NAME}.pdb" DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL) endif()�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������