Rev 4163 | Rev 4243 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4163 | Rev 4192 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | /** @file |
33 | /** @file |
34 | */ |
34 | */ |
35 | 35 | ||
36 | #include <async.h> |
36 | #include <async.h> |
37 | #include <mem.h> |
37 | #include <mem.h> |
- | 38 | #include <rwlock.h> |
|
38 | #include <stdio.h> |
39 | #include <stdio.h> |
39 | 40 | ||
40 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
41 | #include <ipc/services.h> |
42 | #include <ipc/services.h> |
42 | //#include <sys/mman.h> |
- | |
43 | 43 | ||
44 | #include "../err.h" |
44 | #include "../err.h" |
45 | #include "../messages.h" |
45 | #include "../messages.h" |
46 | #include "../modules.h" |
46 | #include "../modules.h" |
47 | 47 | ||
Line 49... | Line 49... | ||
49 | #include "../structures/packet/packet_client.h" |
49 | #include "../structures/packet/packet_client.h" |
50 | #include "../structures/measured_strings.h" |
50 | #include "../structures/measured_strings.h" |
51 | 51 | ||
52 | #include "device.h" |
52 | #include "device.h" |
53 | #include "netif.h" |
53 | #include "netif.h" |
- | 54 | #include "netif_interface.h" |
|
54 | 55 | ||
55 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
56 | #define IPC_GET_DEVICE( call ) ( device_id_t ) IPC_GET_ARG1( * call ) |
56 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
57 | #define IPC_GET_PACKET( call ) ( packet_id_t ) IPC_GET_ARG2( * call ) |
57 | #define IPC_GET_IRQ( call ) ( int ) IPC_GET_ARG2( * call ) |
58 | #define IPC_GET_IRQ( call ) ( int ) IPC_GET_ARG2( * call ) |
58 | #define IPC_GET_IO( call ) ( int ) IPC_GET_ARG3( * call ) |
59 | #define IPC_GET_IO( call ) ( int ) IPC_GET_ARG3( * call ) |
59 | #define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
60 | #define IPC_GET_PHONE( call ) ( int ) IPC_GET_ARG5( * call ) |
60 | 61 | ||
61 | extern netif_globals_t netif_globals; |
62 | extern netif_globals_t netif_globals; |
62 | 63 | ||
63 | extern int initialize( void ); |
- | |
64 | extern int probe_auto_message( void ); |
- | |
65 | extern int probe_message( device_id_t device_id, int irq, int io ); |
- | |
66 | extern int send_message( device_id_t device_id, packet_t packet ); |
- | |
67 | extern int start_message( device_id_t device_id ); |
- | |
68 | extern int stop_message( device_id_t device_id ); |
- | |
69 | extern measured_string_ref get_addr_message( device_id_t device_id ); |
- | |
70 | - | ||
71 | DEVICE_MAP_IMPLEMENT( device_map, device_t ) |
64 | DEVICE_MAP_IMPLEMENT( device_map, device_t ) |
72 | 65 | ||
73 | int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
66 | int module_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ); |
74 | int netif_start_module( async_client_conn_t client_connection ); |
67 | int netif_start_module( async_client_conn_t client_connection ); |
75 | int register_message( device_id_t device_id, int phone ); |
68 | int register_message( device_id_t device_id, int phone ); |
76 | int get_device_stats( device_id_t device_id, device_stats_ref * stats ); |
- | |
77 | - | ||
78 | 69 | ||
79 | int find_device( device_id_t device_id, device_ref * device ){ |
70 | int find_device( device_id_t device_id, device_ref * device ){ |
80 | if( ! device ) return EBADMEM; |
71 | if( ! device ) return EBADMEM; |
81 | * device = device_map_find( & netif_globals.device_map, device_id ); |
72 | * device = device_map_find( & netif_globals.device_map, device_id ); |
82 | if( ! * device ) return ENOENT; |
73 | if( ! * device ) return ENOENT; |
83 | if(( ** device ).state == NETIF_NULL ) return EPERM; |
74 | if(( ** device ).state == NETIF_NULL ) return EPERM; |
84 | return EOK; |
75 | return EOK; |
85 | } |
76 | } |
86 | 77 | ||
87 | int get_device_stats( device_id_t device_id, device_stats_ref * stats ){ |
- | |
88 | ERROR_DECLARE; |
- | |
89 | - | ||
90 | device_ref device; |
- | |
91 | - | ||
92 | if( ! stats ) return EBADMEM; |
- | |
93 | ERROR_PROPAGATE( find_device( device_id, & device )); |
- | |
94 | * stats = & device->stats; |
- | |
95 | return EOK; |
- | |
96 | } |
- | |
97 | - | ||
98 | void null_device_stats( device_stats_ref stats ){ |
78 | void null_device_stats( device_stats_ref stats ){ |
99 | bzero( stats, sizeof( device_stats_t )); |
79 | bzero( stats, sizeof( device_stats_t )); |
100 | } |
80 | } |
101 | 81 | ||
102 | int register_message( device_id_t device_id, int phone ){ |
82 | int register_message( device_id_t device_id, int phone ){ |
Line 113... | Line 93... | ||
113 | 93 | ||
114 | int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
94 | int netif_message( ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count ){ |
115 | ERROR_DECLARE; |
95 | ERROR_DECLARE; |
116 | 96 | ||
117 | size_t length; |
97 | size_t length; |
118 | device_stats_ref stats; |
98 | device_stats_t stats; |
119 | packet_t packet; |
99 | packet_t packet; |
120 | measured_string_ref address; |
100 | measured_string_t address; |
121 | 101 | ||
122 | // printf( "\nNETIF message %d", method ); |
- | |
123 | * answer_count = 0; |
102 | * answer_count = 0; |
124 | switch( IPC_GET_METHOD( * call )){ |
103 | switch( IPC_GET_METHOD( * call )){ |
125 | case IPC_M_PHONE_HUNGUP: |
104 | case IPC_M_PHONE_HUNGUP: |
126 | return EOK; |
105 | return EOK; |
127 | case NET_NETIF_PROBE_AUTO: |
106 | case NET_NETIF_PROBE_AUTO: |
- | 107 | rwlock_write_lock( & netif_globals.lock ); |
|
128 | return probe_auto_message(); |
108 | ERROR_CODE = probe_auto_message(); |
- | 109 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 110 | return ERROR_CODE; |
|
129 | case NET_NETIF_PROBE: |
111 | case NET_NETIF_PROBE: |
- | 112 | rwlock_write_lock( & netif_globals.lock ); |
|
130 | return probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call )); |
113 | ERROR_CODE = probe_message( IPC_GET_DEVICE( call ), IPC_GET_IRQ( call ), IPC_GET_IO( call )); |
- | 114 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 115 | return ERROR_CODE; |
|
131 | case IPC_M_CONNECT_TO_ME: |
116 | case IPC_M_CONNECT_TO_ME: |
- | 117 | rwlock_write_lock( & netif_globals.lock ); |
|
132 | return register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call )); |
118 | ERROR_CODE = register_message( IPC_GET_DEVICE( call ), IPC_GET_PHONE( call )); |
- | 119 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 120 | return ERROR_CODE; |
|
133 | case NET_NETIF_SEND: |
121 | case NET_NETIF_SEND: |
- | 122 | rwlock_write_lock( & netif_globals.lock ); |
|
134 | ERROR_PROPAGATE( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call ))); |
123 | if( ! ERROR_OCCURRED( packet_translate( netif_globals.networking_phone, & packet, IPC_GET_PACKET( call )))){ |
135 | return send_message( IPC_GET_DEVICE( call ), packet ); |
124 | ERROR_CODE = send_message( IPC_GET_DEVICE( call ), packet ); |
- | 125 | } |
|
- | 126 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 127 | return ERROR_CODE; |
|
136 | case NET_NETIF_START: |
128 | case NET_NETIF_START: |
- | 129 | rwlock_write_lock( & netif_globals.lock ); |
|
137 | return start_message( IPC_GET_DEVICE( call )); |
130 | ERROR_CODE = start_message( IPC_GET_DEVICE( call )); |
- | 131 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 132 | return ERROR_CODE; |
|
138 | case NET_NETIF_STATS: |
133 | case NET_NETIF_STATS: |
- | 134 | rwlock_read_lock( & netif_globals.lock ); |
|
139 | ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length )); |
135 | if( ! ERROR_OCCURRED( ipc_data_read_receive( & callid, & length ))){ |
140 | if( length < sizeof( device_stats_t )) return EOVERFLOW; |
136 | if( length < sizeof( device_stats_t )){ |
- | 137 | ERROR_CODE = EOVERFLOW; |
|
- | 138 | }else{ |
|
141 | ERROR_PROPAGATE( get_device_stats( IPC_GET_DEVICE( call ), & stats )); |
139 | if( ! ERROR_OCCURRED( get_device_stats( IPC_GET_DEVICE( call ), & stats ))){ |
142 | return ipc_data_read_finalize( callid, stats, sizeof( device_stats_t )); |
140 | ERROR_CODE = ipc_data_read_finalize( callid, & stats, sizeof( device_stats_t )); |
- | 141 | } |
|
- | 142 | } |
|
- | 143 | } |
|
- | 144 | rwlock_read_unlock( & netif_globals.lock ); |
|
- | 145 | return ERROR_CODE; |
|
143 | case NET_NETIF_STOP: |
146 | case NET_NETIF_STOP: |
- | 147 | rwlock_write_lock( & netif_globals.lock ); |
|
144 | return stop_message( IPC_GET_DEVICE( call )); |
148 | ERROR_CODE = stop_message( IPC_GET_DEVICE( call )); |
- | 149 | rwlock_write_unlock( & netif_globals.lock ); |
|
- | 150 | return ERROR_CODE; |
|
145 | case NET_NETIF_GET_ADDR: |
151 | case NET_NETIF_GET_ADDR: |
- | 152 | rwlock_read_lock( & netif_globals.lock ); |
|
146 | address = get_addr_message( IPC_GET_DEVICE( call )); |
153 | if( ! ERROR_OCCURRED( get_addr_message( IPC_GET_DEVICE( call ), & address ))){ |
147 | return address ? measured_strings_reply( address, 1 ) : ENOENT; |
154 | ERROR_CODE = measured_strings_reply( & address, 1 ); |
- | 155 | } |
|
- | 156 | rwlock_read_unlock( & netif_globals.lock ); |
|
- | 157 | return ERROR_CODE; |
|
148 | } |
158 | } |
149 | return ENOTSUP; |
159 | return specific_message( callid, call, answer, answer_count ); |
150 | } |
160 | } |
151 | 161 | ||
152 | int netif_start_module( async_client_conn_t client_connection ){ |
162 | int netif_start_module( async_client_conn_t client_connection ){ |
153 | ERROR_DECLARE; |
163 | ERROR_DECLARE; |
154 | 164 | ||
155 | async_set_client_connection( client_connection ); |
165 | async_set_client_connection( client_connection ); |
156 | netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING ); |
166 | netif_globals.networking_phone = connect_to_service( SERVICE_NETWORKING ); |
157 | device_map_initialize( & netif_globals.device_map ); |
167 | device_map_initialize( & netif_globals.device_map ); |
158 | ERROR_PROPAGATE( pm_init()); |
168 | ERROR_PROPAGATE( pm_init()); |
- | 169 | rwlock_initialize( & netif_globals.lock ); |
|
159 | if( ERROR_OCCURRED( initialize())){ |
170 | if( ERROR_OCCURRED( initialize())){ |
160 | pm_destroy(); |
171 | pm_destroy(); |
161 | return ERROR_CODE; |
172 | return ERROR_CODE; |
162 | } |
173 | } |
163 | 174 | ||
Line 165... | Line 176... | ||
165 | 176 | ||
166 | pm_destroy(); |
177 | pm_destroy(); |
167 | return EOK; |
178 | return EOK; |
168 | } |
179 | } |
169 | 180 | ||
- | 181 | void netif_pq_release( packet_id_t packet_id ){ |
|
- | 182 | pq_release( netif_globals.networking_phone, packet_id ); |
|
- | 183 | } |
|
- | 184 | ||
- | 185 | packet_t netif_packet_get_1( size_t content ){ |
|
- | 186 | return packet_get_1( netif_globals.networking_phone, content ); |
|
- | 187 | } |
|
- | 188 | ||
170 | /** @} |
189 | /** @} |
171 | */ |
190 | */ |