1/*
2 * Copyright 2006-2017, 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
18struct net_device_handler : DoublyLinkedListLinkImpl<net_device_handler> {
19	net_receive_func	func;
20	int32				type;
21	void*				cookie;
22};
23
24typedef DoublyLinkedList<net_device_handler> DeviceHandlerList;
25
26typedef DoublyLinkedList<net_device_monitor,
27	DoublyLinkedListCLink<net_device_monitor> > DeviceMonitorList;
28
29struct 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	bool				busy;
36
37	net_deframe_func	deframe_func;
38	int32				deframe_ref_count;
39
40	int32				monitor_count;
41	recursive_lock		monitor_lock;
42	DeviceMonitorList	monitor_funcs;
43
44	DeviceHandlerList	receive_funcs;
45	recursive_lock		receive_lock;
46
47	thread_id			consumer_thread;
48	net_fifo			receive_queue;
49};
50
51typedef DoublyLinkedList<net_device_interface> DeviceInterfaceList;
52
53
54// device interfaces
55net_device_interface* acquire_device_interface(net_device_interface* interface);
56void get_device_interface_address(net_device_interface* interface,
57	sockaddr* address);
58uint32 count_device_interfaces();
59status_t list_device_interfaces(void* buffer, size_t* _bufferSize);
60void put_device_interface(struct net_device_interface* interface);
61struct net_device_interface* get_device_interface(uint32 index);
62struct net_device_interface* get_device_interface(const char* name,
63	bool create = true);
64void device_interface_monitor_receive(net_device_interface* interface,
65	net_buffer* buffer);
66status_t up_device_interface(net_device_interface* interface);
67void down_device_interface(net_device_interface* interface);
68
69// devices
70status_t unregister_device_deframer(net_device* device);
71status_t register_device_deframer(net_device* device,
72	net_deframe_func deframeFunc);
73status_t register_domain_device_handler(struct net_device* device, int32 type,
74	struct net_domain* domain);
75status_t register_device_handler(struct net_device* device, int32 type,
76	net_receive_func receiveFunc, void* cookie);
77status_t unregister_device_handler(struct net_device* device, int32 type);
78status_t register_device_monitor(struct net_device* device,
79	struct net_device_monitor* monitor);
80status_t unregister_device_monitor(struct net_device* device,
81	struct net_device_monitor* monitor);
82status_t device_link_changed(net_device* device);
83status_t device_removed(net_device* device);
84status_t device_enqueue_buffer(net_device* device, net_buffer* buffer);
85
86status_t init_device_interfaces();
87status_t uninit_device_interfaces();
88
89
90#endif	// DEVICE_INTERFACES_H
91