4 #include <libubox/avl.h>
5 #include <netinet/in.h>
9 struct device_hotplug_ops;
11 typedef int (*device_state_cb)(struct device *, bool up);
23 enum dev_change_type {
30 struct list_head list;
33 const struct config_param_list *config_params;
35 struct device *(*create)(const char *name, struct blob_attr *attr);
36 void (*config_init)(struct device *);
37 enum dev_change_type (*reload)(struct device *, struct blob_attr *);
38 void (*dump_info)(struct device *, struct blob_buf *buf);
39 void (*dump_stats)(struct device *, struct blob_buf *buf);
40 int (*check_state)(struct device *);
41 void (*free)(struct device *);
45 DEV_OPT_MTU = (1 << 0),
46 DEV_OPT_MACADDR = (1 << 1),
47 DEV_OPT_TXQUEUELEN = (1 << 2)
50 /* events broadcasted to all users of a device */
65 * device dependency with callbacks
68 struct list_head list;
74 void (*cb)(struct device_user *, enum device_event);
77 struct device_settings {
80 unsigned int txqueuelen;
85 * link layer device. typically represents a linux network device.
86 * can be used to support VLANs as well
89 const struct device_type *type;
92 struct list_head users;
94 char ifname[IFNAMSIZ + 1];
97 struct blob_attr *config;
108 /* set interface up or down */
109 device_state_cb set_state;
111 const struct device_hotplug_ops *hotplug_ops;
113 struct device_user parent;
115 struct device_settings orig_settings;
116 struct device_settings settings;
119 struct device_hotplug_ops {
120 int (*prepare)(struct device *dev);
121 int (*add)(struct device *main, struct device *member);
122 int (*del)(struct device *main, struct device *member);
125 extern const struct config_param_list device_attr_list;
126 extern const struct device_type simple_device_type;
127 extern const struct device_type bridge_device_type;
129 void device_lock(void);
130 void device_unlock(void);
132 struct device *device_create(const char *name, const struct device_type *type,
133 struct blob_attr *config);
134 void device_init_settings(struct device *dev, struct blob_attr **tb);
135 void device_init_pending(void);
138 device_set_config(struct device *dev, const struct device_type *type,
139 struct blob_attr *attr);
141 void device_reset_config(void);
142 void device_reset_old(void);
144 void device_init_virtual(struct device *dev, const struct device_type *type, const char *name);
145 int device_init(struct device *iface, const struct device_type *type, const char *ifname);
146 void device_cleanup(struct device *iface);
147 struct device *device_get(const char *name, int create);
148 void device_add_user(struct device_user *dep, struct device *iface);
149 void device_remove_user(struct device_user *dep);
151 void device_set_present(struct device *dev, bool state);
152 void device_set_disabled(struct device *dev, bool value);
153 int device_claim(struct device_user *dep);
154 void device_release(struct device_user *dep);
155 int device_check_state(struct device *dev);
156 void device_dump_status(struct blob_buf *b, struct device *dev);
158 void device_free(struct device *dev);
159 void device_free_unused(struct device *dev);
161 struct device *get_vlan_device_chain(const char *ifname, bool create);
162 void alias_notify_device(const char *name, struct device *dev);