xref: /haiku/src/add-ons/kernel/network/stack/device_interfaces.h (revision f17488662a661029abeba1594c92904f7670c406)
161729d93SAxel Dörfler /*
2*f1748866SAxel Dörfler  * Copyright 2006-2017, Haiku, Inc. All Rights Reserved.
361729d93SAxel Dörfler  * Distributed under the terms of the MIT License.
461729d93SAxel Dörfler  *
561729d93SAxel Dörfler  * Authors:
661729d93SAxel Dörfler  *		Axel Dörfler, axeld@pinc-software.de
761729d93SAxel Dörfler  */
861729d93SAxel Dörfler #ifndef DEVICE_INTERFACES_H
961729d93SAxel Dörfler #define DEVICE_INTERFACES_H
1061729d93SAxel Dörfler 
1161729d93SAxel Dörfler 
1261729d93SAxel Dörfler #include <net_datalink.h>
1361729d93SAxel Dörfler #include <net_stack.h>
1461729d93SAxel Dörfler 
1561729d93SAxel Dörfler #include <util/DoublyLinkedList.h>
1661729d93SAxel Dörfler 
1761729d93SAxel Dörfler 
1861729d93SAxel Dörfler struct net_device_handler : DoublyLinkedListLinkImpl<net_device_handler> {
1961729d93SAxel Dörfler 	net_receive_func	func;
2061729d93SAxel Dörfler 	int32				type;
2161729d93SAxel Dörfler 	void*				cookie;
2261729d93SAxel Dörfler };
2361729d93SAxel Dörfler 
2461729d93SAxel Dörfler typedef DoublyLinkedList<net_device_handler> DeviceHandlerList;
2561729d93SAxel Dörfler 
2661729d93SAxel Dörfler typedef DoublyLinkedList<net_device_monitor,
2761729d93SAxel Dörfler 	DoublyLinkedListCLink<net_device_monitor> > DeviceMonitorList;
2861729d93SAxel Dörfler 
2961729d93SAxel Dörfler struct net_device_interface : DoublyLinkedListLinkImpl<net_device_interface> {
3061729d93SAxel Dörfler 	struct net_device*	device;
3161729d93SAxel Dörfler 	thread_id			reader_thread;
3261729d93SAxel Dörfler 	uint32				up_count;
3361729d93SAxel Dörfler 		// a device can be brought up by more than one interface
3461729d93SAxel Dörfler 	int32				ref_count;
35*f1748866SAxel Dörfler 	bool				busy;
3661729d93SAxel Dörfler 
3761729d93SAxel Dörfler 	net_deframe_func	deframe_func;
3861729d93SAxel Dörfler 	int32				deframe_ref_count;
3961729d93SAxel Dörfler 
40fee56868SAxel Dörfler 	int32				monitor_count;
41ef860b2eSStefano Ceccherini 	recursive_lock		monitor_lock;
4261729d93SAxel Dörfler 	DeviceMonitorList	monitor_funcs;
4361729d93SAxel Dörfler 
44fee56868SAxel Dörfler 	DeviceHandlerList	receive_funcs;
4561729d93SAxel Dörfler 	recursive_lock		receive_lock;
4661729d93SAxel Dörfler 
4761729d93SAxel Dörfler 	thread_id			consumer_thread;
4861729d93SAxel Dörfler 	net_fifo			receive_queue;
4961729d93SAxel Dörfler };
5061729d93SAxel Dörfler 
5161729d93SAxel Dörfler typedef DoublyLinkedList<net_device_interface> DeviceInterfaceList;
5261729d93SAxel Dörfler 
5361729d93SAxel Dörfler 
5461729d93SAxel Dörfler // device interfaces
5561729d93SAxel Dörfler net_device_interface* acquire_device_interface(net_device_interface* interface);
5661729d93SAxel Dörfler void get_device_interface_address(net_device_interface* interface,
5761729d93SAxel Dörfler 	sockaddr* address);
5861729d93SAxel Dörfler uint32 count_device_interfaces();
5961729d93SAxel Dörfler status_t list_device_interfaces(void* buffer, size_t* _bufferSize);
6061729d93SAxel Dörfler void put_device_interface(struct net_device_interface* interface);
6161729d93SAxel Dörfler struct net_device_interface* get_device_interface(uint32 index);
6261729d93SAxel Dörfler struct net_device_interface* get_device_interface(const char* name,
6361729d93SAxel Dörfler 	bool create = true);
64fee56868SAxel Dörfler void device_interface_monitor_receive(net_device_interface* interface,
65fee56868SAxel Dörfler 	net_buffer* buffer);
6661729d93SAxel Dörfler status_t up_device_interface(net_device_interface* interface);
6761729d93SAxel Dörfler void down_device_interface(net_device_interface* interface);
6861729d93SAxel Dörfler 
6961729d93SAxel Dörfler // devices
7061729d93SAxel Dörfler status_t unregister_device_deframer(net_device* device);
71fee56868SAxel Dörfler status_t register_device_deframer(net_device* device,
72fee56868SAxel Dörfler 	net_deframe_func deframeFunc);
7361729d93SAxel Dörfler status_t register_domain_device_handler(struct net_device* device, int32 type,
7461729d93SAxel Dörfler 	struct net_domain* domain);
7561729d93SAxel Dörfler status_t register_device_handler(struct net_device* device, int32 type,
7661729d93SAxel Dörfler 	net_receive_func receiveFunc, void* cookie);
7761729d93SAxel Dörfler status_t unregister_device_handler(struct net_device* device, int32 type);
7861729d93SAxel Dörfler status_t register_device_monitor(struct net_device* device,
7961729d93SAxel Dörfler 	struct net_device_monitor* monitor);
8061729d93SAxel Dörfler status_t unregister_device_monitor(struct net_device* device,
8161729d93SAxel Dörfler 	struct net_device_monitor* monitor);
8261729d93SAxel Dörfler status_t device_link_changed(net_device* device);
8361729d93SAxel Dörfler status_t device_removed(net_device* device);
8461729d93SAxel Dörfler status_t device_enqueue_buffer(net_device* device, net_buffer* buffer);
8561729d93SAxel Dörfler 
8661729d93SAxel Dörfler status_t init_device_interfaces();
8761729d93SAxel Dörfler status_t uninit_device_interfaces();
8861729d93SAxel Dörfler 
8961729d93SAxel Dörfler 
9061729d93SAxel Dörfler #endif	// DEVICE_INTERFACES_H
91