xref: /haiku/src/add-ons/kernel/network/stack/device_interfaces.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
1 /*
2  * Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  */
8 #ifndef DEVICE_INTERFACES_H
9 #define DEVICE_INTERFACES_H
10 
11 
12 #include <net_datalink.h>
13 #include <net_stack.h>
14 
15 #include <util/DoublyLinkedList.h>
16 
17 
18 struct net_device_handler : DoublyLinkedListLinkImpl<net_device_handler> {
19 	net_receive_func	func;
20 	int32				type;
21 	void*				cookie;
22 };
23 
24 typedef DoublyLinkedList<net_device_handler> DeviceHandlerList;
25 
26 typedef DoublyLinkedList<net_device_monitor,
27 	DoublyLinkedListCLink<net_device_monitor> > DeviceMonitorList;
28 
29 struct net_device_interface : DoublyLinkedListLinkImpl<net_device_interface> {
30 	struct net_device*	device;
31 	thread_id			reader_thread;
32 	uint32				up_count;
33 		// a device can be brought up by more than one interface
34 	int32				ref_count;
35 
36 	net_deframe_func	deframe_func;
37 	int32				deframe_ref_count;
38 
39 	int32				monitor_count;
40 	mutex				monitor_lock;
41 	DeviceMonitorList	monitor_funcs;
42 
43 	DeviceHandlerList	receive_funcs;
44 	recursive_lock		receive_lock;
45 
46 	thread_id			consumer_thread;
47 	net_fifo			receive_queue;
48 };
49 
50 typedef DoublyLinkedList<net_device_interface> DeviceInterfaceList;
51 
52 
53 // device interfaces
54 net_device_interface* acquire_device_interface(net_device_interface* interface);
55 void get_device_interface_address(net_device_interface* interface,
56 	sockaddr* address);
57 uint32 count_device_interfaces();
58 status_t list_device_interfaces(void* buffer, size_t* _bufferSize);
59 void put_device_interface(struct net_device_interface* interface);
60 struct net_device_interface* get_device_interface(uint32 index);
61 struct net_device_interface* get_device_interface(const char* name,
62 	bool create = true);
63 void device_interface_monitor_receive(net_device_interface* interface,
64 	net_buffer* buffer);
65 status_t up_device_interface(net_device_interface* interface);
66 void down_device_interface(net_device_interface* interface);
67 
68 // devices
69 status_t unregister_device_deframer(net_device* device);
70 status_t register_device_deframer(net_device* device,
71 	net_deframe_func deframeFunc);
72 status_t register_domain_device_handler(struct net_device* device, int32 type,
73 	struct net_domain* domain);
74 status_t register_device_handler(struct net_device* device, int32 type,
75 	net_receive_func receiveFunc, void* cookie);
76 status_t unregister_device_handler(struct net_device* device, int32 type);
77 status_t register_device_monitor(struct net_device* device,
78 	struct net_device_monitor* monitor);
79 status_t unregister_device_monitor(struct net_device* device,
80 	struct net_device_monitor* monitor);
81 status_t device_link_changed(net_device* device);
82 status_t device_removed(net_device* device);
83 status_t device_enqueue_buffer(net_device* device, net_buffer* buffer);
84 
85 status_t init_device_interfaces();
86 status_t uninit_device_interfaces();
87 
88 
89 #endif	// DEVICE_INTERFACES_H
90