1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * fs/hmdfs/comm/device_node.h
4 *
5 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
6 */
7
8 #ifndef HMDFS_DEVICE_NODE_H
9 #define HMDFS_DEVICE_NODE_H
10
11 #include "hmdfs.h"
12 #include "transport.h"
13
14 enum CTRL_NODE_CMD {
15 CMD_UPDATE_SOCKET = 0,
16 CMD_UPDATE_DEVSL,
17 CMD_OFF_LINE,
18 CMD_CNT,
19 };
20
21 struct update_socket_param {
22 int32_t cmd;
23 int32_t newfd;
24 uint32_t devsl;
25 uint8_t status;
26 uint8_t masterkey[HMDFS_KEY_SIZE];
27 uint8_t cid[HMDFS_CID_SIZE];
28 } __packed;
29
30 struct update_devsl_param {
31 int32_t cmd;
32 uint32_t devsl;
33 uint8_t cid[HMDFS_CID_SIZE];
34 } __attribute__((packed));
35
36 struct offline_param {
37 int32_t cmd;
38 uint8_t remote_cid[HMDFS_CID_SIZE];
39 } __packed;
40
41 struct offline_all_param {
42 int32_t cmd;
43 } __packed;
44
45 enum NOTIFY {
46 NOTIFY_GET_SESSION,
47 NOTIFY_OFFLINE,
48 NOTIFY_NONE,
49 NOTIFY_CNT,
50 };
51
52 struct notify_param {
53 int32_t notify;
54 int32_t fd;
55 uint8_t remote_cid[HMDFS_CID_SIZE];
56 } __packed;
57
58 struct sbi_attribute {
59 struct attribute attr;
60 ssize_t (*show)(struct kobject *kobj, struct sbi_attribute *attr,
61 char *buf);
62 ssize_t (*store)(struct kobject *kobj, struct sbi_attribute *attr,
63 const char *buf, size_t len);
64 };
65
66 struct peer_attribute {
67 struct attribute attr;
68 ssize_t (*show)(struct kobject *kobj, struct peer_attribute *attr,
69 char *buf);
70 ssize_t (*store)(struct kobject *kobj, struct peer_attribute *attr,
71 const char *buf, size_t len);
72 };
73
74 struct sbi_cmd_attribute {
75 struct attribute attr;
76 int command;
77 };
78
79 void notify(struct hmdfs_peer *node, struct notify_param *param);
80 int hmdfs_register_sysfs(const char *name, struct hmdfs_sb_info *sbi);
81 void hmdfs_unregister_sysfs(struct hmdfs_sb_info *sbi);
82 void hmdfs_release_sysfs(struct hmdfs_sb_info *sbi);
83 int hmdfs_register_peer_sysfs(struct hmdfs_sb_info *sbi,
84 struct hmdfs_peer *peer);
85 void hmdfs_release_peer_sysfs(struct hmdfs_peer *peer);
86 int hmdfs_sysfs_init(void);
87 void hmdfs_sysfs_exit(void);
88
to_sbi_attr(struct attribute * x)89 static inline struct sbi_attribute *to_sbi_attr(struct attribute *x)
90 {
91 return container_of(x, struct sbi_attribute, attr);
92 }
93
to_sbi(struct kobject * x)94 static inline struct hmdfs_sb_info *to_sbi(struct kobject *x)
95 {
96 return container_of(x, struct hmdfs_sb_info, kobj);
97 }
98
to_peer_attr(struct attribute * x)99 static inline struct peer_attribute *to_peer_attr(struct attribute *x)
100 {
101 return container_of(x, struct peer_attribute, attr);
102 }
103
to_peer(struct kobject * x)104 static inline struct hmdfs_peer *to_peer(struct kobject *x)
105 {
106 return container_of(x, struct hmdfs_peer, kobj);
107 }
108 #endif
109