--- /dev/null
+/**\r
+ * Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. \n\r
+ *\r
+ * Description: Provides cipher aead driver header \n\r
+ * Author: @CompanyNameTag \n\r
+ * History: \n\r
+ * 2023-03-14, Create file. \n\r
+ */\r
+#ifndef CIPHER_AEAD_H\r
+#define CIPHER_AEAD_H\r
+\r
+#include <stdint.h>\r
+#include <stdbool.h>\r
+#include "errcode.h"\r
+\r
+#ifdef __cplusplus\r
+#if __cplusplus\r
+extern "C" {\r
+#endif\r
+#endif\r
+\r
+/**\r
+ * @defgroup security_unified_cipher_aead Cipher AEAD\r
+ * @ingroup drivers_driver_security_unified\r
+ * @{\r
+ */\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief gcm encrypt and compute tag.\r
+ * @param [in] key Encryption key.\r
+ * @param [in] key_len Encryption key length in byte. Only support 16,24,32.\r
+ * @param [in] keyslot_handle The keyslot handle which store the encryption key.\r
+ * @param [in] iv The initial vector.\r
+ * @param [in] iv_len The initial vector lenght in byte.\r
+ * @param [in] aad The additional authentication message. NULL is support.\r
+ * @param [in] aad_len The additional authentication message length in byte.\r
+ * @param [in] plain_text Input plain text.\r
+ * @param [out] cipher_text Output cipher text.\r
+ * @param [in] data_len data length in byte.\r
+ * @param [out] tag Output tag.\r
+ * @param [in] tag_len The expected tag length in byte.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @note There are two methods to set the key:\r
+ 1)Using key/key_len, in which case, the keyslot_handle is set to 0.\r
+ 2) Calling keyslot api to create one keyslot_handle and set it, in which case,\r
+ the key is set to NULL and key_len is 0.\r
+ When keyslot is supported, you must use method 2, otherwise you should use method 1.\r
+ * @else\r
+ * @brief GCM 加密并计算 tag.\r
+ * @param [in] key 加密密钥.\r
+ * @param [in] key_len 加密密钥长度,单位是 Byte. 只支持 16,24,32.\r
+ * @param [in] keyslot_handle 保存加密密钥的 keyslot 句柄.\r
+ * @param [in] iv 初始向量\r
+ * @param [in] iv_len 初始向量长度,单位是 Byte.\r
+ * @param [in] aad 附加认证信息,支持传入为 NULL\r
+ * @param [in] aad_len 附加认证信息,单位是 Byte.\r
+ * @param [in] plain_text 输入的明文.\r
+ * @param [out] cipher_text 输出的密文.\r
+ * @param [in] data_len 数据长度,单位是 Byte.\r
+ * @param [out] tag 输出的 tag\r
+ * @param [in] tag_len 期望的 tag 长度,单位是 Byte.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @note 有两种方法设置密钥:\r
+ 1)使用 key/key_len 组合,在这种情况下,keyslot_handle 传入 0.\r
+ 2)使用 keyslot 接口创建 keyslot 句柄传入,在这种情况下,key 传入为 NULL,key_len 传入为 0.\r
+ 若支持 keyslot,则必须使用方法2,否则只能使用方法1.\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_encrypt(\r
+ uint8_t *key, uint32_t key_len, uint32_t keyslot_handle,\r
+ const uint8_t *iv, uint32_t iv_len,\r
+ const uint8_t *aad, uint32_t aad_len,\r
+ const uint8_t *plain_text, uint8_t *cipher_text, uint32_t data_len,\r
+ uint8_t *tag, uint32_t tag_len\r
+);\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief gcm decrypt and verify tag.\r
+ * @param [in] key Decryption key.\r
+ * @param [in] key_len Decryption key length in byte. Only support 16,24,32.\r
+ * @param [in] keyslot_handle The keyslot handle which store the decryption key.\r
+ * @param [in] iv The initial vector.\r
+ * @param [in] iv_len The initial vector lenght in byte.\r
+ * @param [in] aad The additional authentication message. NULL is support.\r
+ * @param [in] aad_len The additional authentication message length in byte.\r
+ * @param [in] cipher_text Input cipher text.\r
+ * @param [out] plain_text Output plain text.\r
+ * @param [in] data_len data length in byte.\r
+ * @param [in] tag Input tag to be verified.\r
+ * @param [in] tag_len The tag length in byte.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @note There are two methods to set the key:\r
+ 1)Using key/key_len, in which case, the keyslot_handle is set to 0.\r
+ 2) Calling keyslot api to create one keyslot_handle and set it, in which case,\r
+ the key is set to NULL and key_len is 0.\r
+ When keyslot is supported, you must use method 2, otherwise you should use method 1.\r
+ * @else\r
+ * @brief GCM 解密并校验 tag.\r
+ * @param [in] key 解密密钥.\r
+ * @param [in] key_len 解密密钥长度,单位是 Byte. 只支持 16,24,32.\r
+ * @param [in] keyslot_handle 保存解密密钥的 keyslot 句柄.\r
+ * @param [in] iv 初始向量\r
+ * @param [in] iv_len 初始向量长度,单位是 Byte.\r
+ * @param [in] aad 附加认证信息,支持传入为 NULL\r
+ * @param [in] aad_len 附加认证信息,单位是 Byte.\r
+ * @param [in] cipher_text 输入的密文.\r
+ * @param [out] plain_text 输出的明文.\r
+ * @param [in] data_len 数据长度,单位是 Byte.\r
+ * @param [out] tag 待校验的 tag.\r
+ * @param [in] tag_len tag 长度,单位是 Byte.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @note 有两种方法设置密钥:\r
+ 1)使用 key/key_len 组合,在这种情况下,keyslot_handle 传入 0.\r
+ 2)使用 keyslot 接口创建 keyslot 句柄传入,在这种情况下,key 传入为 NULL,key_len 传入为 0.\r
+ 若支持 keyslot,则必须使用方法2,否则只能使用方法1.\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_decrypt_verify(\r
+ uint8_t *key, uint32_t key_len, uint32_t keyslot_handle,\r
+ const uint8_t *iv, uint32_t iv_len,\r
+ const uint8_t *aad, uint32_t aad_len,\r
+ const uint8_t *cipher_text, uint8_t *plain_text, uint32_t data_len,\r
+ const uint8_t *tag, uint32_t tag_len\r
+);\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief GCM create channel handle.\r
+ * @param [out] handle Pointer to the created channel handle.\r
+ * @param [in] key Encryption/Decryption key.\r
+ * @param [in] key_len Encryption/Decryption key length in byte. Only support 16,24,32.\r
+ * @param [in] keyslot_handle The keyslot handle which store the encryption/decryption key.\r
+ * @param [in] iv The initial vector.\r
+ * @param [in] iv_len The initial vector lenght in byte.\r
+ * @param [in] aad The additional authentication message. NULL is support.\r
+ * @param [in] aad_len The additional authentication message length in byte.\r
+ * @param [in] tag_len The expected tag length in byte.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @note There are two methods to set the key:\r
+ 1)Using key/key_len, in which case, the keyslot_handle is set to 0.\r
+ 2) Calling keyslot api to create one keyslot_handle and set it, in which case,\r
+ the key is set to NULL and key_len is 0.\r
+ When keyslot is supported, you must use method 2, otherwise you should use method 1.\r
+ * @else\r
+ * @brief GCM 创建通道句柄.\r
+ * @param [out] handle 指向创建的通道句柄的指针.\r
+ * @param [in] key 加解密密钥.\r
+ * @param [in] key_len 加解密密钥长度,单位是 Byte. 只支持 16,24,32.\r
+ * @param [in] keyslot_handle 保存加解密密钥的 keyslot 句柄.\r
+ * @param [in] iv 初始向量\r
+ * @param [in] iv_len 初始向量长度,单位是 Byte.\r
+ * @param [in] aad 附加认证信息,支持传入为 NULL\r
+ * @param [in] aad_len 附加认证信息,单位是 Byte.\r
+ * @param [in] tag_len 期望的 tag 长度,单位是 Byte.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @note 有两种方法设置密钥:\r
+ 1)使用 key/key_len 组合,在这种情况下,keyslot_handle 传入 0.\r
+ 2)使用 keyslot 接口创建 keyslot 句柄传入,在这种情况下,key 传入为 NULL,key_len 传入为 0.\r
+ 若支持 keyslot,则必须使用方法2,否则只能使用方法1.\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_create(uint32_t *handle,\r
+ uint8_t *key, uint32_t key_len, uint32_t keyslot_handle,\r
+ const uint8_t *iv, uint32_t iv_len,\r
+ const uint8_t *aad, uint32_t aad_len,\r
+ uint32_t tag_len\r
+);\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief GCM destroy channel handle.\r
+ * @param [out] handle Channel handle to be destroyed.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @else\r
+ * @brief GCM 销毁通道句柄.\r
+ * @param [in] handle 待销毁的通道句柄.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_destroy(uint32_t handle);\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief GCM encrypt.\r
+ * @param [in] handle The created channel handle.\r
+ * @param [in] plain_text Input plain text.\r
+ * @param [out] cipher_text Output cipher text.\r
+ * @param [in] data_len data length in byte.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @note User can call this function more than one times to process data in fragments.\r
+ * @else\r
+ * @brief GCM 加密.\r
+ * @param [in] handle 已创建的通道句柄.\r
+ * @param [in] plain_text 输入的明文.\r
+ * @param [out] cipher_text 输出的密文.\r
+ * @param [in] data_len 数据长度,单位是 Byte.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @note 用户可以调用该函数多次来处理分段的数据.\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_encrypt_update(uint32_t handle,\r
+ const uint8_t *plain_text, uint8_t *cipher_text, uint32_t data_len\r
+);\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief GCM get tag after encryption.\r
+ * @param [in] handle The created channel handle.\r
+ * @param [out] tag Output tag.\r
+ * @param [in] tag_len The expected tag length in byte. The value must be the same as that of the\r
+ uapi_drv_cipher_symc_gcm_create interface.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @else\r
+ * @brief GCM 加密完获取 tag.\r
+ * @param [in] handle 已创建的通道句柄.\r
+ * @param [out] tag 输出的 tag\r
+ * @param [in] tag_len 期望的 tag 长度,单位是 Byte. 必须和传入 uapi_drv_cipher_symc_gcm_create 接口的值一致.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_encrypt_get_tag(uint32_t handle,\r
+ uint8_t *tag, uint32_t tag_len\r
+);\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief GCM set tag before verify.\r
+ * @param [in] handle The created channel handle.\r
+ * @param [in] tag Input tag to be verified.\r
+ * @param [in] tag_len The tag length in byte.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @else\r
+ * @brief GCM 校验前设置 tag.\r
+ * @param [in] handle 已创建的通道句柄.\r
+ * @param [out] tag 待校验的 tag.\r
+ * @param [in] tag_len tag 长度,单位是 Byte.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_decrypt_set_tag(uint32_t handle,\r
+ const uint8_t *tag, uint32_t tag_len\r
+);\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief GCM decrypt.\r
+ * @param [in] handle The created channel handle.\r
+ * @param [in] cipher_text Input cipher text.\r
+ * @param [out] plain_text Output plain text.\r
+ * @param [in] data_len data length in byte.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @note User can call this function more than one times to process data in fragments.\r
+ * @else\r
+ * @brief GCM 解密.\r
+ * @param [in] handle 已创建的通道句柄.\r
+ * @param [in] cipher_text 输入的密文.\r
+ * @param [out] plain_text 输出的明文.\r
+ * @param [in] data_len 数据长度,单位是 Byte.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @note 用户可以调用该函数多次来处理分段的数据.\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_decrypt_update(uint32_t handle,\r
+ const uint8_t *cipher_text, uint8_t *plain_text, uint32_t data_len\r
+);\r
+\r
+/**\r
+ * @if Eng\r
+ * @brief GCM verify tag after decrypt.\r
+ * @param [in] handle The created channel handle.\r
+ * @retval ERRCODE_SUCC Success.\r
+ * @retval Other Failure. For details, see @ref errcode_t\r
+ * @note Before invoking this interface, you must invoke uapi_drv_cipher_symc_gcm_decrypt_set_tag.\r
+ * @else\r
+ * @brief GCM 解密完校验 tag.\r
+ * @param [in] handle 已创建的通道句柄.\r
+ * @retval ERRCODE_SUCC 成功。\r
+ * @retval Other 失败,参考 @ref errcode_t 。\r
+ * @note 调用该接口前必须先调用 uapi_drv_cipher_symc_gcm_decrypt_set_tag.\r
+ * @endif\r
+ */\r
+errcode_t uapi_drv_cipher_symc_gcm_decrypt_verify_tag(uint32_t handle);\r
+\r
+/**\r
+ * @}\r
+ */\r
+\r
+#ifdef __cplusplus\r
+#if __cplusplus\r
+}\r
+#endif\r
+#endif\r
+\r
+#endif\r
PAN_NET_STATE_ON, /*!< @if Eng Online. @else 在线 @endif */
} pan_net_state_t;
+/**
+ * @if Eng
+ * @brief Enum of pan Network protocol type.
+ * @else
+ * @brief Pan 网络协议类型
+ * @endif
+ */
+typedef enum {
+ PAN_NETWORK_PROTOCOL_IPV4 = 0x0800, /*!< @if Eng Network protocol is IPV4.
+ @else 网络协议是IPV4 @endif */
+ PAN_NETWORK_PROTOCOL_ARP = 0x0806, /*!< @if Eng Network protocol is ARP.
+ @else 网络协议是ARP @endif */
+} pan_network_protocol_t;
+
+/**
+ * @if Eng
+ * @brief Enum of pan packet type.
+ * @else
+ * @brief Pan 报文类型
+ * @endif
+ */
+typedef enum {
+ PAN_PACKET_TYPE_DEST_ONLY_UNICAST = 0, /*!< @if Eng Packet type is dest only unicast.
+ @else 报文类型是保留目的地址的单播 @endif */
+ PAN_PACKET_TYPE_DEST_ONLY_BORADCAST = 1, /*!< @if Eng Packet type is dest only broadcast.
+ @else 报文类型是保留目的地址的广播 @endif */
+ PAN_PACKET_TYPE_GENERAL_UNICAST = 2, /*!< @if Eng Packet type is general unicast.
+ @else 报文类型是通用类型的单播 @endif */
+ PAN_PACKET_TYPE_GENERAL_BORADCAST = 3, /*!< @if Eng Packet type is general broadcast.
+ @else 报文类型是通用类型的广播 @endif */
+ PAN_PACKET_TYPE_COMPRESSED = 4, /*!< @if Eng Packet type is compressed.
+ @else 报文类型是压缩头报文 @endif */
+} pan_ethernet_packet_type_t;
+
+
/**
* @if Eng
* @brief Open the pan service.
* Send the ethernet.
* @param [in] ip_packet A poniter of the ethernet data.
* @param [in] ip_length The length of the ethernet data.
+ * @param [in] network_protocol network protocol, see @ref pan_network_protocol_t.
+ * @param [in] packet_type packet type, see @ref pan_ethernet_packet_type_t
* @retval #ERRCODE_BT_SUCCESS Success.
* @retval Other Failure. For details, see @ref errcode_bt_t
* @else
* 发送网络数据包
* @param [in] ip_packet 网络数据包指针
* @param [in] ip_length 网络数据包长度
+ * @param [in] network_protocol 网络协议类型, see @ref pan_network_protocol_t
+ * @param [in] packet_type 报文类型, see @ref pan_ethernet_packet_type_t
* @retval #ERRCODE_BT_SUCCESS 成功.
* @retval Other 失败. 参考 @ref errcode_bt_t
* @endif
* @par Dependency:
* @li pan_service.h
*/
-int pan_service_write_data(const unsigned char *ip_packet, const unsigned short ip_length);
+int pan_service_write_data(const unsigned char *ip_packet, const unsigned short ip_length,
+ uint16_t network_protocol, uint8_t packet_type);
/**
* @if Eng
* @par 说明:注册该回调函数之后,读取网络数据包结果反馈上层应用。
* @param [in] packet 指针,指向网络数据包所在内存地址.
* @param [in] packet_length 网络数据包长度.
+ * @param [in] network_protocol 网络协议类型, see @ref pan_network_protocol_t
* @retval 无返回值。参考 @ref void
* @endif
* @par Dependency:
* @li pan_service.h
*/
-typedef void (*pan_rpt_data_callback)(unsigned char *packet, unsigned short packet_length);
+typedef void (*pan_rpt_data_callback)(unsigned char *packet, unsigned short packet_length, uint16_t network_protocol);
/**
* @if Eng