OpenHarmony源码分析之分布式软总线:authmanager/auth_conn.h

📌往期推文全新看点(文中附带最新·鸿蒙全栈学习笔记)

①📖 鸿蒙应用开发与鸿蒙系统开发哪个更有前景?

②📖嵌入式开发适不适合做鸿蒙南向开发?看完这篇你就了解了~

③📖 对于大前端开发来说,转鸿蒙开发究竟是福还是祸?

④📖 鸿蒙岗位需求突增!移动端、PC端、IoT到底该怎么选?

⑤📖 记录一场鸿蒙开发岗位面试经历~

⑥📖 持续更新中……


一、概述

该头文件定义了与设备认证连接相关的接口、宏和结构体,本文将对其深刻含义进行介绍。

二、源码分析

auth_conn.h

/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef LITE_AUTH_CONN_H
#define LITE_AUTH_CONN_H
#include "cJSON.h"
#include "common_info_manager.h"
#include "comm_defs.h"
#define MESSAGE_INDEX_LEN 4     //消息索引长度
#define MESSAGE_GCM_NONCE_LEN 12    //GCM加密的消息的NONCE长度
#define MESSAGE_GCM_MAC_LEN 16      //GCM加密的消息的MAC长度
#define MESSAGE_ENCRYPT_OVER_HEAD_LEN (MESSAGE_INDEX_LEN + MESSAGE_GCM_NONCE_LEN + MESSAGE_GCM_MAC_LEN)     //GCM加密的消息的头部长度
#define DEFAULT_BUF_SIZE 1536   //默认缓冲区大小
#define PACKET_HEAD_SIZE 24     //认证协议数据包头部长度
#define PACKET_DATA_SIZE (DEFAULT_BUF_SIZE - PACKET_HEAD_SIZE)
#define PKG_HEADER_IDENTIFIER 0xBABEFACE    //数据包标识号
#define ONLINE_UNKNOWN 0    //未知状态设备
#define ONLINE_YES 1        //在线设备
#define ONLINE_NO (-1)      //离线设备
/*数据包类型*/
#define MODULE_NONE 0
#define MODULE_TRUST_ENGINE 1   //可信设备
#define MODULE_HICHAIN 2
#define MODULE_AUTH_SDK 3       //待认证设备
#define MODULE_HICHAIN_SYNC 4
#define MODULE_CONNECTION 5     //验证IP和设备id
#define MODULE_SESSION 6
#define MODULE_SMART_COMM 7
#define MODULE_AUTH_CHANNEL 8
#define MODULE_AUTH_MSG 9
#define FLAG_REPLY 1    //表示回复消息
#define AUTH_UNKNOWN 0  
#define AUTH_INIT 1
/*用于设备通信的数据缓冲区*/
typedef struct DataBuffer {
    char *buf;//缓冲区首地址
    int size;//缓冲区大小
    int used;//缓冲区已使用量
} DataBuffer;
/*AuthConn结构体用于保存已建立socket连接的身份认证设备的基本信息以及状态信息*/
typedef struct AuthConn {
    int fd;//通信套接字描述符
    char authId[MAX_AUTH_ID_LEN];//身份认证id
    char deviceId[MAX_DEV_ID_LEN];//设备id
    char deviceIp[MAX_DEV_IP_LEN];//设备IP
    int busVersion;//总线版本
    int authPort;//认证通道端口
    int sessionPort;//会话通道端口
    int authState;//认证状态
    int onlineState;//设备在线状态
    DataBuffer db;//数据缓冲区
} AuthConn;
/*设备身份认证连接节点*/
typedef struct AuthConnNode {
    List head;
    AuthConn *aconn;
} AuthConnNode;
/*设备连接信息*/
typedef struct ConnInfo {
    int maxVersion;//最大版本号
    int minVersion;//最小版本号
    char deviceName[MAX_DEV_NAME_LEN];//设备名称
    char deviceType[MAX_DEV_TYPE_LEN];//设备类型
} ConnInfo;
int AuthConnRecv(int fd, char *buf, int offset, int count, int timeout);//接收设备认证过程中传输的数据
int AuthConnPostBytes(int fd, int module, int flags, long long seq, const char *data);//按字节构造身份认证连接的POST消息并通过TCP协议发送
int AuthConnPostMessage(int fd, int module, int flags, long long seqNum, const cJSON *msg);//构造/封装身份认证Post消息并发送给对端
bool ModuleUseCipherText(int module);//根据module参数判断是否使用密文传输
unsigned char* AuthConnPackBytes(int module, int flags, long long seqNum, const char *str, int *bufLen);//按字节构造设备身份认证数据包
#endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值