jhi.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*
  2. Copyright 2010-2016 Intel Corporation
  3. This software is licensed to you in accordance
  4. with the agreement between you and Intel Corporation.
  5. Alternatively, you can use this file in compliance
  6. with the Apache license, Version 2.
  7. Apache License, Version 2.0
  8. Licensed under the Apache License, Version 2.0 (the "License");
  9. you may not use this file except in compliance with the License.
  10. You may obtain a copy of the License at
  11. http://www.apache.org/licenses/LICENSE-2.0
  12. Unless required by applicable law or agreed to in writing, software
  13. distributed under the License is distributed on an "AS IS" BASIS,
  14. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. See the License for the specific language governing permissions and
  16. limitations under the License.
  17. */
  18. /**
  19. ********************************************************************************
  20. **
  21. ** @file jhi.h
  22. **
  23. ** @brief Defines exported interfaces for JHI.DLL
  24. **
  25. ** @author Elad Dabool
  26. **
  27. ********************************************************************************
  28. */
  29. #ifndef __JHI_H__
  30. #define __JHI_H__
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #include "typedefs.h"
  35. // Format: Major.Minor.ReverseDate
  36. #define JHI_VERSION "1.13.20161115"
  37. //------------------------------------------------------------
  38. // Common & External Interfaces
  39. //------------------------------------------------------------
  40. typedef PVOID JHI_HANDLE ;
  41. typedef UINT32 JHI_RET ;
  42. typedef PVOID JHI_SESSION_HANDLE;
  43. //------------------------------------------------------------
  44. // Define Linkage for the functions
  45. //------------------------------------------------------------
  46. #define JHI_EXPORT __declspec(dllexport) JHI_RET
  47. //----------------------------------------------------------------------------------------------------------------
  48. // JHI 7.1 return codes - not used in 8.0 and above (backward compatibility only), JHI 8.0 return codes are listed below
  49. //----------------------------------------------------------------------------------------------------------------
  50. #define JHI_FILE_MISSING_SRC 0x101 // Source File not found in install/uninstall or unable to load
  51. // file in SendAndRecv
  52. #define JHI_FILE_ERROR_AUTH 0x102 // Attempted to load the file, but FW returned back
  53. // a manifest failure check and rejected it
  54. #define JHI_FILE_ERROR_DELETE 0x104 // Unable to remove file corresponding to the UUID in uninstall
  55. // Maybe permission issues
  56. #define JHI_FILE_INVALID 0x105 // Invalid file - bad characters or larger than 64K
  57. #define JHI_FILE_ERROR_OPEN 0x106 // Unable to open file. Maybe permission issues
  58. #define JHI_FILE_UUID_MISMATCH 0x107 // UUIDs dont match between applet file and function input
  59. #define JHI_FILE_IDENTICAL 0x108 // downloaded applet matches existing one in Jom
  60. #define JHI_INVALID_COMMAND 0x202 // invalid JHI interface command
  61. #define JHI_ILLEGAL_VALUE 0x204 // validation failed on input parameters
  62. #define JHI_COMMS_ERROR 0x300 // Communications error due to HECI timeouts
  63. // or ME auto resets or any other COMMS error
  64. #define JHI_SERVICE_INVALID_GUID 0x302 // Invalid COM guid (from DLL)
  65. #define JHI_APPLET_TIMEOUT 0x401 // This may be a result of a Java code in VM in an infinite loop.
  66. // TL will kill applet in JOM and return error code
  67. #define JHI_APPID_NOT_EXIST 0x402 // If appid is not present in app table
  68. #define JHI_JOM_FATAL 0x403 //JOM fatal error
  69. #define JHI_JOM_OVERFLOW 0x404 //exceeds max installed applets or active sessions in JOM
  70. #define JHI_JOM_ERROR_DOWNLOAD 0x405 //JOM download error
  71. #define JHI_JOM_ERROR_UNLOAD 0x406 //JOM unload error
  72. #define JHI_ERROR_LOGGING 0x500 // Error in logging
  73. #define JHI_UNKNOWN_ERROR 0x600 // Any other error
  74. //----------------------------------------------------------------------------------------------------------------
  75. // JHI 8.0 return codes
  76. //----------------------------------------------------------------------------------------------------------------
  77. // General JHI Return Code
  78. #define JHI_SUCCESS 0x00 // general success response
  79. #define JHI_INVALID_HANDLE 0x201 // invalid JHI handle
  80. #define JHI_INVALID_PARAMS 0x203 // passed a null pointer to a required argument / illegal arguments passed to API function
  81. #define JHI_INVALID_APPLET_GUID JHI_ILLEGAL_VALUE // the applet UUID is invalid
  82. #define JHI_SERVICE_UNAVAILABLE 0x301 // there is no connection to JHI service
  83. #define JHI_ERROR_REGISTRY 0x501 // error for any registry based access or registry corruption
  84. #define JHI_ERROR_REPOSITORY_NOT_FOUND 0x1000 // when cannot find applets repository directory
  85. #define JHI_INTERNAL_ERROR 0x601 // an unexpected internal error happened.
  86. #define JHI_INVALID_BUFFER_SIZE 0x1001 // used a buffer that is larger than JHI_BUFFER_MAX
  87. #define JHI_INVALID_COMM_BUFFER 0x1002 // JVM_COMM_BUFFER passed to function is invalid
  88. // Install errors
  89. #define JHI_INVALID_INSTALL_FILE 0x1003 // the dalp file path is invalid
  90. #define JHI_READ_FROM_FILE_FAILED 0x1004 // failed to read DALP file
  91. #define JHI_INVALID_PACKAGE_FORMAT 0x1005 // dalp file format is not a valid
  92. #define JHI_FILE_ERROR_COPY 0x103 // applet file could not be copied to repository
  93. #define JHI_INVALID_INIT_BUFFER 0x1006 // passed an invalid init buffer to the function
  94. #define JHI_FILE_NOT_FOUND JHI_FILE_MISSING_SRC // could not find the specified dalp file
  95. #define JHI_INVALID_FILE_EXTENSION 0x1007 // applets package file must end with .dalp extension.
  96. #define JHI_MAX_INSTALLED_APPLETS_REACHED JHI_JOM_OVERFLOW // exceeds max applets allowed, need to uninstall an applet.
  97. #define JHI_INSTALL_FAILURE_SESSIONS_EXISTS 0x1008 // could not install because there are open sessions.
  98. #define JHI_INSTALL_FAILED 0x1009 // no compatible applet was found in the DALP file
  99. #define JHI_SVL_CHECK_FAIL 0x1040 // install failed due to an svl check
  100. #define JHI_ILLEGAL_PLATFORM_ID 0x1041 // install failed due to an illegal platform id
  101. // Uninstall errors
  102. #define JHI_DELETE_FROM_REPOSITORY_FAILURE JHI_FILE_ERROR_DELETE // unable to delete applet DALP file from repository
  103. #define JHI_UNINSTALL_FAILURE_SESSIONS_EXISTS 0x100A // for app uninstallation errors
  104. // Create Session errors
  105. #define JHI_APPLET_NOT_INSTALLED JHI_APPID_NOT_EXIST // trying to create a session of uninstalled applet
  106. #define JHI_MAX_SESSIONS_REACHED 0x100C // exceeds max sessions allowed, need to close a session.
  107. #define JHI_SHARED_SESSION_NOT_SUPPORTED 0x100D // the applet does not support shared sessions.
  108. #define JHI_MAX_SHARED_SESSION_REACHED 0x100E // failed to get session handle due to maximun handles limit.
  109. #define JHI_FIRMWARE_OUT_OF_RESOURCES 0x1018 // request causes the VM to exceed its memory quota
  110. #define JHI_ONLY_SINGLE_INSTANCE_ALLOWED 0x1019 // trying to create more than a single instance of an applet
  111. #define JHI_OPERATION_NOT_PERMITTED 0x101A // userspace tried to perform a kernel space operation
  112. // Close Session errors
  113. #define JHI_INVALID_SESSION_HANDLE 0x100F // the session handle is not of an active session.
  114. // Send And Recieve errors
  115. #define JHI_INSUFFICIENT_BUFFER 0x200 // buffer overflow - response greater than supplied Rx buffer
  116. #define JHI_APPLET_FATAL 0x400 // This may be a result of uncaught exception or unusual applet
  117. // error that results in applet being terminated by TL VM.
  118. #define JHI_APPLET_BAD_STATE 0x407 // Applet in bad state, need to reopen the session
  119. // Register/Unregister session events
  120. #define JHI_SESSION_NOT_REGISTERED 0x1010 // trying to unregister a session that is not registered for events.
  121. #define JHI_SESSION_ALREADY_REGSITERED 0x1011 // Registration to an event is done only once.
  122. #define JHI_EVENTS_NOT_SUPPORTED 0x1012 // events are not supported for this type of session
  123. // Get Applet Property errors:
  124. #define JHI_APPLET_PROPERTY_NOT_SUPPORTED 0x1013 // Returned when calling GetAppletProperty with invalid property
  125. // Init errors
  126. #define JHI_SPOOLER_NOT_FOUND 0x1014 // cannot find the spooler file
  127. #define JHI_INVALID_SPOOLER 0x1015 // cannot download spooler / create an instance of the spooler
  128. #define JHI_NO_CONNECTION_TO_FIRMWARE JHI_COMMS_ERROR // JHI has no connection to the VM
  129. // DLL errors
  130. #define JHI_VM_DLL_FILE_NOT_FOUND 0x1016 // VM DLL is missing from the exe path
  131. #define JHI_VM_DLL_VERIFY_FAILED 0x1017 // DLL Signature or Publisher name are not valid.
  132. // IAC errors
  133. #define JHI_IAC_SERVER_SESSION_EXIST 0x1020 // May occur when trying to create two sessions on an IAC server applet
  134. #define JHI_IAC_SERVER_INTERNAL_SESSIONS_EXIST 0x1021 // May occur when trying to close an IAC server applet session that has internal sessions
  135. // Access control errors
  136. #define JHI_MISSING_ACCESS_CONTROL 0x1030 // Will return from install when trying to install an applet which uses an API that it is not permitted to.
  137. // SD session errors
  138. #define JHI_ERROR_OEM_SIGNING_DISABLED 0x1050 // May occur if DAL OEAM signing is disabled
  139. #define JHI_ERROR_SD_PUBLICKEY_HASH_FAILED 0x1051 // May occur if there is a mismatch in the public key hash of an SD
  140. #define JHI_ERROR_SD_DB_NO_FREE_SLOT 0x1052 // In case reached max installed SDs in DB
  141. #define JHI_ERROR_SD_TA_INSTALLATION_UNALLOWED 0x1053 // TA installation is not allowed for SD
  142. // -----------------------------------------------------------
  143. // Buffer size limitation is 2MB
  144. // JHI will not accept any buffer with greater size.
  145. //
  146. // Note that this size limitiation does not mark the maximum buffer size an applet can recieve,
  147. // applet max buffer size changes from one applet to another.
  148. //
  149. // This applies for all JHI API function that use buffers such as:
  150. // SendAndRecieve, CreateSession, GetAppletProperty.
  151. // -----------------------------------------------------------
  152. #define JHI_BUFFER_MAX 2097152
  153. //------------------------------------------------------------
  154. // Applet version macros
  155. //------------------------------------------------------------
  156. // While applet version is represented in a Major.Minor format (i.e. 1.0)
  157. // the VM repersntation of an applet version (that can be obtained using JHI_GetAppletProperty) is as an integer that combine both major and minor version.
  158. // in order to perform the transition between to two representation we offer the following macros:
  159. /*
  160. Make VM Applet Version (32bit) from a Major.Minor format
  161. Bits:
  162. 00-07 - Major
  163. 08-15 - Minor
  164. 15-31 - Reserved (All Zero)
  165. */
  166. #define MK_APPLET_VER(maj, min) ( (UINT32) \
  167. (maj & 0x000000FFUL) | \
  168. ((min << 8) & 0x0000FF00UL) & \
  169. (0x0000FFFFUL) )
  170. /* Extract Applet Major Version from a VM integer representation (num) */
  171. #define MAJOR_APPLET_VER(num) ((UINT8) (num & 0x000000FFUL))
  172. /* Extract Applet Minor Version from a VM integer representation (num) */
  173. #define MINOR_APPLET_VER(num) ((UINT8) ((num & 0x0000FF00UL) >> 8))
  174. //------------------------------------------------------------
  175. // JHI Events
  176. //------------------------------------------------------------
  177. // this enum lists the types of data received by JHI event
  178. typedef enum _JHI_EVENT_DATA_TYPE
  179. {
  180. JHI_DATA_FROM_APPLET = 0, // the event raised by an applet session
  181. JHI_DATA_FROM_SERVICE = 1 // the event raised by JHI service
  182. }JHI_EVENT_DATA_TYPE;
  183. //this struct repersents the data received upon a JHI event
  184. typedef struct {
  185. UINT32 datalen; // byte length of the event data
  186. UINT8* data; // the buffer that contains the event data
  187. JHI_EVENT_DATA_TYPE dataType; // the event type
  188. }JHI_EVENT_DATA;
  189. // This is the format for a callback function that is used in order to
  190. // receive session events.
  191. typedef void (*JHI_EventFunc)(JHI_SESSION_HANDLE SessionHandle, JHI_EVENT_DATA EventData);
  192. //------------------------------------------------------------
  193. // JHI Version info.
  194. //------------------------------------------------------------
  195. // this enum lists the communication types that are used
  196. // by JHI in order to communicate with the firmware
  197. typedef enum _JHI_COMMUNICATION_TYPE
  198. {
  199. JHI_SOCKETS = 0, // communication by sockets
  200. JHI_HECI = 1 // communication by HECI
  201. } JHI_COMMUNICATION_TYPE;
  202. #define VERSION_BUFFER_SIZE 50
  203. // this enum lists the platfom types that are supported by JHI
  204. typedef enum _JHI_PLATFROM_ID
  205. {
  206. ME = 0, // Intel(R) Management Engine (Intel(R) ME)
  207. SEC = 1,
  208. CSE = 2,
  209. INVALID_PLATFORM_ID = -1
  210. } JHI_PLATFROM_ID;
  211. // This enum lists the VM types that are supported by JHI
  212. typedef enum _JHI_VM_TYPE
  213. {
  214. JHI_VM_TYPE_INVALID = -1,
  215. JHI_VM_TYPE_TL = 0,
  216. JHI_VM_TYPE_BEIHAI = 1, // Alias of BHv1 for backward compatibility
  217. JHI_VM_TYPE_BEIHAI_V1 = 1,
  218. JHI_VM_TYPE_BEIHAI_V2 = 2
  219. } JHI_VM_TYPE;
  220. // Different VM plugin types used by JHI
  221. typedef enum _JHI_PLUGIN_TYPE
  222. {
  223. JHI_PLUGIN_TYPE_INVALID = 0,
  224. JHI_PLUGIN_TYPE_TL = 1,
  225. JHI_PLUGIN_TYPE_BEIHAI_V1 = 2,
  226. JHI_PLUGIN_TYPE_BEIHAI_V2 = 3
  227. } JHI_PLUGIN_TYPE;
  228. // this struct contains information about the JHI service and the
  229. // firmware versions, and additional info
  230. typedef struct
  231. {
  232. char jhi_version[VERSION_BUFFER_SIZE]; // the version of the JHI service
  233. char fw_version[VERSION_BUFFER_SIZE]; // the version of the firmware
  234. JHI_COMMUNICATION_TYPE comm_type; // the communication type between JHI and the firmware
  235. JHI_PLATFROM_ID platform_id; // the platform supported by the JHI service
  236. JHI_VM_TYPE vm_type; // the VM type supported by the JHI service
  237. UINT32 reserved[19]; // reserved bits
  238. } JHI_VERSION_INFO;
  239. //------------------------------------------------------------
  240. // Session info
  241. //------------------------------------------------------------
  242. // this enum lists the states of a session
  243. typedef enum _JHI_SESSION_STATE
  244. {
  245. JHI_SESSION_STATE_ACTIVE = 0, // the session is active
  246. JHI_SESSION_STATE_NOT_EXISTS = 1 // the session does not exists
  247. } JHI_SESSION_STATE;
  248. // this struct contains information for a given session
  249. typedef struct
  250. {
  251. JHI_SESSION_STATE state; // the session state
  252. UINT32 flags; // the flags used when this session created
  253. UINT32 reserved[20]; // reserved bits
  254. } JHI_SESSION_INFO;
  255. //------------------------------------------------------------
  256. // Create Session flags
  257. //------------------------------------------------------------
  258. // this enum lists the flags that used when creating a session
  259. //
  260. #define JHI_NO_FLAGS 0 // no flags to be used
  261. #define JHI_SHARED_SESSION 1 // create a shared session, or receive a handle for an existing shared session
  262. //------------------------------------------------------------
  263. // Data Buffer
  264. //------------------------------------------------------------
  265. typedef struct
  266. {
  267. PVOID buffer;
  268. UINT32 length ;
  269. } DATA_BUFFER ;
  270. //------------------------------------------------------------
  271. // For Tx and Rx downto the MEI routine
  272. // DON'T ADD MEMBERS IN
  273. //------------------------------------------------------------
  274. typedef struct
  275. {
  276. DATA_BUFFER TxBuf [1] ;
  277. //--------------------!!!!!!!!!!!--------------------//
  278. // Dont add members in between TxBuf[1] & RxBuf[1] //
  279. // The code that uses this depends on it //
  280. //--------------------!!!!!!!!!!!--------------------//
  281. DATA_BUFFER RxBuf [1] ;
  282. // You may add anything here
  283. } JVM_COMM_BUFFER ;
  284. //------------------------------------------------------------
  285. // Function Prototypes
  286. //------------------------------------------------------------
  287. // Function: JHI_Initialize
  288. //------------------------------------------------------------
  289. JHI_EXPORT
  290. JHI_Initialize (
  291. OUT JHI_HANDLE* ppHandle,
  292. IN PVOID context,
  293. IN UINT32 flags
  294. ) ;
  295. //------------------------------------------------------------
  296. // Function: JHI_Deinit
  297. //------------------------------------------------------------
  298. JHI_EXPORT JHI_Deinit(IN JHI_HANDLE handle) ;
  299. //------------------------------------------------------------
  300. // Function: JHI_SendAndRecv
  301. //------------------------------------------------------------
  302. JHI_EXPORT
  303. JHI_SendAndRecv2(
  304. IN JHI_HANDLE handle,
  305. IN JHI_SESSION_HANDLE SessionHandle,
  306. IN INT32 nCommandId,
  307. INOUT JVM_COMM_BUFFER* pComm,
  308. OUT INT32* responseCode);
  309. //------------------------------------------------------------
  310. // Function: JHI_Install
  311. //------------------------------------------------------------
  312. JHI_EXPORT
  313. JHI_Install2 (
  314. IN const JHI_HANDLE handle,
  315. IN const char* AppId,
  316. IN const FILECHAR* srcFile
  317. );
  318. //------------------------------------------------------------
  319. // Function: JHI_Uninstall
  320. //------------------------------------------------------------
  321. JHI_EXPORT
  322. JHI_Uninstall(
  323. IN JHI_HANDLE handle,
  324. IN const char* AppId
  325. );
  326. //------------------------------------------------------------
  327. // Function: JHI_GetAppletProperty
  328. //------------------------------------------------------------
  329. JHI_EXPORT
  330. JHI_GetAppletProperty(
  331. IN JHI_HANDLE handle,
  332. IN const char* AppId,
  333. INOUT JVM_COMM_BUFFER* pComm
  334. );
  335. //------------------------------------------------------------
  336. // Function: JHI_CreateSession
  337. //------------------------------------------------------------
  338. JHI_EXPORT
  339. JHI_CreateSession (
  340. IN const JHI_HANDLE handle,
  341. IN const char* AppId,
  342. IN UINT32 flags,
  343. IN DATA_BUFFER* initBuffer,
  344. OUT JHI_SESSION_HANDLE* pSessionHandle
  345. );
  346. //------------------------------------------------------------
  347. // Function: JHI_GetSessionsCount
  348. //------------------------------------------------------------
  349. JHI_EXPORT
  350. JHI_GetSessionsCount(
  351. IN const JHI_HANDLE handle,
  352. IN const char* AppId,
  353. OUT UINT32* SessionsCount
  354. );
  355. //------------------------------------------------------------
  356. // Function: JHI_CloseSession
  357. //------------------------------------------------------------
  358. JHI_EXPORT
  359. JHI_CloseSession(
  360. IN const JHI_HANDLE handle,
  361. IN JHI_SESSION_HANDLE* pSessionHandle
  362. );
  363. //------------------------------------------------------------
  364. // Function: JHI_ForceCloseSession
  365. //------------------------------------------------------------
  366. JHI_EXPORT
  367. JHI_ForceCloseSession(
  368. IN const JHI_HANDLE handle,
  369. IN JHI_SESSION_HANDLE* pSessionHandle
  370. );
  371. //------------------------------------------------------------
  372. // Function: JHI_GetSessionInfo
  373. //------------------------------------------------------------
  374. JHI_EXPORT
  375. JHI_GetSessionInfo(
  376. IN const JHI_HANDLE handle,
  377. IN JHI_SESSION_HANDLE SessionHandle,
  378. OUT JHI_SESSION_INFO* SessionInfo
  379. );
  380. #ifdef __ANDROID__
  381. //------------------------------------------------------------
  382. // Function: JHI_ClearSessions
  383. //
  384. JHI_RET
  385. JHI_ClearSessions(
  386. IN const JHI_HANDLE handle,
  387. IN int ApplicationPid
  388. );
  389. //------------------------------------------------------------
  390. // Function: JHI_GetSessionsCount
  391. //------------------------------------------------------------
  392. JHI_EXPORT
  393. JHI_CreateSessionProcess (
  394. IN const JHI_HANDLE handle,
  395. IN const char* AppId,
  396. IN int SessionPid,
  397. IN UINT32 flags,
  398. IN DATA_BUFFER* initBuffer,
  399. OUT JHI_SESSION_HANDLE* pSessionHandle
  400. );
  401. #endif //__ANDROID__
  402. //------------------------------------------------------------
  403. // Function: JHI_RegisterEvent
  404. //------------------------------------------------------------
  405. JHI_EXPORT
  406. JHI_RegisterEvents(
  407. IN const JHI_HANDLE handle,
  408. IN JHI_SESSION_HANDLE SessionHandle,
  409. IN JHI_EventFunc pEventFunction);
  410. //------------------------------------------------------------
  411. // Function: JHI_UnRegisterEvent
  412. //------------------------------------------------------------
  413. JHI_EXPORT
  414. JHI_UnRegisterEvents(
  415. IN const JHI_HANDLE handle,
  416. IN JHI_SESSION_HANDLE SessionHandle);
  417. //------------------------------------------------------------
  418. // Function: JHI_GetVersionInfo
  419. //------------------------------------------------------------
  420. JHI_EXPORT
  421. JHI_GetVersionInfo (
  422. IN const JHI_HANDLE handle,
  423. OUT JHI_VERSION_INFO* pVersionInfo);
  424. #ifdef __cplusplus
  425. };
  426. #endif
  427. #endif