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 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 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 51 typedef DoublyLinkedList<net_device_interface> DeviceInterfaceList; 52 53 54 // device interfaces 55 net_device_interface* acquire_device_interface(net_device_interface* interface); 56 void get_device_interface_address(net_device_interface* interface, 57 sockaddr* address); 58 uint32 count_device_interfaces(); 59 status_t list_device_interfaces(void* buffer, size_t* _bufferSize); 60 void put_device_interface(struct net_device_interface* interface); 61 struct net_device_interface* get_device_interface(uint32 index); 62 struct net_device_interface* get_device_interface(const char* name, 63 bool create = true); 64 void device_interface_monitor_receive(net_device_interface* interface, 65 net_buffer* buffer); 66 status_t up_device_interface(net_device_interface* interface); 67 void down_device_interface(net_device_interface* interface); 68 69 // devices 70 status_t unregister_device_deframer(net_device* device); 71 status_t register_device_deframer(net_device* device, 72 net_deframe_func deframeFunc); 73 status_t register_domain_device_handler(struct net_device* device, int32 type, 74 struct net_domain* domain); 75 status_t register_device_handler(struct net_device* device, int32 type, 76 net_receive_func receiveFunc, void* cookie); 77 status_t unregister_device_handler(struct net_device* device, int32 type); 78 status_t register_device_monitor(struct net_device* device, 79 struct net_device_monitor* monitor); 80 status_t unregister_device_monitor(struct net_device* device, 81 struct net_device_monitor* monitor); 82 status_t device_link_changed(net_device* device); 83 status_t device_removed(net_device* device); 84 status_t device_enqueue_buffer(net_device* device, net_buffer* buffer); 85 86 status_t init_device_interfaces(); 87 status_t uninit_device_interfaces(); 88 89 90 #endif // DEVICE_INTERFACES_H 91