-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommon.h
70 lines (59 loc) · 1.57 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (C) Bouffalo Lab 2016-2023
* SPDX-License-Identifier: GPL-2.0-only
*/
#ifndef COMMON_H_KCJUM19Y
#define COMMON_H_KCJUM19Y
#ifdef BUILD_USERSPACE
#include <stdint.h>
#else
#include <linux/kernel.h>
#endif
#define DEVICE_NAME "/dev/blctlport"
#define CTL_PORT_MSG_LEN_MAX 4096
#define PACKED_STRUCT struct __attribute__((packed))
enum ctl_port_event {
CTL_PORT_MSG_CONNECT_REQ,
CTL_PORT_MSG_CONNECT_RSP,
CTL_PORT_MSG_DISCONNECT_REQ,
CTL_PORT_MSG_DISCONNECT_RSP,
CTL_PORT_MSG_DISCONNECT_ALL_REQ,
CTL_PORT_MSG_DISCONNECT_ALL_RSP,
CTL_PORT_MSG_TRANSPARENT_HOST2DEVICE,
CTL_PORT_MSG_TRANSPARENT_DEVICE2HOST,
CTL_PORT_MSG_CARD_INSERTED,
CTL_PORT_MSG_CARD_DEAD,
CTL_PORT_MSG_IP_UPDATE,
CTL_PORT_MSG_DISCONNECT,
};
enum {
CTL_PORT_ERROR_CODE_LENGTH = -100,
CTL_PORT_ERROR_CODE_UNKNOWN_CMD,
};
#define CTL_PORT_MSG_MAGIC "BFLBMESG"
typedef PACKED_STRUCT {
uint8_t magic[8];
uint16_t type;
uint16_t length; // including hdr, payload
uint32_t msg_id;
uint8_t payload[];
} ctl_port_msg_hdr_t;
PACKED_STRUCT ip_info {
uint8_t ip4_addr[4];
uint8_t ip4_mask[4];
uint8_t ip4_gw[4];
uint8_t ip4_dns1[4];
uint8_t ip4_dns2[4];
uint8_t gw_mac[6];
};
#define CTL_PORT_MSG_HDR_LEN (sizeof(ctl_port_msg_hdr_t))
typedef PACKED_STRUCT {
ctl_port_msg_hdr_t hdr;
struct ip_info ip_info;
} ctl_port_msg_ip_update_t;
typedef PACKED_STRUCT {
ctl_port_msg_hdr_t hdr;
uint8_t success;
uint16_t session_id;
} ctl_port_msg_conn_rsp_t;
#endif /* end of include guard: COMMON_H_KCJUM19Y */