fix interface object type name
[project/netifd.git] / device.h
1 #ifndef __LL_H
2 #define __LL_H
3
4 #include <libubox/avl.h>
5
6 struct device;
7 struct device_hotplug_ops;
8
9 typedef int (*device_state_cb)(struct device *, bool up);
10
11 struct device_type {
12         const char *name;
13
14         int (*check_state)(struct device *);
15         void (*free)(struct device *);
16 };
17
18 /* 
19  * link layer device. typically represents a linux network device.
20  * can be used to support VLANs as well
21  */
22 struct device {
23         const struct device_type *type;
24
25         struct avl_node avl;
26         struct list_head users;
27
28         char ifname[IFNAMSIZ + 1];
29         int ifindex;
30
31         bool present;
32         int active;
33
34         /* set interface up or down */
35         device_state_cb set_state;
36
37         const struct device_hotplug_ops *hotplug_ops;
38 };
39
40 /* events broadcasted to all users of a device */
41 enum device_event {
42         /* device has been added to the system and can be brought up */
43         DEV_EVENT_ADD,
44
45         /* device has been removed */
46         DEV_EVENT_REMOVE,
47
48         /* device is being brought up */
49         DEV_EVENT_SETUP,
50
51         /* device is being brought down */
52         DEV_EVENT_TEARDOWN,
53
54         /* device has been brought up */
55         DEV_EVENT_UP,
56
57         /* device has been brought down */
58         DEV_EVENT_DOWN,
59
60         /* device has changed its link state to up */
61         DEV_EVENT_LINK_UP,
62
63         /* device has changed its link state to down */
64         DEV_EVENT_LINK_DOWN,
65 };
66
67 /*
68  * device dependency with callbacks
69  */
70 struct device_user {
71         struct list_head list;
72
73         struct device *dev;
74         void (*cb)(struct device_user *, enum device_event);
75 };
76
77 struct device_hotplug_ops {
78         int (*add)(struct device *main, struct device *member);
79         int (*del)(struct device *main, struct device *member);
80 };
81
82 int init_device(struct device *iface, const struct device_type *type, const char *ifname);
83 void cleanup_device(struct device *iface);
84 struct device *get_device(const char *name, bool create);
85 void add_device_user(struct device_user *dep, struct device *iface);
86 void remove_device_user(struct device_user *dep);
87
88 void set_device_present(struct device *dev, bool state);
89 int claim_device(struct device *dev);
90 void release_device(struct device *dev);
91 int check_device_state(struct device *dev);
92
93 struct device *get_vlan_device_chain(const char *ifname, bool create);
94
95 #endif