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 {
31 struct list_head list;
34 const struct config_param_list *config_params;
36 struct device *(*create)(const char *name, struct blob_attr *attr);
37 void (*config_init)(struct device *);
38 enum dev_change_type (*reload)(struct device *, struct blob_attr *);
39 void (*dump_info)(struct device *, struct blob_buf *buf);
40 void (*dump_stats)(struct device *, struct blob_buf *buf);
41 int (*check_state)(struct device *);
42 void (*free)(struct device *);
46 DEV_OPT_MTU = (1 << 0),
47 DEV_OPT_MACADDR = (1 << 1),
48 DEV_OPT_TXQUEUELEN = (1 << 2)
51 /* events broadcasted to all users of a device */
66 * device dependency with callbacks
69 struct list_head list;
75 void (*cb)(struct device_user *, enum device_event);
78 struct device_settings {
81 unsigned int txqueuelen;
86 * link layer device. typically represents a linux network device.
87 * can be used to support VLANs as well
90 const struct device_type *type;
93 struct list_head users;
95 char ifname[IFNAMSIZ + 1];
98 struct blob_attr *config;
109 /* set interface up or down */
110 device_state_cb set_state;
112 const struct device_hotplug_ops *hotplug_ops;
114 struct device_user parent;
116 struct device_settings orig_settings;
117 struct device_settings settings;
120 struct device_hotplug_ops {
121 int (*prepare)(struct device *dev);
122 int (*add)(struct device *main, struct device *member);
123 int (*del)(struct device *main, struct device *member);
126 extern const struct config_param_list device_attr_list;
127 extern const struct device_type simple_device_type;
128 extern const struct device_type bridge_device_type;
130 void device_lock(void);
131 void device_unlock(void);
133 struct device *device_create(const char *name, const struct device_type *type,
134 struct blob_attr *config);
135 void device_init_settings(struct device *dev, struct blob_attr **tb);
136 void device_init_pending(void);
139 device_set_config(struct device *dev, const struct device_type *type,
140 struct blob_attr *attr);
142 void device_reset_config(void);
143 void device_reset_old(void);
145 void device_init_virtual(struct device *dev, const struct device_type *type, const char *name);
146 int device_init(struct device *iface, const struct device_type *type, const char *ifname);
147 void device_cleanup(struct device *iface);
148 struct device *device_get(const char *name, int create);
149 void device_add_user(struct device_user *dep, struct device *iface);
150 void device_remove_user(struct device_user *dep);
152 void device_set_present(struct device *dev, bool state);
153 void device_set_disabled(struct device *dev, bool value);
154 int device_claim(struct device_user *dep);
155 void device_release(struct device_user *dep);
156 int device_check_state(struct device *dev);
157 void device_dump_status(struct blob_buf *b, struct device *dev);
159 void device_free(struct device *dev);
160 void device_free_unused(struct device *dev);
162 struct device *get_vlan_device_chain(const char *ifname, bool create);
163 void alias_notify_device(const char *name, struct device *dev);