Changeset a7a85d16 in mainline for uspace/lib/net/include


Ignore:
Timestamp:
2010-10-16T17:16:30Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
668f8cbf, e0e568ff, f14291b
Parents:
ef689ef0 (diff), c62ae1d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/net.

Location:
uspace/lib/net/include
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/include/adt/module_map.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup net
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Character string to module map.
     34 * Character string to module map.
    3535 */
    3636
    37 #ifndef __NET_MODULES_MAP_H__
    38 #define __NET_MODULES_MAP_H__
     37#ifndef LIBNET_MODULES_MAP_H_
     38#define LIBNET_MODULES_MAP_H_
    3939
    4040#include <task.h>
    41 
    4241#include <ipc/services.h>
    43 
    4442#include <net/modules.h>
    45 
    4643#include <adt/generic_char_map.h>
    4744
    4845/** Type definition of the module structure.
    49  *  @see module_struct
     46 * @see module_struct
    5047 */
    51 typedef struct module_struct    module_t;
     48typedef struct module_struct module_t;
    5249
    5350/** Type definition of the module structure pointer.
    54  *  @see module_struct
     51 * @see module_struct
    5552 */
    56 typedef module_t *                              module_ref;
     53typedef module_t *module_ref;
    5754
    5855/** Module map.
    59  *  Sorted by module names.
    60  *  @see generic_char_map.h
     56 * Sorted by module names.
     57 * @see generic_char_map.h
    6158 */
    6259GENERIC_CHAR_MAP_DECLARE(modules, module_t)
    6360
    64 /** Module structure.
    65  */
    66 struct  module_struct{
    67         /** Module task identifier if running.
    68          */
     61/** Module structure. */
     62struct module_struct {
     63        /** Module task identifier if running. */
    6964        task_id_t task_id;
    70         /** Module service identifier.
    71          */
     65        /** Module service identifier. */
    7266        services_t service;
    73         /** Module phone if running and connected.
    74          */
     67        /** Module phone if running and connected. */
    7568        int phone;
    76         /** Usage counter.
    77          */
     69        /** Usage counter. */
    7870        int usage;
    79         /** Module name.
    80          */
    81         const char * name;
    82         /** Module full path filename.
    83          */
    84         const char * filename;
    85         /** Connecting function.
    86          */
    87         connect_module_t * connect_module;
     71        /** Module name. */
     72        const char *name;
     73        /** Module full path filename. */
     74        const char *filename;
     75        /** Connecting function. */
     76        connect_module_t *connect_module;
    8877};
    8978
    90 /** Adds module to the module map.
    91  *  @param[out] module The module structure added.
    92  *  @param[in] modules The module map.
    93  *  @param[in] name The module name.
    94  *  @param[in] filename The full path filename.
    95  *  @param[in] service The module service.
    96  *  @param[in] task_id The module current task identifier. Zero (0) means not running.
    97  *  @param[in] connect_module The module connecting function.
    98  *  @returns EOK on success.
    99  *  @returns ENOMEM if there is not enough memory left.
    100  */
    101 int add_module(module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id, connect_module_t * connect_module);
    102 
    103 /** Searches and returns the specified module.
    104  *  If the module is not running, the module filaname is spawned.
    105  *  If the module is not connected, the connect_function is called.
    106  *  @param[in] modules The module map.
    107  *  @param[in] name The module name.
    108  *  @returns The running module found. It does not have to be connected.
    109  *  @returns NULL if there is no such module.
    110  */
    111 module_ref get_running_module(modules_ref modules, char * name);
    112 
    113 /** Starts the given module.
    114  *  @param[in] fname The module full or relative path filename.
    115  *  @returns The new module task identifier on success.
    116  *  @returns 0 if there is no such module.
    117  */
    118 task_id_t spawn(const char * fname);
     79extern int add_module(module_ref *, modules_ref, const char *, const char *,
     80    services_t, task_id_t, connect_module_t *);
     81extern module_ref get_running_module(modules_ref, char *);
     82extern task_id_t spawn(const char *);
    11983
    12084#endif
  • uspace/lib/net/include/arp_interface.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup arp
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    33 #ifndef __NET_ARP_INTERFACE_H__
    34 #define __NET_ARP_INTERFACE_H__
     33#ifndef LIBNET_ARP_INTERFACE_H_
     34#define LIBNET_ARP_INTERFACE_H_
    3535
    3636#include <adt/measured_strings.h>
     
    4343
    4444/** @name ARP module interface
    45  *  This interface is used by other modules.
     45 * This interface is used by other modules.
    4646 */
    4747/*@{*/
    4848
    49 /** Registers the new device and the requesting protocol service.
    50  *  Connects to the network interface layer service.
    51  *  Determines the device broadcast address, its address lengths and packet size.
    52  *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
    53  *  @param[in] device_id The new device identifier.
    54  *  @param[in] protocol The requesting protocol service.
    55  *  @param[in] netif The underlying device network interface layer service.
    56  *  @param[in] address The local requesting protocol address of the device.
    57  *  @returns EOK on success.
    58  *  @returns EEXIST if the device is already used.
    59  *  @returns ENOMEM if there is not enough memory left.
    60  *  @returns ENOENT if the network interface service is not known.
    61  *  @returns EREFUSED if the network interface service is not responding.
    62  *  @returns Other error codes as defined for the nil_packet_get_size() function.
    63  *  @returns Other error codes as defined for the nil_get_addr() function.
    64  *  @returns Other error codes as defined for the nil_get_broadcast_addr() function.
    65  */
    66 extern int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address);
    67 
    68 /** Translates the given protocol address to the network interface address.
    69  *  Broadcasts the ARP request if the mapping is not found.
    70  *  Allocates and returns the needed memory block as the data parameter.
    71  *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
    72  *  @param[in] device_id The device identifier.
    73  *  @param[in] protocol The requesting protocol service.
    74  *  @param[in] address The local requesting protocol address.
    75  *  @param[out] translation The translation of the local protocol address.
    76  *  @param[out] data The allocated raw translation data container.
    77  *  @returns EOK on success.
    78  *  @returns EINVAL if the address parameter is NULL.
    79  *  @returns EBADMEM if the translation or the data parameters are NULL.
    80  *  @returns ENOENT if the mapping is not found.
    81  */
    82 extern int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data);
    83 
    84 /** Clears the device cache.
    85  *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
    86  *  @param[in] device_id The device identifier.
    87  *  @returns EOK on success.
    88  *  @returns ENOENT if the device is not found.
    89  */
    90 extern int arp_clear_device_req(int arp_phone, device_id_t device_id);
    91 
    92 /** Clears the given protocol address from the cache.
    93  *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
    94  *  @param[in] device_id The device identifier.
    95  *  @param[in] protocol The requesting protocol service.
    96  *  @param[in] address The protocol address to be cleared.
    97  *  @returns EOK on success.
    98  *  @returns ENOENT if the mapping is not found.
    99  */
    100 extern int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address);
    101 
    102 /** Cleans the cache.
    103  *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
    104  *  @returns EOK on success.
    105  */
    106 extern int arp_clean_cache_req(int arp_phone);
    107 
    108 /** Connects to the ARP module.
    109  *  @param service The ARP module service. Ignored parameter.
    110  *  @returns The ARP module phone on success.
    111  */
    112 extern int arp_connect_module(services_t service);
    113 
    114 /** Returns the ARP task identifier.
    115  *  @returns 0 if called by the remote module.
    116  */
    117 extern task_id_t arp_task_get_id(void);
     49extern int arp_device_req(int, device_id_t, services_t, services_t,
     50    measured_string_ref);
     51extern int arp_translate_req(int, device_id_t, services_t, measured_string_ref,
     52    measured_string_ref *, char **);
     53extern int arp_clear_device_req(int, device_id_t);
     54extern int arp_clear_address_req(int, device_id_t, services_t,
     55    measured_string_ref);
     56extern int arp_clean_cache_req(int);
     57extern int arp_connect_module(services_t);
    11858
    11959/*@}*/
  • uspace/lib/net/include/generic.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup net
     29/** @addtogroup libnet
    3030 * @{
    3131 */
     
    3535 */
    3636
    37 #ifndef NET_GENERIC_H_
    38 #define NET_GENERIC_H_
     37#ifndef LIBNET_GENERIC_H_
     38#define LIBNET_GENERIC_H_
    3939
    4040#include <async.h>
  • uspace/lib/net/include/il_interface.h

    ref689ef0 ra7a85d16  
    4242
    4343#include <ipc/services.h>
     44#include <ipc/il.h>
    4445
    4546#include <net/device.h>
    4647#include <net/packet.h>
    47 #include <il_messages.h>
    4848
    4949#include <packet_client.h>
  • uspace/lib/net/include/ip_client.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup ip
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  IP client interface.
     34 * IP client interface.
    3535 */
    3636
    37 #ifndef __NET_IP_CLIENT_H__
    38 #define __NET_IP_CLIENT_H__
     37#ifndef LIBNET_IP_CLIENT_H_
     38#define LIBNET_IP_CLIENT_H_
    3939
    4040#include <net/socket_codes.h>
     
    4545#include <ip_interface.h>
    4646
    47 /** Prepares the packet to be transfered via IP.
    48  *  The IP header is prefixed.
    49  *  @param[in,out] packet The packet to be prepared.
    50  *  @param[in] protocol The transport protocol.
    51  *  @param[in] ttl The time to live counter. The IPDEFTTL is set if zero (0).
    52  *  @param[in] tos The type of service.
    53  *  @param[in] dont_fragment The value indicating whether fragmentation is disabled.
    54  *  @param[in] ipopt_length The prefixed IP options length in bytes.
    55  *  @returns EOK on success.
    56  *  @returns ENOMEM if there is not enough memory left in the packet.
    57  */
    58 extern int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length);
    59 
    60 /** Processes the received IP packet.
    61  *  Fills set header fields.
    62  *  Returns the prefixed IP header length.
    63  *  @param[in] packet The received packet.
    64  *  @param[out] protocol The transport protocol. May be NULL if not desired.
    65  *  @param[out] ttl The time to live counter. May be NULL if not desired.
    66  *  @param[out] tos The type of service. May be NULL if not desired.
    67  *  @param[out] dont_fragment The value indicating whether the fragmentation is disabled. May be NULL if not desired.
    68  *  @param[out] ipopt_length The IP options length in bytes. May be NULL if not desired.
    69  *  @returns The prefixed IP header length in bytes on success.
    70  *  @returns ENOMEM if the packet is too short to contain the IP header.
    71  */
    72 extern int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length);
    73 
    74 /** Returns the IP header length.
    75  *  @param[in] packet The packet.
    76  *  @returns The IP header length in bytes.
    77  *  @returns Zero (0) if there is no IP header.
    78  */
    79 extern size_t ip_client_header_length(packet_t packet);
    80 
    81 /** Updates the IPv4 pseudo header data length field.
    82  *  @param[in,out] header The IPv4 pseudo header to be updated.
    83  *  @param[in] headerlen The length of the IP pseudo header in bytes.
    84  *  @param[in] data_length The data length to be set.
    85  *  @returns EOK on success.
    86  *  @returns EBADMEM if the header parameter is NULL.
    87  *  @returns EINVAL if the headerlen parameter is not IPv4 pseudo header length.
    88  */
    89 extern int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length);
    90 
    91 /** Constructs the IPv4 pseudo header.
    92  *  @param[in] protocol The transport protocol.
    93  *  @param[in] src The source address.
    94  *  @param[in] srclen The source address length.
    95  *  @param[in] dest The destination address.
    96  *  @param[in] destlen The destination address length.
    97  *  @param[in] data_length The data length to be set.
    98  *  @param[out] header The constructed IPv4 pseudo header.
    99  *  @param[out] headerlen The length of the IP pseudo header in bytes.
    100  *  @returns EOK on success.
    101  *  @returns EBADMEM if the header and/or the headerlen parameter is NULL.
    102  *  @returns EINVAL if the source address and/or the destination address parameter is NULL.
    103  *  @returns EINVAL if the source address length is less than struct sockaddr length.
    104  *  @returns EINVAL if the source address length differs from the destination address length.
    105  *  @returns EINVAL if the source address family differs from the destination family.
    106  *  @returns EAFNOSUPPORT if the address family is not supported.
    107  *  @returns ENOMEM if there is not enough memory left.
    108  */
    109 extern int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, void **header, size_t * headerlen);
     47extern int ip_client_prepare_packet(packet_t, ip_protocol_t, ip_ttl_t, ip_tos_t,
     48    int, size_t);
     49extern int ip_client_process_packet(packet_t, ip_protocol_t *, ip_ttl_t *,
     50    ip_tos_t *, int *, size_t *);
     51extern size_t ip_client_header_length(packet_t);
     52extern int ip_client_set_pseudo_header_data_length(void *, size_t, size_t);
     53extern int ip_client_get_pseudo_header(ip_protocol_t, struct sockaddr *,
     54    socklen_t, struct sockaddr *, socklen_t, size_t, void **, size_t *);
    11055
    11156// TODO ipopt manipulation
  • uspace/lib/net/include/net_checksum.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup net
    30  *  @{
     29/** @addtogroup libnet
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  General CRC and checksum computation.
     34 * General CRC and checksum computation.
    3535 */
    3636
    37 #ifndef __NET_CHECKSUM_H__
    38 #define __NET_CHECKSUM_H__
     37#ifndef LIBNET_CHECKSUM_H_
     38#define LIBNET_CHECKSUM_H_
    3939
    4040#include <byteorder.h>
    41 
    4241#include <sys/types.h>
    4342
    4443/** IP checksum value for computed zero checksum.
    45  *  Zero is returned as 0xFFFF (not flipped)
     44 * Zero is returned as 0xFFFF (not flipped)
    4645 */
    47 #define IP_CHECKSUM_ZERO                        0xFFFFu
     46#define IP_CHECKSUM_ZERO        0xffffU
    4847
    49 /**     Computes CRC32 value.
    50  *  @param[in] seed Initial value. Often used as 0 or ~0.
    51  *  @param[in] data Pointer to the beginning of data to process.
    52  *  @param[in] length Length of the data in bits.
    53  *  @returns The computed CRC32 of the length bits of the data.
    54  */
    5548#ifdef ARCH_IS_BIG_ENDIAN
    56         #define compute_crc32(seed, data, length)       compute_crc32_be(seed, (uint8_t *) data, length)
     49#define compute_crc32(seed, data, length) \
     50        compute_crc32_be(seed, (uint8_t *) data, length)
    5751#else
    58         #define compute_crc32(seed, data, length)       compute_crc32_le(seed, (uint8_t *) data, length)
     52#define compute_crc32(seed, data, length) \
     53        compute_crc32_le(seed, (uint8_t *) data, length)
    5954#endif
    6055
    61 /**     Computes CRC32 value in the little-endian environment.
    62  *  @param[in] seed Initial value. Often used as 0 or ~0.
    63  *  @param[in] data Pointer to the beginning of data to process.
    64  *  @param[in] length Length of the data in bits.
    65  *  @returns The computed CRC32 of the length bits of the data.
    66  */
    67 extern uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length);
    68 
    69 /**     Computes CRC32 value in the big-endian environment.
    70  *  @param[in] seed Initial value. Often used as 0 or ~0.
    71  *  @param[in] data Pointer to the beginning of data to process.
    72  *  @param[in] length Length of the data in bits.
    73  *  @returns The computed CRC32 of the length bits of the data.
    74  */
    75 extern uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length);
    76 
    77 /** Computes sum of the 2 byte fields.
    78  *  Padds one zero (0) byte if odd.
    79  *  @param[in] seed Initial value. Often used as 0 or ~0.
    80  *  @param[in] data Pointer to the beginning of data to process.
    81  *  @param[in] length Length of the data in bytes.
    82  *  @returns The computed checksum of the length bytes of the data.
    83  */
    84 extern uint32_t compute_checksum(uint32_t seed, uint8_t * data, size_t length);
    85 
    86 /** Compacts the computed checksum to the 16 bit number adding the carries.
    87  *  @param[in] sum Computed checksum.
    88  *  @returns Compacted computed checksum to the 16 bits.
    89  */
    90 extern uint16_t compact_checksum(uint32_t sum);
    91 
    92 /** Returns or flips the checksum if zero.
    93  *  @param[in] checksum The computed checksum.
    94  *  @returns The internet protocol header checksum.
    95  *  @returns 0xFFFF if the computed checksum is zero.
    96  */
    97 extern uint16_t flip_checksum(uint16_t checksum);
    98 
    99 /** Computes the ip header checksum.
    100  *  To compute the checksum of a new packet, the checksum header field must be zero.
    101  *  To check the checksum of a received packet, the checksum may be left set.
    102  *  The zero (0) value will be returned in this case if valid.
    103  *  @param[in] data The header data.
    104  *  @param[in] length The header length in bytes.
    105  *  @returns The internet protocol header checksum.
    106  *  @returns 0xFFFF if the computed checksum is zero.
    107  */
    108 extern uint16_t ip_checksum(uint8_t * data, size_t length);
     56extern uint32_t compute_crc32_le(uint32_t, uint8_t *, size_t);
     57extern uint32_t compute_crc32_be(uint32_t, uint8_t *, size_t);
     58extern uint32_t compute_checksum(uint32_t, uint8_t *, size_t);
     59extern uint16_t compact_checksum(uint32_t);
     60extern uint16_t flip_checksum(uint16_t);
     61extern uint16_t ip_checksum(uint8_t *, size_t);
    10962
    11063#endif
  • uspace/lib/net/include/net_interface.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup net
     29/** @addtogroup libnet
    3030 *  @{
    3131 */
    3232
    33 #ifndef __NET_NET_INTERFACE_H__
    34 #define __NET_NET_INTERFACE_H__
     33#ifndef LIBNET_NET_INTERFACE_H_
     34#define LIBNET_NET_INTERFACE_H_
    3535
    3636#include <ipc/services.h>
     
    4040
    4141/** @name Networking module interface
    42  *  This interface is used by other modules.
     42 * This interface is used by other modules.
    4343 */
    4444/*@{*/
    4545
    46 /** Returns the device specific configuration.
    47  *  Returns the global configuration if the device specific is not found.
    48  *  The configuration names are read and the appropriate settings are set instead.
    49  *  Call net_free_settings() function to release the returned configuration.
    50  *  @param[in] net_phone The networking module phone.
    51  *  @param[in] device_id The device identifier.
    52  *  @param[in,out] configuration The requested device configuration. The names are read and the appropriate settings are set instead.
    53  *  @param[in] count The configuration entries count.
    54  *  @param[in,out] data The configuration and settings data.
    55  *  @returns EOK on success.
    56  *  @returns EINVAL if the configuration is NULL.
    57  *  @returns EINVAL if the count is zero (0).
    58  *  @returns Other error codes as defined for the generic_translate_req() function.
    59  */
    60 extern int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data);
    61 
    62 /** Returns the global configuration.
    63  *  The configuration names are read and the appropriate settings are set instead.
    64  *  Call net_free_settings() function to release the returned configuration.
    65  *  @param[in] net_phone The networking module phone.
    66  *  @param[in,out] configuration The requested configuration. The names are read and the appropriate settings are set instead.
    67  *  @param[in] count The configuration entries count.
    68  *  @param[in,out] data The configuration and settings data.
    69  *  @returns EOK on success.
    70  *  @returns EINVAL if the configuration is NULL.
    71  *  @returns EINVAL if the count is zero (0).
    72  *  @returns Other error codes as defined for the generic_translate_req() function.
    73  */
    74 extern int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data);
    75 
    76 /** Frees the received settings.
    77  *  @param[in] settings The received settings.
    78  *  @param[in] data The received settings data.
    79  *  @see net_get_device_conf_req()
    80  *  @see net_get_conf_req()
    81  */
    82 extern void net_free_settings(measured_string_ref settings, char * data);
    83 
    84 /** Connects to the networking module.
    85  *  @param service The networking module service. Ignored parameter.
    86  *  @returns The networking module phone on success.
    87  */
    88 extern int net_connect_module(services_t service);
     46extern int net_get_device_conf_req(int, device_id_t, measured_string_ref *,
     47    size_t, char **);
     48extern int net_get_conf_req(int, measured_string_ref *, size_t, char **);
     49extern void net_free_settings(measured_string_ref, char *);
     50extern int net_connect_module(void);
    8951
    9052/*@}*/
  • uspace/lib/net/include/nil_interface.h

    ref689ef0 ra7a85d16  
    3838
    3939#include <ipc/ipc.h>
     40#include <ipc/nil.h>
    4041
    4142#include <generic.h>
    42 #include <nil_messages.h>
    4343#include <nil_remote.h>
    4444
  • uspace/lib/net/include/packet_client.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup packet
     29/** @addtogroup libnet
    3030 *  @{
    3131 */
    3232
    3333/** @file
    34  *  Packet client.
    35  *  The hosting module has to be compiled with both the packet.c and the packet_client.c source files.
    36  *  To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place.
    37  *  The module should not send the packet messages to the packet server but use the functions provided.
    38  *  The packet map should be released by the pm_destroy() function during the module termination.
    39  *  The packets and the packet queues can't be locked at all.
    40  *  The processing modules should process them sequentially -&nbsp;by passing the packets to the next module and stopping using the passed ones.
    41  *  @see packet.h
     34 * Packet client.
     35 *
     36 * To function correctly, initialization of the packet map by the pm_init()
     37 * function has to happen at the first place. The module should not send the
     38 * packet messages to the packet server but use the functions provided. The
     39 * packet map should be released by the pm_destroy() function during the module
     40 * termination. The packets and the packet queues can't be locked at all. The
     41 * processing modules should process them sequentially - by passing the packets
     42 * to the next module and stopping using the passed ones.
     43 *
     44 * @see packet.h
    4245 */
    4346
    44 #ifndef __NET_PACKET_CLIENT_H__
    45 #define __NET_PACKET_CLIENT_H__
     47#ifndef LIBNET_PACKET_CLIENT_H_
     48#define LIBNET_PACKET_CLIENT_H_
    4649
    4750#include <net/packet.h>
    4851
    49 /** @name Packet client interface
    50  */
     52/** @name Packet client interface */
    5153/*@{*/
    5254
    53 /** Allocates the specified type right before the actual packet content and returns its pointer.
    54  *  The wrapper of the packet_prepend() function.
    55  *  @param[in] packet The packet to be used.
    56  *  @param[in] type The type to be allocated at the beginning of the packet content.
    57  *  @returns The typed pointer to the allocated memory.
    58  *  @returns NULL if the packet is not valid.
    59  *  @returns NULL if there is not enough memory left.
     55/** Allocates the specified type right before the actual packet content and
     56 * returns its pointer.
     57 *
     58 * The wrapper of the packet_prepend() function.
     59 *
     60 * @param[in] packet    The packet to be used.
     61 * @param[in] type      The type to be allocated at the beginning of the packet
     62 *                      content.
     63 * @returns             The typed pointer to the allocated memory.
     64 * @returns             NULL if the packet is not valid.
     65 * @returns             NULL if there is not enough memory left.
    6066 */
    61 #define PACKET_PREFIX(packet, type)     (type *) packet_prefix((packet), sizeof(type))
     67#define PACKET_PREFIX(packet, type) \
     68        (type *) packet_prefix((packet), sizeof(type))
    6269
    63 /** Allocates the specified type right after the actual packet content and returns its pointer.
    64  *  The wrapper of the packet_append() function.
    65  *  @param[in] packet The packet to be used.
    66  *  @param[in] type The type to be allocated at the end of the packet content.
    67  *  @returns The typed pointer to the allocated memory.
    68  *  @returns NULL if the packet is not valid.
    69  *  @returns NULL if there is not enough memory left.
     70/** Allocates the specified type right after the actual packet content and
     71 * returns its pointer.
     72 *
     73 * The wrapper of the packet_append() function.
     74 *
     75 * @param[in] packet    The packet to be used.
     76 * @param[in] type      The type to be allocated at the end of the packet
     77 *                      content.
     78 * @returns             The typed pointer to the allocated memory.
     79 * @returns             NULL if the packet is not valid.
     80 * @returns             NULL if there is not enough memory left.
    7081 */
    71 #define PACKET_SUFFIX(packet, type)     (type *) packet_suffix((packet), sizeof(type))
     82#define PACKET_SUFFIX(packet, type) \
     83        (type *) packet_suffix((packet), sizeof(type))
    7284
    7385/** Trims the actual packet content by the specified prefix and suffix types.
    74  *  The wrapper of the packet_trim() function.
    75  *  @param[in] packet The packet to be trimmed.
    76  *  @param[in] prefix The type of the prefix to be removed from the beginning of the packet content.
    77  *  @param[in] suffix The type of the suffix to be removed from the end of the packet content.
    78  *  @returns EOK on success.
    79  *  @returns EINVAL if the packet is not valid.
    80  *  @returns ENOMEM if there is not enough memory left.
     86 *
     87 * The wrapper of the packet_trim() function.
     88 *
     89 * @param[in] packet    The packet to be trimmed.
     90 * @param[in] prefix    The type of the prefix to be removed from the beginning
     91 *                      of the packet content.
     92 * @param[in] suffix    The type of the suffix to be removed from the end of
     93 *                      the packet content.
     94 * @returns             EOK on success.
     95 * @returns             EINVAL if the packet is not valid.
     96 * @returns             ENOMEM if there is not enough memory left.
    8197 */
    82 #define PACKET_TRIM(packet, prefix, suffix)     packet_trim((packet), sizeof(prefix), sizeof(suffix))
     98#define PACKET_TRIM(packet, prefix, suffix) \
     99        packet_trim((packet), sizeof(prefix), sizeof(suffix))
    83100
    84 /** Allocates the specified space right before the actual packet content and returns its pointer.
    85  *  @param[in] packet The packet to be used.
    86  *  @param[in] length The space length to be allocated at the beginning of the packet content.
    87  *  @returns The pointer to the allocated memory.
    88  *  @returns NULL if there is not enough memory left.
    89  */
    90 extern void * packet_prefix(packet_t packet, size_t length);
    91 
    92 /** Allocates the specified space right after the actual packet content and returns its pointer.
    93  *  @param[in] packet The packet to be used.
    94  *  @param[in] length The space length to be allocated at the end of the packet content.
    95  *  @returns The pointer to the allocated memory.
    96  *  @returns NULL if there is not enough memory left.
    97  */
    98 extern void * packet_suffix(packet_t packet, size_t length);
    99 
    100 /** Trims the actual packet content by the specified prefix and suffix lengths.
    101  *  @param[in] packet The packet to be trimmed.
    102  *  @param[in] prefix The prefix length to be removed from the beginning of the packet content.
    103  *  @param[in] suffix The suffix length to be removed from the end of the packet content.
    104  *  @returns EOK on success.
    105  *  @returns EINVAL if the packet is not valid.
    106  *  @returns ENOMEM if there is not enough memory left.
    107  */
    108 extern int packet_trim(packet_t packet, size_t prefix, size_t suffix);
    109 
    110 /** Copies the specified data to the beginning of the actual packet content.
    111  *  Pushes the content end if needed.
    112  *  @param[in] packet The packet to be filled.
    113  *  @param[in] data The data to be copied.
    114  *  @param[in] length The length of the copied data.
    115  *  @returns EOK on success.
    116  *  @returns EINVAL if the packet is not valid.
    117  *  @returns ENOMEM if there is not enough memory left.
    118  */
    119 extern int packet_copy_data(packet_t packet, const void * data, size_t length);
    120 
    121 /** Returns the packet identifier.
    122  *  @param[in] packet The packet.
    123  *  @returns The packet identifier.
    124  *  @returns Zero (0) if the packet is not valid.
    125  */
    126 extern packet_id_t packet_get_id(const packet_t packet);
    127 
    128 /** Returns the packet content length.
    129  *  @param[in] packet The packet.
    130  *  @returns The packet content length in bytes.
    131  *  @returns Zero (0) if the packet is not valid.
    132  */
    133 extern size_t packet_get_data_length(const packet_t packet);
    134 
    135 /** Returns the pointer to the beginning of the packet content.
    136  *  @param[in] packet The packet.
    137  *  @returns The pointer to the beginning of the packet content.
    138  *  @returns NULL if the packet is not valid.
    139  */
    140 extern void * packet_get_data(const packet_t packet);
    141 
    142 /** Returns the stored packet addresses and their length.
    143  *  @param[in] packet The packet.
    144  *  @param[out] src The source address. May be NULL if not desired.
    145  *  @param[out] dest The destination address. May be NULL if not desired.
    146  *  @returns The stored addresses length.
    147  *  @returns Zero (0) if the addresses are not present.
    148  *  @returns EINVAL if the packet is not valid.
    149  */
    150 extern int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest);
    151 
    152 /** Sets the packet addresses.
    153  *  @param[in] packet The packet.
    154  *  @param[in] src The new source address. May be NULL.
    155  *  @param[in] dest The new destination address. May be NULL.
    156  *  @param[in] addr_len The addresses length.
    157  *  @returns EOK on success.
    158  *  @returns EINVAL if the packet is not valid.
    159  *  @returns ENOMEM if there is not enough memory left.
    160  */
    161 extern int packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len);
    162 
    163 /** Translates the packet identifier to the packet reference.
    164  *  Tries to find mapping first.
    165  *  Contacts the packet server to share the packet if the mapping is not present.
    166  *  @param[in] phone The packet server module phone.
    167  *  @param[out] packet The packet reference.
    168  *  @param[in] packet_id The packet identifier.
    169  *  @returns EOK on success.
    170  *  @returns EINVAL if the packet parameter is NULL.
    171  *  @returns Other error codes as defined for the NET_PACKET_GET_SIZE message.
    172  *  @returns Other error codes as defined for the packet_return() function.
    173  */
    174 extern int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id);
    175 
    176 /** Obtains the packet of the given dimensions.
    177  *  Contacts the packet server to return the appropriate packet.
    178  *  @param[in] phone The packet server module phone.
    179  *  @param[in] addr_len The source and destination addresses maximal length in bytes.
    180  *  @param[in] max_prefix The maximal prefix length in bytes.
    181  *  @param[in] max_content The maximal content length in bytes.
    182  *  @param[in] max_suffix The maximal suffix length in bytes.
    183  *  @returns The packet reference.
    184  *  @returns NULL on error.
    185  */
    186 extern packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);
    187 
    188 /** Obtains the packet of the given content size.
    189  *  Contacts the packet server to return the appropriate packet.
    190  *  @param[in] phone The packet server module phone.
    191  *  @param[in] content The maximal content length in bytes.
    192  *  @returns The packet reference.
    193  *  @returns NULL on error.
    194  */
    195 extern packet_t packet_get_1_remote(int phone, size_t content);
    196 
    197 /** Releases the packet queue.
    198  *  All packets in the queue are marked as free for use.
    199  *  The packet queue may be one packet only.
    200  *  The module should not use the packets after this point until they are received or obtained again.
    201  *  @param[in] phone The packet server module phone.
    202  *  @param[in] packet_id The packet identifier.
    203  */
    204 extern void pq_release_remote(int phone, packet_id_t packet_id);
    205 
    206 /** Returns the packet copy.
    207  *  Copies the addresses, data, order and metric values.
    208  *  Does not copy the queue placement.
    209  *  @param[in] phone The packet server module phone.
    210  *  @param[in] packet The original packet.
    211  *  @returns The packet copy.
    212  *  @returns NULL on error.
    213  */
     101extern void *packet_prefix(packet_t, size_t);
     102extern void *packet_suffix(packet_t, size_t);
     103extern int packet_trim(packet_t, size_t, size_t);
     104extern int packet_copy_data(packet_t, const void *, size_t);
     105extern packet_id_t packet_get_id(const packet_t);
     106extern size_t packet_get_data_length(const packet_t);
     107extern void *packet_get_data(const packet_t);
     108extern int packet_get_addr(const packet_t, uint8_t **, uint8_t **);
     109extern int packet_set_addr(packet_t, const uint8_t *, const uint8_t *, size_t);
    214110extern packet_t packet_get_copy(int phone, packet_t packet);
    215111
  • uspace/lib/net/include/packet_remote.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup packet
     29/** @addtogroup libnet
    3030 * @{
    3131 */
    3232
    33 #ifndef __NET_PACKET_REMOTE_H__
    34 #define __NET_PACKET_REMOTE_H__
     33#ifndef LIBNET_PACKET_REMOTE_H_
     34#define LIBNET_PACKET_REMOTE_H_
    3535
    3636#include <net/packet.h>
     37#include <sys/types.h>
    3738
    3839extern int packet_translate_remote(int, packet_ref, packet_id_t);
  • uspace/lib/net/include/socket_core.h

    ref689ef0 ra7a85d16  
    2727 */
    2828
    29 /** @addtogroup socket
     29/** @addtogroup libnet
    3030 *  @{
    3131 */
    3232
    3333/** @file
    34  *  Socket common core.
     34 * Socket common core.
    3535 */
    3636
    37 #ifndef __NET_SOCKET_CORE_H__
    38 #define __NET_SOCKET_CORE_H__
     37#ifndef LIBNET_SOCKET_CORE_H_
     38#define LIBNET_SOCKET_CORE_H_
    3939
    4040#include <sys/types.h>
    41 
    42 #include <net/in.h>
    43 #include <net/device.h>
    4441#include <adt/generic_char_map.h>
    4542#include <adt/dynamic_fifo.h>
    4643#include <adt/int_map.h>
     44#include <net/in.h>
     45#include <net/device.h>
    4746#include <net/packet.h>
    4847
    49 /** Initial size of the received packet queue.
    50  */
     48/** Initial size of the received packet queue. */
    5149#define SOCKET_INITIAL_RECEIVED_SIZE    4
    5250
    53 /** Maximum size of the received packet queue.
    54  */
    55 #define SOCKET_MAX_RECEIVED_SIZE                0
     51/** Maximum size of the received packet queue. */
     52#define SOCKET_MAX_RECEIVED_SIZE        0
    5653
    57 /** Initial size of the sockets for acceptance queue.
    58  */
     54/** Initial size of the sockets for acceptance queue. */
    5955#define SOCKET_INITIAL_ACCEPTED_SIZE    1
    6056
    61 /** Maximum size of the sockets for acceptance queue.
    62  */
    63 #define SOCKET_MAX_ACCEPTEDED_SIZE              0
     57/** Maximum size of the sockets for acceptance queue. */
     58#define SOCKET_MAX_ACCEPTEDED_SIZE      0
    6459
    65 /** Listening sockets' port map key.
    66  */
     60/** Listening sockets' port map key. */
    6761#define SOCKET_MAP_KEY_LISTENING        "L"
    6862
    6963/** Type definition of the socket core.
    70  *  @see socket_core
     64 * @see socket_core
    7165 */
    72 typedef struct socket_core      socket_core_t;
     66typedef struct socket_core socket_core_t;
    7367
    7468/** Type definition of the socket core pointer.
    75  *  @see socket_core
     69 * @see socket_core
    7670 */
    77 typedef socket_core_t * socket_core_ref;
     71typedef socket_core_t *socket_core_ref;
    7872
    7973/** Type definition of the socket port.
    80  *  @see socket_port
     74 * @see socket_port
    8175 */
    82 typedef struct socket_port      socket_port_t;
     76typedef struct socket_port socket_port_t;
    8377
    8478/** Type definition of the socket port pointer.
    85  *  @see socket_port
     79 * @see socket_port
    8680 */
    87 typedef socket_port_t * socket_port_ref;
     81typedef socket_port_t *socket_port_ref;
    8882
    89 /** Socket core.
    90  */
    91 struct socket_core{
    92         /** Socket identifier.
    93          */
     83/** Socket core. */
     84struct socket_core {
     85        /** Socket identifier. */
    9486        int socket_id;
    95         /** Client application phone.
    96          */
     87        /** Client application phone. */
    9788        int phone;
    98         /** Bound port.
    99          */
     89        /** Bound port. */
    10090        int port;
    101         /** Received packets queue.
    102          */
     91        /** Received packets queue. */
    10392        dyn_fifo_t received;
    104         /** Sockets for acceptance queue.
    105          */
     93        /** Sockets for acceptance queue. */
    10694        dyn_fifo_t accepted;
    107         /** Protocol specific data.
    108          */
    109         void * specific_data;
    110         /** Socket ports map key.
    111          */
    112         const char * key;
    113         /** Length of the Socket ports map key.
    114          */
     95        /** Protocol specific data. */
     96        void *specific_data;
     97        /** Socket ports map key. */
     98        const char *key;
     99        /** Length of the Socket ports map key. */
    115100        size_t key_length;
    116101};
    117102
    118103/** Sockets map.
    119  *  The key is the socket identifier.
     104 * The key is the socket identifier.
    120105 */
    121106INT_MAP_DECLARE(socket_cores, socket_core_t);
    122107
    123108/** Bount port sockets map.
    124  *  The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas the other use the remote addresses.
     109 *
     110 * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas
     111 * the other use the remote addresses.
    125112 */
    126113GENERIC_CHAR_MAP_DECLARE(socket_port_map, socket_core_ref);
    127114
    128115/** Ports map.
    129  *  The key is the port number.
     116 * The key is the port number.
    130117 */
    131118INT_MAP_DECLARE(socket_ports, socket_port_t);
    132119
    133 /** Destroys local sockets.
    134  *  Releases all buffered packets and calls the release function for each of the sockets.
    135  *  @param[in] packet_phone The packet server phone to release buffered packets.
    136  *  @param[in] local_sockets The local sockets to be destroyed.
    137  *  @param[in,out] global_sockets The global sockets to be updated.
    138  *  @param[in] socket_release The client release callback function.
    139  */
    140 extern void socket_cores_release(int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket));
    141 
    142 /** Binds the socket to the port.
    143  *  The address port is used if set, a free port is used if not.
    144  *  @param[in] local_sockets The local sockets to be searched.
    145  *  @param[in,out] global_sockets The global sockets to be updated.
    146  *  @param[in] socket_id The new socket identifier.
    147  *  @param[in] addr The address to be bound to.
    148  *  @param[in] addrlen The address length.
    149  *  @param[in] free_ports_start The minimum free port.
    150  *  @param[in] free_ports_end The maximum free port.
    151  *  @param[in] last_used_port The last used free port.
    152  *  @returns EOK on success.
    153  *  @returns ENOTSOCK if the socket was not found.
    154  *  @returns EAFNOSUPPORT if the address family is not supported.
    155  *  @returns EADDRINUSE if the port is already in use.
    156  *  @returns Other error codes as defined for the socket_bind_free_port() function.
    157  *  @returns Other error codes as defined for the socket_bind_insert() function.
    158  */
    159 extern int socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port);
    160 
    161 /** Binds the socket to a free port.
    162  *  The first free port is used.
    163  *  @param[in,out] global_sockets The global sockets to be updated.
    164  *  @param[in,out] socket The socket to be bound.
    165  *  @param[in] free_ports_start The minimum free port.
    166  *  @param[in] free_ports_end The maximum free port.
    167  *  @param[in] last_used_port The last used free port.
    168  *  @returns EOK on success.
    169  *  @returns ENOTCONN if no free port was found.
    170  *  @returns Other error codes as defined for the socket_bind_insert() function.
    171  */
    172 extern int socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port);
    173 
    174 /** Creates a new socket.
    175  *  @param[in,out] local_sockets The local sockets to be updated.
    176  *  @param[in] app_phone The application phone.
    177  *  @param[in] specific_data The socket specific data.
    178  *  @param[in,out] socket_id The new socket identifier. A new identifier is chosen if set to zero (0) or negative. A negative identifier is chosen if set to negative.
    179  *  @returns EOK on success.
    180  *  @returns EINVAL if the socket_id parameter is NULL.
    181  *  @returns ENOMEM if there is not enough memory left.
    182  */
    183 extern int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id);
    184 
    185 /** Destroys the socket.
    186  *  If the socket is bound, the port is released.
    187  *  Releases all buffered packets, calls the release function and removes the socket from the local sockets.
    188  *  @param[in] packet_phone The packet server phone to release buffered packets.
    189  *  @param[in] socket_id The socket identifier.
    190  *  @param[in,out] local_sockets The local sockets to be updated.
    191  *  @param[in,out] global_sockets The global sockets to be updated.
    192  *  @param[in] socket_release The client release callback function.
    193  *  @returns EOK on success.
    194  *  @returns ENOTSOCK if the socket is not found.
    195  */
    196 extern int socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket));
    197 
    198 /** Replies the packet or the packet queue data to the application via the socket.
    199  *  Uses the current message processing fibril.
    200  *  @param[in] packet The packet to be transfered.
    201  *  @param[out] length The total data length.
    202  *  @returns EOK on success.
    203  *  @returns EBADMEM if the length parameter is NULL.
    204  *  @returns ENOMEM if there is not enough memory left.
    205  *  @returns Other error codes as defined for the data_reply() function.
    206  */
    207 extern int socket_reply_packets(packet_t packet, size_t * length);
    208 
    209 /** Finds the bound port socket.
    210  *  @param[in] global_sockets The global sockets to be searched.
    211  *  @param[in] port The port number.
    212  *  @param[in] key The socket key identifier.
    213  *  @param[in] key_length The socket key length.
    214  *  @returns The found socket.
    215  *  @returns NULL if no socket was found.
    216  */
    217 extern socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length);
    218 
    219 /** Releases the socket port.
    220  *  If the socket is bound the port entry is released.
    221  *  If there are no more port entries the port is release.
    222  *  @param[in] global_sockets The global sockets to be updated.
    223  *  @param[in] socket The socket to be unbound.
    224  */
    225 extern void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket);
    226 
    227 /** Adds the socket to an already bound port.
    228  *  @param[in] global_sockets The global sockets to be updated.
    229  *  @param[in] port The port number to be bound to.
    230  *  @param[in] socket The socket to be added.
    231  *  @param[in] key The socket key identifier.
    232  *  @param[in] key_length The socket key length.
    233  *  @returns EOK on success.
    234  *  @returns ENOENT if the port is not already used.
    235  *  @returns Other error codes as defined for the socket_port_add_core() function.
    236  */
    237 extern int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length);
     120extern void socket_cores_release(int, socket_cores_ref, socket_ports_ref,
     121    void (*)(socket_core_ref));
     122extern int socket_bind(socket_cores_ref, socket_ports_ref, int, void *, size_t,
     123    int, int, int);
     124extern int socket_bind_free_port(socket_ports_ref, socket_core_ref, int, int,
     125    int);
     126extern int socket_create(socket_cores_ref, int, void *, int *);
     127extern int socket_destroy(int, int, socket_cores_ref, socket_ports_ref,
     128    void (*)(socket_core_ref));
     129extern int socket_reply_packets(packet_t, size_t *);
     130extern socket_core_ref socket_port_find(socket_ports_ref, int, const char *,
     131    size_t);
     132extern void socket_port_release(socket_ports_ref, socket_core_ref);
     133extern int socket_port_add(socket_ports_ref, int, socket_core_ref,
     134    const char *, size_t);
    238135
    239136#endif
  • uspace/lib/net/include/tl_interface.h

    ref689ef0 ra7a85d16  
    4040#include <async.h>
    4141#include <ipc/services.h>
     42#include <ipc/tl.h>
    4243
    4344#include <generic.h>
     
    4546#include <net/packet.h>
    4647#include <packet_client.h>
    47 #include <tl_messages.h>
    4848
    4949/** @name Transport layer module interface
Note: See TracChangeset for help on using the changeset viewer.