xiuos-test/APP_Framework/Framework/connection/adapter.h

233 lines
6.0 KiB
C
Raw Normal View History

2021-06-16 11:07:17 +08:00
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file adapter.h
2021-06-25 10:20:55 +08:00
* @brief Structure and function declarations of the connection adapter framework
* @version 1.1
2021-06-16 11:07:17 +08:00
* @author AIIT XUOS Lab
* @date 2021.05.10
*/
#ifndef ADAPTER_H
#define ADAPTER_H
#include <list.h>
#include <transform.h>
#include <stdio.h>
#include <string.h>
2021-06-16 11:07:17 +08:00
#include <stdint.h>
#include <sys/types.h>
#include <at_agent.h>
2021-06-16 11:07:17 +08:00
#ifdef __cplusplus
extern "C" {
#endif
2021-06-16 11:07:17 +08:00
#define ADAPTER_BUFFSIZE 64
2021-06-25 10:20:55 +08:00
#define ADAPTER_AT_OPERATION 1
#define ADAPTER_LWIP_OPERATION 2
#define ADAPTER_RAWIP_OPERATION 3
#ifdef CONNECTION_FRAMEWORK_DEBUG
#define ADAPTER_DEBUG printf
#else
#define ADAPTER_DEBUF
#endif
2021-06-16 11:07:17 +08:00
struct Adapter;
struct AdapterProductInfo;
2021-06-25 10:20:55 +08:00
typedef struct Adapter *AdapterType;
typedef struct AdapterProductInfo *AdapterProductInfoType;
2021-06-16 11:07:17 +08:00
struct Socket
{
int id;
struct Adapter *adapter;
};
enum AdapterType
{
ADAPTER_TYPE_LORA = 0,
ADAPTER_TYPE_4G ,
ADAPTER_TYPE_NBIOT ,
ADAPTER_TYPE_WIFI ,
ADAPTER_TYPE_ETHERNET ,
ADAPTER_TYPE_BLUETOOTH ,
ADAPTER_TYPE_ZIGBEE ,
ADAPTER_TYPE_5G ,
2021-06-16 11:07:17 +08:00
};
enum NetProtocolType
{
PRIVATE_PROTOCOL = 1,
IP_PROTOCOL,
PROTOCOL_NONE,
};
enum NetRoleType
{
CLIENT = 1,
SERVER,
2021-08-30 10:56:48 +08:00
MASTER,
SLAVE,
2021-09-24 15:22:19 +08:00
COORDINATOR,
ROUTER,
END_DEVICE,
2021-06-16 11:07:17 +08:00
ROLE_NONE,
};
2021-06-25 10:20:55 +08:00
enum AdapterStatus
{
REGISTERED = 1,
UNREGISTERED,
INSTALL,
UNINSTALL,
};
enum IpType
{
IPV4 = 1,
IPV6,
};
2021-06-16 11:07:17 +08:00
struct AdapterProductInfo
{
uint32_t functions;
char vendor_name[NAME_NUM_MAX];
char model_name[NAME_NUM_MAX];
2021-09-24 15:22:19 +08:00
uint32_t work_mode;
void *model_done;
2021-06-16 11:07:17 +08:00
};
struct IpProtocolDone
{
int (*open)(struct Adapter *adapter);
int (*close)(struct Adapter *adapter);
int (*ioctl)(struct Adapter *adapter, int cmd, void *args);
int (*setup)(struct Adapter *adapter);
int (*setdown)(struct Adapter *adapter);
int (*setaddr)(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask);
int (*setdns)(struct Adapter *adapter, const char *dns_addr, uint8 dns_count);
int (*setdhcp)(struct Adapter *adapter, int enable);
int (*ping)(struct Adapter *adapter, const char *destination);
int (*netstat)(struct Adapter *adapter);
int (*connect)(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type);
int (*send)(struct Adapter *adapter, const void *buf, size_t len);
int (*recv)(struct Adapter *adapter, void *buf, size_t len);
int (*disconnect)(struct Adapter *adapter);
2021-06-16 11:07:17 +08:00
};
struct PrivProtocolDone
{
int (*open)(struct Adapter *adapter);
int (*close)(struct Adapter *adapter);
int (*ioctl)(struct Adapter *adapter, int cmd, void *args);
int (*setup)(struct Adapter *adapter);
int (*setdown)(struct Adapter *adapter);
int (*setaddr)(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask);
int (*setdns)(struct Adapter *adapter, const char *dns_addr, uint8 dns_count);
int (*setdhcp)(struct Adapter *adapter, int enable);
int (*ping)(struct Adapter *adapter, const char *destination);
int (*netstat)(struct Adapter *adapter);
2021-06-16 11:07:17 +08:00
int (*join)(struct Adapter *adapter, const char *priv_net_group);
int (*send)(struct Adapter *adapter, const void *buf, size_t len);
int (*recv)(struct Adapter *adapter, void *buf, size_t len);
int (*quit)(struct Adapter *adapter);
2021-06-16 11:07:17 +08:00
};
struct Adapter
{
char name[NAME_NUM_MAX];
2021-06-16 11:07:17 +08:00
int fd;
int product_info_flag;
2021-06-16 11:07:17 +08:00
struct AdapterProductInfo *info;
ATAgentType agent;
//struct Socket *socket;
2021-06-16 11:07:17 +08:00
enum NetProtocolType net_protocol;
enum NetRoleType net_role;
2021-06-25 10:20:55 +08:00
enum AdapterStatus adapter_status;
2021-06-16 11:07:17 +08:00
char buffer[ADAPTER_BUFFSIZE];
void *done;
struct DoublelistNode link;
2021-06-16 11:07:17 +08:00
};
2021-06-25 10:20:55 +08:00
/*Init adapter framework*/
int AdapterFrameworkInit(void);
/*Find adapter device by name*/
AdapterType AdapterDeviceFindByName(const char *name);
/*Register the adapter to the linked list*/
int AdapterDeviceRegister(struct Adapter *adapter);
/*Unregister the adapter from the linked list*/
int AdapterDeviceUnregister(struct Adapter *adapter);
/*Open adapter device*/
int AdapterDeviceOpen(struct Adapter *adapter);
2021-06-25 10:20:55 +08:00
/*Close adapter device*/
int AdapterDeviceClose(struct Adapter *adapter);
/*Receice data from adapter*/
ssize_t AdapterDeviceRecv(struct Adapter *adapter, void *dst, size_t len);
/*Send data to adapter*/
ssize_t AdapterDeviceSend(struct Adapter *adapter, const void *src, size_t len);
/*Configure adapter device*/
int AdapterDeviceControl(struct Adapter *adapter, int cmd, void *args);
/*Connect to a certain ip net, only support IP_PROTOCOL*/
int AdapterDeviceConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type);
2021-06-25 10:20:55 +08:00
/*Join to a certain private net, only support PRIVATE_PROTOCOL*/
int AdapterDeviceJoin(struct Adapter *adapter, const char *priv_net_group);
/*Adapter disconnect from ip net or private net group*/
int AdapterDeviceDisconnect(struct Adapter *adapter);
2021-08-30 10:56:48 +08:00
/*Set up to net*/
int AdapterDeviceSetUp(struct Adapter *adapter);
2021-08-30 10:56:48 +08:00
/*Set down from net*/
int AdapterDeviceSetDown(struct Adapter *adapter);
2021-08-30 10:56:48 +08:00
/*Set ip/gateway/netmask address*/
int AdapterDeviceSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask);
2021-08-30 10:56:48 +08:00
/**/
int AdapterDeviceSetDns(struct Adapter *adapter, const char *dns_addr, uint8 dns_count);
2021-08-30 10:56:48 +08:00
/**/
int AdapterDeviceSetDhcp(struct Adapter *adapter, int enable);
2021-08-30 10:56:48 +08:00
/*ping function*/
int AdapterDevicePing(struct Adapter *adapter, const char *destination);
2021-08-30 10:56:48 +08:00
/*Show the net status*/
int AdapterDeviceNetstat(struct Adapter *adapter);
#ifdef __cplusplus
}
#endif
2021-06-16 11:07:17 +08:00
#endif