Rev 1088 | Rev 1248 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1088 | Rev 1090 | ||
---|---|---|---|
Line 45... | Line 45... | ||
45 | #define GET_CHECK_PHONE(phone,phoneid,err) { \ |
45 | #define GET_CHECK_PHONE(phone,phoneid,err) { \ |
46 | if (phoneid > IPC_MAX_PHONES) { err; } \ |
46 | if (phoneid > IPC_MAX_PHONES) { err; } \ |
47 | phone = &TASK->phones[phoneid]; \ |
47 | phone = &TASK->phones[phoneid]; \ |
48 | } |
48 | } |
49 | 49 | ||
50 | #define STRUCT_TO_USPACE(dst,src) copy_to_uspace(dst,src,sizeof(*src)) |
50 | #define STRUCT_TO_USPACE(dst,src) copy_to_uspace(dst,src,sizeof(*(src))) |
51 | 51 | ||
52 | /** Return true if the method is a system method */ |
52 | /** Return true if the method is a system method */ |
53 | static inline int is_system_method(__native method) |
53 | static inline int is_system_method(__native method) |
54 | { |
54 | { |
55 | if (method <= IPC_M_LAST_SYSTEM) |
55 | if (method <= IPC_M_LAST_SYSTEM) |
Line 105... | Line 105... | ||
105 | /* The connection was not accepted */ |
105 | /* The connection was not accepted */ |
106 | phone_dealloc(phoneid); |
106 | phone_dealloc(phoneid); |
107 | } else { |
107 | } else { |
108 | /* The connection was accepted */ |
108 | /* The connection was accepted */ |
109 | phone_connect(phoneid,&answer->sender->answerbox); |
109 | phone_connect(phoneid,&answer->sender->answerbox); |
- | 110 | /* Set 'phone identification' as arg3 of response */ |
|
- | 111 | IPC_SET_ARG3(answer->data, (__native)&TASK->phones[phoneid]); |
|
110 | } |
112 | } |
111 | } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) { |
113 | } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) { |
112 | /* If the users accepted call, connect */ |
114 | /* If the users accepted call, connect */ |
113 | if (!IPC_GET_RETVAL(answer->data)) { |
115 | if (!IPC_GET_RETVAL(answer->data)) { |
114 | ipc_phone_connect((phone_t *)IPC_GET_ARG3(*olddata), |
116 | ipc_phone_connect((phone_t *)IPC_GET_ARG3(*olddata), |
115 | &TASK->answerbox); |
117 | &TASK->answerbox); |
116 | } |
118 | } |
117 | } |
119 | } |
118 | } |
120 | } |
119 | 121 | ||
- | 122 | /** Called before the request is sent |
|
- | 123 | * |
|
- | 124 | * @return 0 - no error, -1 - report error to user |
|
- | 125 | */ |
|
- | 126 | static int request_preprocess(call_t *call) |
|
- | 127 | { |
|
- | 128 | int newphid; |
|
- | 129 | ||
- | 130 | switch (IPC_GET_METHOD(call->data)) { |
|
- | 131 | case IPC_M_CONNECT_ME_TO: |
|
- | 132 | newphid = phone_alloc(); |
|
- | 133 | if (newphid < 0) |
|
- | 134 | return ELIMIT; |
|
- | 135 | /* Set arg3 for server */ |
|
- | 136 | IPC_SET_ARG3(call->data, (__native)&TASK->phones[newphid]); |
|
- | 137 | call->flags |= IPC_CALL_CONN_ME_TO; |
|
- | 138 | call->private = newphid; |
|
- | 139 | break; |
|
- | 140 | default: |
|
- | 141 | break; |
|
- | 142 | } |
|
- | 143 | return 0; |
|
- | 144 | } |
|
- | 145 | ||
120 | /****************************************************/ |
146 | /****************************************************/ |
121 | /* Functions called to process received call/answer |
147 | /* Functions called to process received call/answer |
122 | * before passing to uspace |
148 | * before passing to uspace |
123 | */ |
149 | */ |
124 | 150 | ||
125 | /** Do basic kernel processing of received call answer */ |
151 | /** Do basic kernel processing of received call answer */ |
126 | static int process_answer(answerbox_t *box,call_t *call) |
152 | static void process_answer(call_t *call) |
127 | { |
153 | { |
128 | if (IPC_GET_RETVAL(call->data) == EHANGUP && \ |
154 | if (IPC_GET_RETVAL(call->data) == EHANGUP && \ |
129 | call->flags & IPC_CALL_FORWARDED) |
155 | call->flags & IPC_CALL_FORWARDED) |
130 | IPC_SET_RETVAL(call->data, EFORWARD); |
156 | IPC_SET_RETVAL(call->data, EFORWARD); |
- | 157 | ||
- | 158 | if (call->flags & IPC_CALL_CONN_ME_TO) { |
|
- | 159 | if (IPC_GET_RETVAL(call->data)) |
|
- | 160 | phone_dealloc(call->private); |
|
131 | return 0; |
161 | else |
- | 162 | IPC_SET_ARG3(call->data, call->private); |
|
- | 163 | } |
|
132 | } |
164 | } |
133 | 165 | ||
134 | /** Do basic kernel processing of received call request |
166 | /** Do basic kernel processing of received call request |
135 | * |
167 | * |
136 | * @return 0 - the call should be passed to userspace, 1 - ignore call |
168 | * @return 0 - the call should be passed to userspace, 1 - ignore call |
Line 159... | Line 191... | ||
159 | __native sys_ipc_call_sync_fast(__native phoneid, __native method, |
191 | __native sys_ipc_call_sync_fast(__native phoneid, __native method, |
160 | __native arg1, ipc_data_t *data) |
192 | __native arg1, ipc_data_t *data) |
161 | { |
193 | { |
162 | call_t call; |
194 | call_t call; |
163 | phone_t *phone; |
195 | phone_t *phone; |
164 | - | ||
165 | if (is_system_method(method)) |
- | |
166 | return EPERM; |
196 | int res; |
167 | 197 | ||
168 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
198 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
169 | 199 | ||
170 | ipc_call_static_init(&call); |
200 | ipc_call_static_init(&call); |
171 | IPC_SET_METHOD(call.data, method); |
201 | IPC_SET_METHOD(call.data, method); |
172 | IPC_SET_ARG1(call.data, arg1); |
202 | IPC_SET_ARG1(call.data, arg1); |
173 | 203 | ||
- | 204 | if (!(res=request_preprocess(&call))) { |
|
174 | ipc_call_sync(phone, &call); |
205 | ipc_call_sync(phone, &call); |
- | 206 | process_answer(&call); |
|
175 | 207 | } else |
|
- | 208 | IPC_SET_RETVAL(call.data, res); |
|
176 | STRUCT_TO_USPACE(&data->args, &call.data.args); |
209 | STRUCT_TO_USPACE(&data->args, &call.data.args); |
177 | 210 | ||
178 | return 0; |
211 | return 0; |
179 | } |
212 | } |
180 | 213 | ||
Line 182... | Line 215... | ||
182 | __native sys_ipc_call_sync(__native phoneid, ipc_data_t *question, |
215 | __native sys_ipc_call_sync(__native phoneid, ipc_data_t *question, |
183 | ipc_data_t *reply) |
216 | ipc_data_t *reply) |
184 | { |
217 | { |
185 | call_t call; |
218 | call_t call; |
186 | phone_t *phone; |
219 | phone_t *phone; |
- | 220 | int res; |
|
187 | 221 | ||
188 | ipc_call_static_init(&call); |
222 | ipc_call_static_init(&call); |
189 | copy_from_uspace(&call.data.args, &question->args, sizeof(call.data.args)); |
223 | copy_from_uspace(&call.data.args, &question->args, sizeof(call.data.args)); |
190 | 224 | ||
191 | if (is_system_method(IPC_GET_METHOD(call.data))) |
- | |
192 | return EPERM; |
- | |
193 | - | ||
194 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
225 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
195 | 226 | ||
- | 227 | if (!(res=request_preprocess(&call))) { |
|
196 | ipc_call_sync(phone, &call); |
228 | ipc_call_sync(phone, &call); |
- | 229 | process_answer(&call); |
|
- | 230 | } else |
|
- | 231 | IPC_SET_RETVAL(call.data, res); |
|
197 | 232 | ||
198 | STRUCT_TO_USPACE(&reply->args, &call.data.args); |
233 | STRUCT_TO_USPACE(&reply->args, &call.data.args); |
199 | 234 | ||
200 | return 0; |
235 | return 0; |
201 | } |
236 | } |
Line 221... | Line 256... | ||
221 | __native sys_ipc_call_async_fast(__native phoneid, __native method, |
256 | __native sys_ipc_call_async_fast(__native phoneid, __native method, |
222 | __native arg1, __native arg2) |
257 | __native arg1, __native arg2) |
223 | { |
258 | { |
224 | call_t *call; |
259 | call_t *call; |
225 | phone_t *phone; |
260 | phone_t *phone; |
226 | - | ||
227 | if (is_system_method(method)) |
- | |
228 | return IPC_CALLRET_FATAL; |
261 | int res; |
229 | 262 | ||
230 | if (check_call_limit()) |
263 | if (check_call_limit()) |
231 | return IPC_CALLRET_TEMPORARY; |
264 | return IPC_CALLRET_TEMPORARY; |
232 | 265 | ||
233 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
266 | GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL); |
234 | 267 | ||
235 | call = ipc_call_alloc(); |
268 | call = ipc_call_alloc(); |
236 | IPC_SET_METHOD(call->data, method); |
269 | IPC_SET_METHOD(call->data, method); |
237 | IPC_SET_ARG1(call->data, arg1); |
270 | IPC_SET_ARG1(call->data, arg1); |
238 | IPC_SET_ARG2(call->data, arg2); |
271 | IPC_SET_ARG2(call->data, arg2); |
239 | 272 | ||
- | 273 | if (!(res=request_preprocess(call))) |
|
240 | ipc_call(phone, call); |
274 | ipc_call(phone, call); |
- | 275 | else |
|
- | 276 | ipc_backsend_err(phone, call, res); |
|
241 | 277 | ||
242 | return (__native) call; |
278 | return (__native) call; |
243 | } |
279 | } |
244 | 280 | ||
245 | /** Synchronous IPC call allowing to send whole message |
281 | /** Synchronous IPC call allowing to send whole message |
Line 248... | Line 284... | ||
248 | */ |
284 | */ |
249 | __native sys_ipc_call_async(__native phoneid, ipc_data_t *data) |
285 | __native sys_ipc_call_async(__native phoneid, ipc_data_t *data) |
250 | { |
286 | { |
251 | call_t *call; |
287 | call_t *call; |
252 | phone_t *phone; |
288 | phone_t *phone; |
- | 289 | int res; |
|
253 | 290 | ||
254 | if (check_call_limit()) |
291 | if (check_call_limit()) |
255 | return IPC_CALLRET_TEMPORARY; |
292 | return IPC_CALLRET_TEMPORARY; |
256 | 293 | ||
257 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
294 | GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL); |
258 | 295 | ||
259 | call = ipc_call_alloc(); |
296 | call = ipc_call_alloc(); |
260 | copy_from_uspace(&call->data.args, &data->args, sizeof(call->data.args)); |
297 | copy_from_uspace(&call->data.args, &data->args, sizeof(call->data.args)); |
261 | - | ||
262 | if (is_system_method(IPC_GET_METHOD(call->data))) { |
298 | if (!(res=request_preprocess(call))) |
263 | ipc_call_free(call); |
- | |
264 | return EPERM; |
- | |
265 | } |
- | |
266 | - | ||
267 | ipc_call(phone, call); |
299 | ipc_call(phone, call); |
- | 300 | else |
|
- | 301 | ipc_backsend_err(phone, call, res); |
|
268 | 302 | ||
269 | return (__native) call; |
303 | return (__native) call; |
270 | } |
304 | } |
271 | 305 | ||
272 | /** Forward received call to another destination |
306 | /** Forward received call to another destination |
Line 302... | Line 336... | ||
302 | 336 | ||
303 | /* Userspace is not allowed to change method of system methods |
337 | /* Userspace is not allowed to change method of system methods |
304 | * on forward, allow changing ARG1 and ARG2 by means of method and arg1 |
338 | * on forward, allow changing ARG1 and ARG2 by means of method and arg1 |
305 | */ |
339 | */ |
306 | if (is_system_method(IPC_GET_METHOD(call->data))) { |
340 | if (is_system_method(IPC_GET_METHOD(call->data))) { |
- | 341 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) |
|
- | 342 | phone_dealloc(IPC_GET_ARG3(call->data)); |
|
- | 343 | ||
307 | IPC_SET_ARG1(call->data, method); |
344 | IPC_SET_ARG1(call->data, method); |
308 | IPC_SET_ARG2(call->data, arg1); |
345 | IPC_SET_ARG2(call->data, arg1); |
309 | } else { |
346 | } else { |
310 | IPC_SET_METHOD(call->data, method); |
347 | IPC_SET_METHOD(call->data, method); |
311 | IPC_SET_ARG1(call->data, arg1); |
348 | IPC_SET_ARG1(call->data, arg1); |
Line 363... | Line 400... | ||
363 | ipc_answer(&TASK->answerbox, call); |
400 | ipc_answer(&TASK->answerbox, call); |
364 | 401 | ||
365 | return 0; |
402 | return 0; |
366 | } |
403 | } |
367 | 404 | ||
368 | /** Ask the other side of connection to do 'callback' connection |
- | |
369 | * |
- | |
370 | * @return 0 if no error, error otherwise |
- | |
371 | */ |
- | |
372 | __native sys_ipc_connect_to_me(__native phoneid, __native arg1, |
- | |
373 | __native arg2, task_id_t *taskid) |
- | |
374 | { |
- | |
375 | call_t call; |
- | |
376 | phone_t *phone; |
- | |
377 | - | ||
378 | ipc_call_static_init(&call); |
- | |
379 | IPC_SET_METHOD(call.data, IPC_M_CONNECT_TO_ME); |
- | |
380 | IPC_SET_ARG1(call.data, arg1); |
- | |
381 | IPC_SET_ARG2(call.data, arg2); |
- | |
382 | - | ||
383 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
- | |
384 | - | ||
385 | ipc_call_sync(phone, &call); |
- | |
386 | - | ||
387 | if (!IPC_GET_RETVAL(call.data) && taskid) |
- | |
388 | STRUCT_TO_USPACE(taskid, &phone->callee->task->taskid); |
- | |
389 | - | ||
390 | return IPC_GET_RETVAL(call.data); |
- | |
391 | } |
- | |
392 | - | ||
393 | /** Ask target process to connect me somewhere |
- | |
394 | * |
- | |
395 | * @return phoneid - on success, error otherwise |
- | |
396 | */ |
- | |
397 | __native sys_ipc_connect_me_to(__native phoneid, __native arg1, |
- | |
398 | __native arg2) |
- | |
399 | { |
- | |
400 | call_t call; |
- | |
401 | phone_t *phone; |
- | |
402 | int newphid; |
- | |
403 | - | ||
404 | GET_CHECK_PHONE(phone, phoneid, return ENOENT); |
- | |
405 | - | ||
406 | newphid = phone_alloc(); |
- | |
407 | if (newphid < 0) |
- | |
408 | return ELIMIT; |
- | |
409 | - | ||
410 | ipc_call_static_init(&call); |
- | |
411 | IPC_SET_METHOD(call.data, IPC_M_CONNECT_ME_TO); |
- | |
412 | IPC_SET_ARG1(call.data, arg1); |
- | |
413 | IPC_SET_ARG2(call.data, arg2); |
- | |
414 | IPC_SET_ARG3(call.data, (__native)&TASK->phones[newphid]); |
- | |
415 | - | ||
416 | ipc_call_sync(phone, &call); |
- | |
417 | - | ||
418 | if (IPC_GET_RETVAL(call.data)) { /* Connection failed */ |
- | |
419 | phone_dealloc(newphid); |
- | |
420 | return IPC_GET_RETVAL(call.data); |
- | |
421 | } |
- | |
422 | - | ||
423 | return newphid; |
- | |
424 | } |
- | |
425 | - | ||
426 | /** Hang up the phone |
405 | /** Hang up the phone |
427 | * |
406 | * |
428 | * |
- | |
429 | * |
- | |
430 | */ |
407 | */ |
431 | __native sys_ipc_hangup(int phoneid) |
408 | __native sys_ipc_hangup(int phoneid) |
432 | { |
409 | { |
433 | phone_t *phone; |
410 | phone_t *phone; |
434 | 411 | ||
Line 446... | Line 423... | ||
446 | * @param taskid On 'CONNECT_ME_TO' call it is filled with 'taskid' of |
423 | * @param taskid On 'CONNECT_ME_TO' call it is filled with 'taskid' of |
447 | * the caller. |
424 | * the caller. |
448 | * @param flags |
425 | * @param flags |
449 | * @return Callid, if callid & 1, then the call is answer |
426 | * @return Callid, if callid & 1, then the call is answer |
450 | */ |
427 | */ |
451 | __native sys_ipc_wait_for_call(ipc_data_t *calldata, task_id_t *taskid, |
428 | __native sys_ipc_wait_for_call(ipc_data_t *calldata, __native flags) |
452 | __native flags) |
- | |
453 | - | ||
454 | { |
429 | { |
455 | call_t *call; |
430 | call_t *call; |
456 | 431 | ||
457 | restart: |
432 | restart: |
458 | call = ipc_wait_for_call(&TASK->answerbox, flags); |
433 | call = ipc_wait_for_call(&TASK->answerbox, flags); |
459 | if (!call) |
434 | if (!call) |
460 | return 0; |
435 | return 0; |
461 | 436 | ||
462 | if (call->flags & IPC_CALL_ANSWERED) { |
437 | if (call->flags & IPC_CALL_ANSWERED) { |
463 | if (process_answer(&TASK->answerbox, call)) |
438 | process_answer(call); |
464 | goto restart; |
- | |
465 | 439 | ||
466 | ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); |
440 | ASSERT(! (call->flags & IPC_CALL_STATIC_ALLOC)); |
467 | 441 | ||
468 | atomic_dec(&TASK->active_calls); |
442 | atomic_dec(&TASK->active_calls); |
469 | 443 | ||
Line 479... | Line 453... | ||
479 | } |
453 | } |
480 | 454 | ||
481 | if (process_request(&TASK->answerbox, call)) |
455 | if (process_request(&TASK->answerbox, call)) |
482 | goto restart; |
456 | goto restart; |
483 | 457 | ||
484 | /* Include phone address('id') of the caller in the request */ |
458 | /* Include phone address('id') of the caller in the request, |
- | 459 | * copy whole call->data, not only call->data.args */ |
|
485 | STRUCT_TO_USPACE(calldata, &call->data); |
460 | STRUCT_TO_USPACE(calldata, &call->data); |
486 | if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_ME_TO) |
- | |
487 | STRUCT_TO_USPACE(taskid, &TASK->taskid); |
- | |
488 | return (__native)call; |
461 | return (__native)call; |
489 | } |
462 | } |