| 1 | /*
|
|---|
| 2 | * Copyright (c) 2012 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup udp
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file UDP type definitions
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #ifndef UDP_TYPE_H
|
|---|
| 36 | #define UDP_TYPE_H
|
|---|
| 37 |
|
|---|
| 38 | #include <fibril_synch.h>
|
|---|
| 39 | #include <socket_core.h>
|
|---|
| 40 | #include <sys/types.h>
|
|---|
| 41 |
|
|---|
| 42 | typedef enum {
|
|---|
| 43 | UDP_EOK
|
|---|
| 44 | } udp_error_t;
|
|---|
| 45 |
|
|---|
| 46 | typedef enum {
|
|---|
| 47 | XF_DUMMY = 0x1
|
|---|
| 48 | } xflags_t;
|
|---|
| 49 |
|
|---|
| 50 | typedef struct {
|
|---|
| 51 | uint32_t ipv4;
|
|---|
| 52 | } netaddr_t;
|
|---|
| 53 |
|
|---|
| 54 | enum netaddr {
|
|---|
| 55 | UDP_IPV4_ANY = 0
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 | typedef struct {
|
|---|
| 59 | netaddr_t addr;
|
|---|
| 60 | uint16_t port;
|
|---|
| 61 | } udp_sock_t;
|
|---|
| 62 |
|
|---|
| 63 | typedef struct {
|
|---|
| 64 | udp_sock_t local;
|
|---|
| 65 | udp_sock_t foreign;
|
|---|
| 66 | } udp_sockpair_t;
|
|---|
| 67 |
|
|---|
| 68 | /** Unencoded UDP message (datagram) */
|
|---|
| 69 | typedef struct {
|
|---|
| 70 | /** Message data */
|
|---|
| 71 | void *data;
|
|---|
| 72 | /** Message data size */
|
|---|
| 73 | size_t data_size;
|
|---|
| 74 | } udp_msg_t;
|
|---|
| 75 |
|
|---|
| 76 | /** Encoded PDU */
|
|---|
| 77 | typedef struct {
|
|---|
| 78 | /** Source address */
|
|---|
| 79 | netaddr_t src;
|
|---|
| 80 | /** Destination address */
|
|---|
| 81 | netaddr_t dest;
|
|---|
| 82 |
|
|---|
| 83 | /** Encoded PDU data including header */
|
|---|
| 84 | void *data;
|
|---|
| 85 | /** Encoded PDU data size */
|
|---|
| 86 | size_t data_size;
|
|---|
| 87 | } udp_pdu_t;
|
|---|
| 88 |
|
|---|
| 89 | typedef struct {
|
|---|
| 90 | async_sess_t *sess;
|
|---|
| 91 | socket_cores_t sockets;
|
|---|
| 92 | } udp_client_t;
|
|---|
| 93 |
|
|---|
| 94 | typedef struct {
|
|---|
| 95 | char *name;
|
|---|
| 96 | udp_sockpair_t ident;
|
|---|
| 97 | } udp_assoc_t;
|
|---|
| 98 |
|
|---|
| 99 | typedef struct {
|
|---|
| 100 | } udp_assoc_status_t;
|
|---|
| 101 |
|
|---|
| 102 | typedef struct udp_sockdata {
|
|---|
| 103 | /** Lock */
|
|---|
| 104 | fibril_mutex_t lock;
|
|---|
| 105 | /** Socket core */
|
|---|
| 106 | socket_core_t *sock_core;
|
|---|
| 107 | /** Client */
|
|---|
| 108 | udp_client_t *client;
|
|---|
| 109 | /** Connection */
|
|---|
| 110 | udp_assoc_t *assoc;
|
|---|
| 111 | /** Local address */
|
|---|
| 112 | netaddr_t laddr;
|
|---|
| 113 | } udp_sockdata_t;
|
|---|
| 114 |
|
|---|
| 115 | #endif
|
|---|
| 116 |
|
|---|
| 117 | /** @}
|
|---|
| 118 | */
|
|---|