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
14enum CTRL_NODE_CMD {
15	CMD_UPDATE_SOCKET = 0,
16	CMD_UPDATE_DEVSL,
17	CMD_OFF_LINE,
18	CMD_CNT,
19};
20
21struct 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
30struct update_devsl_param {
31    int32_t cmd;
32    uint32_t devsl;
33    uint8_t cid[HMDFS_CID_SIZE];
34} __attribute__((packed));
35
36struct offline_param {
37	int32_t cmd;
38	uint8_t remote_cid[HMDFS_CID_SIZE];
39} __packed;
40
41struct offline_all_param {
42	int32_t cmd;
43} __packed;
44
45enum NOTIFY {
46	NOTIFY_GET_SESSION,
47	NOTIFY_OFFLINE,
48	NOTIFY_NONE,
49	NOTIFY_CNT,
50};
51
52struct notify_param {
53	int32_t notify;
54	int32_t fd;
55	uint8_t remote_cid[HMDFS_CID_SIZE];
56} __packed;
57
58struct 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
66struct 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
74struct sbi_cmd_attribute {
75	struct attribute attr;
76	int command;
77};
78
79void notify(struct hmdfs_peer *node, struct notify_param *param);
80int hmdfs_register_sysfs(const char *name, struct hmdfs_sb_info *sbi);
81void hmdfs_unregister_sysfs(struct hmdfs_sb_info *sbi);
82void hmdfs_release_sysfs(struct hmdfs_sb_info *sbi);
83int hmdfs_register_peer_sysfs(struct hmdfs_sb_info *sbi,
84			      struct hmdfs_peer *peer);
85void hmdfs_release_peer_sysfs(struct hmdfs_peer *peer);
86int hmdfs_sysfs_init(void);
87void hmdfs_sysfs_exit(void);
88
89static inline struct sbi_attribute *to_sbi_attr(struct attribute *x)
90{
91	return container_of(x, struct sbi_attribute, attr);
92}
93
94static inline struct hmdfs_sb_info *to_sbi(struct kobject *x)
95{
96	return container_of(x, struct hmdfs_sb_info, kobj);
97}
98
99static inline struct peer_attribute *to_peer_attr(struct attribute *x)
100{
101	return container_of(x, struct peer_attribute, attr);
102}
103
104static inline struct hmdfs_peer *to_peer(struct kobject *x)
105{
106	return container_of(x, struct hmdfs_peer, kobj);
107}
108#endif
109