161729d93SAxel Dörfler /* 261729d93SAxel Dörfler * Copyright 2006-2010, 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; 3561729d93SAxel Dörfler 3661729d93SAxel Dörfler net_deframe_func deframe_func; 3761729d93SAxel Dörfler int32 deframe_ref_count; 3861729d93SAxel Dörfler 39fee56868SAxel Dörfler int32 monitor_count; 40*ef860b2eSStefano Ceccherini recursive_lock monitor_lock; 4161729d93SAxel Dörfler DeviceMonitorList monitor_funcs; 4261729d93SAxel Dörfler 43fee56868SAxel Dörfler DeviceHandlerList receive_funcs; 4461729d93SAxel Dörfler recursive_lock receive_lock; 4561729d93SAxel Dörfler 4661729d93SAxel Dörfler thread_id consumer_thread; 4761729d93SAxel Dörfler net_fifo receive_queue; 4861729d93SAxel Dörfler }; 4961729d93SAxel Dörfler 5061729d93SAxel Dörfler typedef DoublyLinkedList<net_device_interface> DeviceInterfaceList; 5161729d93SAxel Dörfler 5261729d93SAxel Dörfler 5361729d93SAxel Dörfler // device interfaces 5461729d93SAxel Dörfler net_device_interface* acquire_device_interface(net_device_interface* interface); 5561729d93SAxel Dörfler void get_device_interface_address(net_device_interface* interface, 5661729d93SAxel Dörfler sockaddr* address); 5761729d93SAxel Dörfler uint32 count_device_interfaces(); 5861729d93SAxel Dörfler status_t list_device_interfaces(void* buffer, size_t* _bufferSize); 5961729d93SAxel Dörfler void put_device_interface(struct net_device_interface* interface); 6061729d93SAxel Dörfler struct net_device_interface* get_device_interface(uint32 index); 6161729d93SAxel Dörfler struct net_device_interface* get_device_interface(const char* name, 6261729d93SAxel Dörfler bool create = true); 63fee56868SAxel Dörfler void device_interface_monitor_receive(net_device_interface* interface, 64fee56868SAxel Dörfler net_buffer* buffer); 6561729d93SAxel Dörfler status_t up_device_interface(net_device_interface* interface); 6661729d93SAxel Dörfler void down_device_interface(net_device_interface* interface); 6761729d93SAxel Dörfler 6861729d93SAxel Dörfler // devices 6961729d93SAxel Dörfler status_t unregister_device_deframer(net_device* device); 70fee56868SAxel Dörfler status_t register_device_deframer(net_device* device, 71fee56868SAxel Dörfler net_deframe_func deframeFunc); 7261729d93SAxel Dörfler status_t register_domain_device_handler(struct net_device* device, int32 type, 7361729d93SAxel Dörfler struct net_domain* domain); 7461729d93SAxel Dörfler status_t register_device_handler(struct net_device* device, int32 type, 7561729d93SAxel Dörfler net_receive_func receiveFunc, void* cookie); 7661729d93SAxel Dörfler status_t unregister_device_handler(struct net_device* device, int32 type); 7761729d93SAxel Dörfler status_t register_device_monitor(struct net_device* device, 7861729d93SAxel Dörfler struct net_device_monitor* monitor); 7961729d93SAxel Dörfler status_t unregister_device_monitor(struct net_device* device, 8061729d93SAxel Dörfler struct net_device_monitor* monitor); 8161729d93SAxel Dörfler status_t device_link_changed(net_device* device); 8261729d93SAxel Dörfler status_t device_removed(net_device* device); 8361729d93SAxel Dörfler status_t device_enqueue_buffer(net_device* device, net_buffer* buffer); 8461729d93SAxel Dörfler 8561729d93SAxel Dörfler status_t init_device_interfaces(); 8661729d93SAxel Dörfler status_t uninit_device_interfaces(); 8761729d93SAxel Dörfler 8861729d93SAxel Dörfler 8961729d93SAxel Dörfler #endif // DEVICE_INTERFACES_H 90