1 /* 2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef NET_DEVICE_H 6 #define NET_DEVICE_H 7 8 9 #include <net/if.h> 10 11 #include <module.h> 12 13 14 typedef struct net_buffer net_buffer; 15 16 17 struct net_hardware_address { 18 uint8 data[64]; 19 uint8 length; 20 }; 21 22 typedef struct net_device { 23 struct net_device_module_info* module; 24 25 char name[IF_NAMESIZE]; 26 uint32 index; 27 uint32 flags; // IFF_LOOPBACK, ... 28 uint32 type; // IFT_ETHER, ... 29 size_t mtu; 30 uint32 media; 31 uint64 link_speed; 32 uint32 link_quality; 33 size_t header_length; 34 35 struct net_hardware_address address; 36 37 struct ifreq_stats stats; 38 } net_device; 39 40 41 struct net_device_module_info { 42 struct module_info info; 43 44 status_t (*init_device)(const char* name, net_device** _device); 45 status_t (*uninit_device)(net_device* device); 46 47 status_t (*up)(net_device* device); 48 void (*down)(net_device* device); 49 50 status_t (*control)(net_device* device, int32 op, void* argument, 51 size_t length); 52 53 status_t (*send_data)(net_device* device, net_buffer* buffer); 54 status_t (*receive_data)(net_device* device, net_buffer** _buffer); 55 56 status_t (*set_mtu)(net_device* device, size_t mtu); 57 status_t (*set_promiscuous)(net_device* device, bool promiscuous); 58 status_t (*set_media)(net_device* device, uint32 media); 59 60 status_t (*add_multicast)(net_device* device, 61 const struct sockaddr* address); 62 status_t (*remove_multicast)(net_device* device, 63 const struct sockaddr* address); 64 }; 65 66 67 #endif // NET_DEVICE_H 68