Subversion Repositories HelenOS

Rev

Rev 3912 | Rev 4243 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3912 Rev 3990
1
/*
1
/*
2
 * Copyright (c) 2009 Lukas Mejdrech
2
 * Copyright (c) 2009 Lukas Mejdrech
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup packet
29
/** @addtogroup packet
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
34
 *  Packet map and queue.
34
 *  Packet map and queue.
35
 */
35
 */
36
 
36
 
37
#ifndef __NET_PACKET_H__
37
#ifndef __NET_PACKET_H__
38
#define __NET_PACKET_H__
38
#define __NET_PACKET_H__
39
 
39
 
40
/** Packet identifier type.
40
/** Packet identifier type.
41
 *  Value zero (0) is used as an invalid identifier.
41
 *  Value zero (0) is used as an invalid identifier.
42
 */
42
 */
43
typedef unsigned int    packet_id_t;
43
typedef unsigned int    packet_id_t;
44
 
44
 
45
/** Type definition of the packet.
45
/** Type definition of the packet.
46
 *  @see packet
46
 *  @see packet
47
 */
47
 */
48
typedef struct packet * packet_t;
48
typedef struct packet * packet_t;
49
 
49
 
50
/** Type definition of the packet pointer.
50
/** Type definition of the packet pointer.
51
 *  @see packet
51
 *  @see packet
52
 */
52
 */
53
typedef packet_t *      packet_ref;
53
typedef packet_t *      packet_ref;
54
 
54
 
55
/** Packet operation mode type.
55
/** Type of the received packet.
56
 */
56
 */
-
 
57
enum packet_type{
57
typedef enum packet_mode    packet_mode_t;
58
    /** The packet is from the local subsystem.
58
 
59
     */
-
 
60
    PACKET_SELF,
59
/** Packet operation mode.
61
    /** The packet is for all hosts.
60
 */
62
     */
61
enum    packet_mode{
63
    PACKET_BROADCAST,
62
    /** The packet is processed in one direction and can be released at any time.
64
    /** The packet target complies with the local subsystem filter.
63
     */
65
     */
64
    PM_ONE_WAY,
66
    PACKET_MULTICAST,
65
    /** The packet should be returned at the end of the processing back to its initiator.
67
    /** The packet is for the local subsystem from other host.
66
     */
68
     */
67
    PM_RETURN
69
    PACKET_OTHERHOST
68
};
70
};
69
 
71
 
70
/** Finds the packet mapping.
72
/** Finds the packet mapping.
71
 *  @param packet_id The packet identifier to be found. Input parameter.
73
 *  @param packet_id The packet identifier to be found. Input parameter.
72
 *  @returns The found packet reference.
74
 *  @returns The found packet reference.
73
 *  @returns NULL if the mapping does not exist.
75
 *  @returns NULL if the mapping does not exist.
74
 */
76
 */
75
packet_t    pm_find( packet_id_t packet_id );
77
packet_t    pm_find( packet_id_t packet_id );
76
 
78
 
77
/** Adds the packet mapping.
79
/** Adds the packet mapping.
78
 *  @param packet The packet to be remembered. Input parameter.
80
 *  @param packet The packet to be remembered. Input parameter.
79
 *  @returns EOK on success.
81
 *  @returns EOK on success.
80
 *  @returns EINVAL if the packet is not valid.
82
 *  @returns EINVAL if the packet is not valid.
81
 *  @returns EINVAL if the packet map is not initialized.
83
 *  @returns EINVAL if the packet map is not initialized.
82
 *  @returns ENOMEM if there is not enough memory left.
84
 *  @returns ENOMEM if there is not enough memory left.
83
 */
85
 */
84
int pm_add( packet_t packet );
86
int pm_add( packet_t packet );
85
 
87
 
86
/** Initializes the packet map.
88
/** Initializes the packet map.
87
 *  @returns EOK on success.
89
 *  @returns EOK on success.
88
 *  @returns ENOMEM if there is not enough memory left.
90
 *  @returns ENOMEM if there is not enough memory left.
89
 */
91
 */
90
int pm_init( void );
92
int pm_init( void );
91
 
93
 
92
/** Releases the packet map.
94
/** Releases the packet map.
93
 */
95
 */
94
void    pm_destroy( void );
96
void    pm_destroy( void );
95
 
97
 
96
/** Add packet to the sorted queue.
98
/** Add packet to the sorted queue.
97
 *  The queue is sorted in the ascending order.
99
 *  The queue is sorted in the ascending order.
98
 *  The packet is inserted right before the packets of the same order value.
100
 *  The packet is inserted right before the packets of the same order value.
99
 *  @param first The first packet of the queue. May be NULL. Input parameter.
101
 *  @param first The first packet of the queue. May be NULL. Input parameter.
100
 *  @param packet The packet to be added. Input parameter.
102
 *  @param packet The packet to be added. Input parameter.
101
 *  @param order The packet order value. Input parameter.
103
 *  @param order The packet order value. Input parameter.
102
 *  @param metric The metric value of the packet. Input parameter.
104
 *  @param metric The metric value of the packet. Input parameter.
103
 *  @returns The first packet of the queue. The original first packet may be shifted by the new packet.
105
 *  @returns The first packet of the queue. The original first packet may be shifted by the new packet.
104
 *  @returns NULL if the packet is not valid.
106
 *  @returns NULL if the packet is not valid.
105
 */
107
 */
106
packet_t    pq_add( packet_t first, packet_t packet, int order, size_t metric );
108
packet_t    pq_add( packet_t first, packet_t packet, int order, size_t metric );
107
 
109
 
108
/** Detach the packet from the queue.
110
/** Detach the packet from the queue.
109
 *  @param packet The packet to be detached. Input parameter.
111
 *  @param packet The packet to be detached. Input parameter.
110
 *  @returns The next packet in the queue. If the packet is the first one of the queue, this becomes the new first one.
112
 *  @returns The next packet in the queue. If the packet is the first one of the queue, this becomes the new first one.
-
 
113
 *  @returns NULL if there is no packet left.
111
 *  @returns NULL if the packet is not valid.
114
 *  @returns NULL if the packet is not valid.
112
 */
115
 */
113
packet_t    pq_detach( packet_t packet );
116
packet_t    pq_detach( packet_t packet );
114
 
117
 
115
/** Sets the packet order and metric attributes.
118
/** Sets the packet order and metric attributes.
116
 *  @param packet The packet to be set. Input parameter.
119
 *  @param packet The packet to be set. Input parameter.
117
 *  @param order The packet order value. Input parameter.
120
 *  @param order The packet order value. Input parameter.
118
 *  @param metric The metric value of the packet. Input parameter.
121
 *  @param metric The metric value of the packet. Input parameter.
119
 */
122
 */
120
int pq_set( packet_t packet, int order, size_t metric );
123
int pq_set( packet_t packet, int order, size_t metric );
121
 
124
 
122
/** Releases the whole queue.
125
/** Releases the whole queue.
123
 *  Detaches all packets of the queue and calls the packet_release() for each of them.
126
 *  Detaches all packets of the queue and calls the packet_release() for each of them.
124
 *  @param first The first packet of the queue. Input parameter.
127
 *  @param first The first packet of the queue. Input parameter.
125
 *  @param packet_release The releasing function called for each of the packets after its detachment. Input parameter.
128
 *  @param packet_release The releasing function called for each of the packets after its detachment. Input parameter.
126
 */
129
 */
127
void    pq_destroy( packet_t first, void ( * packet_release )( packet_t packet ));
130
void    pq_destroy( packet_t first, void ( * packet_release )( packet_t packet ));
128
 
131
 
129
#endif
132
#endif
130
 
133
 
131
/** @}
134
/** @}
132
 */
135
 */
133
 
136