2006-08-08 17:07:07 +04:00
|
|
|
/*
|
2010-08-03 15:23:03 +04:00
|
|
|
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
|
2006-08-08 17:07:07 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef NET_STACK_H
|
|
|
|
#define NET_STACK_H
|
|
|
|
|
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
#include <module.h>
|
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
#include <lock.h>
|
|
|
|
#include <util/list.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define NET_STACK_MODULE_NAME "network/stack/v1"
|
|
|
|
|
2007-05-04 01:18:21 +04:00
|
|
|
|
|
|
|
struct net_address_module_info;
|
|
|
|
struct net_protocol_module_info;
|
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
typedef struct net_buffer net_buffer;
|
|
|
|
typedef struct net_device net_device;
|
|
|
|
typedef struct net_domain net_domain;
|
|
|
|
typedef struct net_socket net_socket;
|
|
|
|
|
2007-05-04 01:18:21 +04:00
|
|
|
struct net_timer;
|
|
|
|
|
2008-05-02 18:37:16 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
typedef struct net_fifo {
|
2008-05-29 06:08:23 +04:00
|
|
|
mutex lock;
|
2006-08-08 17:07:07 +04:00
|
|
|
sem_id notify;
|
|
|
|
int32 waiting;
|
|
|
|
|
|
|
|
size_t max_bytes;
|
|
|
|
size_t current_bytes;
|
|
|
|
|
|
|
|
struct list buffers;
|
2010-08-03 15:23:03 +04:00
|
|
|
} net_fifo;
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
typedef void (*net_timer_func)(struct net_timer* timer, void* data);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
typedef struct net_timer {
|
2006-08-08 17:07:07 +04:00
|
|
|
struct list_link link;
|
|
|
|
net_timer_func hook;
|
2010-08-03 15:23:03 +04:00
|
|
|
void* data;
|
2006-08-08 17:07:07 +04:00
|
|
|
bigtime_t due;
|
2008-08-15 18:46:16 +04:00
|
|
|
uint32 flags;
|
2010-08-03 15:23:03 +04:00
|
|
|
} net_timer;
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
typedef status_t (*net_deframe_func)(net_device* device, net_buffer* buffer);
|
|
|
|
typedef status_t (*net_receive_func)(void* cookie, net_device* device,
|
|
|
|
net_buffer* buffer);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2007-04-08 13:15:52 +04:00
|
|
|
enum {
|
|
|
|
B_DEVICE_GOING_UP = 1,
|
|
|
|
B_DEVICE_GOING_DOWN,
|
|
|
|
B_DEVICE_BEING_REMOVED,
|
|
|
|
};
|
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
typedef struct net_device_monitor {
|
2007-04-08 13:15:52 +04:00
|
|
|
struct list_link link;
|
2010-08-03 15:23:03 +04:00
|
|
|
void* cookie;
|
2007-04-08 13:15:52 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*receive)(struct net_device_monitor* monitor,
|
|
|
|
struct net_buffer* buffer);
|
|
|
|
void (*event)(struct net_device_monitor* monitor, int32 event);
|
|
|
|
} net_device_monitor;
|
2007-04-08 13:15:52 +04:00
|
|
|
|
2008-05-02 18:37:16 +04:00
|
|
|
typedef struct ancillary_data_header {
|
|
|
|
int level;
|
|
|
|
int type;
|
|
|
|
size_t len;
|
|
|
|
} ancillary_data_header;
|
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
typedef struct ancillary_data_container ancillary_data_container;
|
|
|
|
|
|
|
|
|
|
|
|
#define B_NET_FRAME_TYPE(super, sub) (((int32)(super) << 16) | (sub))
|
|
|
|
// Use this when registering a device handler, see net/if_types.h for
|
2011-07-02 00:26:37 +04:00
|
|
|
// the possible "super" values. Input values are in host byte order.
|
2010-08-03 15:23:03 +04:00
|
|
|
|
|
|
|
|
|
|
|
// sub types
|
|
|
|
enum {
|
|
|
|
B_NET_FRAME_TYPE_IPV4 = 0x0001,
|
|
|
|
B_NET_FRAME_TYPE_IPV6 = 0x0002,
|
|
|
|
B_NET_FRAME_TYPE_IPX = 0x0003,
|
|
|
|
B_NET_FRAME_TYPE_APPLE_TALK = 0x0004,
|
|
|
|
|
|
|
|
B_NET_FRAME_TYPE_ALL = 0x0000
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
struct net_stack_module_info {
|
|
|
|
module_info info;
|
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*register_domain)(int family, const char* name,
|
|
|
|
struct net_protocol_module_info* module,
|
|
|
|
struct net_address_module_info* addressModule,
|
|
|
|
net_domain** _domain);
|
|
|
|
status_t (*unregister_domain)(net_domain* domain);
|
|
|
|
net_domain* (*get_domain)(int family);
|
|
|
|
|
|
|
|
status_t (*register_domain_protocols)(int family, int type, int protocol,
|
|
|
|
...);
|
|
|
|
status_t (*register_domain_datalink_protocols)(int family, int type,
|
|
|
|
...);
|
|
|
|
status_t (*register_domain_receiving_protocol)(int family, int type,
|
|
|
|
const char* moduleName);
|
|
|
|
|
|
|
|
status_t (*get_domain_receiving_protocol)(net_domain* domain,
|
|
|
|
uint32 type, struct net_protocol_module_info** _module);
|
|
|
|
status_t (*put_domain_receiving_protocol)(net_domain* domain,
|
2007-10-22 00:10:43 +04:00
|
|
|
uint32 type);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
// devices
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*register_device_deframer)(net_device* device,
|
2006-08-08 17:07:07 +04:00
|
|
|
net_deframe_func deframeFunc);
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*unregister_device_deframer)(net_device* device);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*register_domain_device_handler)(net_device* device,
|
|
|
|
int32 type, net_domain* domain);
|
|
|
|
status_t (*register_device_handler)(net_device* device,
|
|
|
|
int32 type, net_receive_func receiveFunc, void* cookie);
|
|
|
|
status_t (*unregister_device_handler)(net_device* device, int32 type);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*register_device_monitor)(net_device* device,
|
|
|
|
struct net_device_monitor* monitor);
|
|
|
|
status_t (*unregister_device_monitor)(net_device* device,
|
|
|
|
struct net_device_monitor* monitor);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*device_link_changed)(net_device* device);
|
|
|
|
status_t (*device_removed)(net_device* device);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*device_enqueue_buffer)(net_device* device,
|
|
|
|
net_buffer* buffer);
|
2007-05-23 11:56:15 +04:00
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
// Utility Functions
|
|
|
|
|
2006-10-07 16:32:02 +04:00
|
|
|
// notification
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*notify_socket)(net_socket* socket, uint8 event, int32 value);
|
2006-10-07 16:32:02 +04:00
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
// checksum
|
2010-08-03 15:23:03 +04:00
|
|
|
uint16 (*checksum)(uint8* buffer, size_t length);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
// fifo
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*init_fifo)(net_fifo* fifo, const char* name, size_t maxBytes);
|
|
|
|
void (*uninit_fifo)(net_fifo* fifo);
|
|
|
|
status_t (*fifo_enqueue_buffer)(net_fifo* fifo, net_buffer* buffer);
|
|
|
|
ssize_t (*fifo_dequeue_buffer)(net_fifo* fifo, uint32 flags,
|
|
|
|
bigtime_t timeout, net_buffer** _buffer);
|
|
|
|
status_t (*clear_fifo)(net_fifo* fifo);
|
|
|
|
status_t (*fifo_socket_enqueue_buffer)(net_fifo* fifo,
|
|
|
|
net_socket* socket, uint8 event, net_buffer* buffer);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
// timer
|
2010-08-03 15:23:03 +04:00
|
|
|
void (*init_timer)(net_timer* timer, net_timer_func hook,
|
|
|
|
void* data);
|
|
|
|
void (*set_timer)(net_timer* timer, bigtime_t delay);
|
|
|
|
bool (*cancel_timer)(net_timer* timer);
|
|
|
|
status_t (*wait_for_timer)(net_timer* timer);
|
|
|
|
bool (*is_timer_active)(net_timer* timer);
|
|
|
|
bool (*is_timer_running)(net_timer* timer);
|
2008-02-17 19:25:07 +03:00
|
|
|
|
|
|
|
// syscall restart
|
2010-08-03 15:23:03 +04:00
|
|
|
bool (*is_syscall)(void);
|
|
|
|
bool (*is_restarted_syscall)(void);
|
|
|
|
void (*store_syscall_restart_timeout)(bigtime_t timeout);
|
|
|
|
bigtime_t (*restore_syscall_restart_timeout)(void);
|
2008-05-02 18:37:16 +04:00
|
|
|
|
|
|
|
// ancillary data
|
|
|
|
ancillary_data_container* (*create_ancillary_data_container)();
|
2010-08-03 15:23:03 +04:00
|
|
|
void (*delete_ancillary_data_container)(
|
2008-05-02 18:37:16 +04:00
|
|
|
ancillary_data_container* container);
|
2010-08-03 15:23:03 +04:00
|
|
|
status_t (*add_ancillary_data)(ancillary_data_container* container,
|
|
|
|
const ancillary_data_header* header, const void* data,
|
2008-05-02 18:37:16 +04:00
|
|
|
void (*destructor)(const ancillary_data_header*, void*),
|
2010-08-03 15:23:03 +04:00
|
|
|
void** _allocatedData);
|
|
|
|
status_t (*remove_ancillary_data)(ancillary_data_container* container,
|
|
|
|
void* data, bool destroy);
|
|
|
|
void* (*move_ancillary_data)(ancillary_data_container* from,
|
|
|
|
ancillary_data_container* to);
|
|
|
|
void* (*next_ancillary_data)(ancillary_data_container* container,
|
|
|
|
void* previousData, ancillary_data_header* _header);
|
2006-08-08 17:07:07 +04:00
|
|
|
};
|
|
|
|
|
2010-08-03 15:23:03 +04:00
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
#endif // NET_STACK_H
|