[f0defd2] | 1 | /*
|
---|
[e8039a86] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[48bcf49] | 3 | * Copyright (c) 2012 Jakub Jermar
|
---|
[f0defd2] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[174156fd] | 30 | /** @addtogroup kernel_generic_ipc
|
---|
[f0defd2] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <ipc/sysipc_ops.h>
|
---|
[e8039a86] | 37 | #include <ipc/ipc.h>
|
---|
| 38 | #include <ipc/ipcrsc.h>
|
---|
| 39 | #include <abi/errno.h>
|
---|
| 40 | #include <arch.h>
|
---|
[f0defd2] | 41 |
|
---|
[b7fd2a0] | 42 | static errno_t request_preprocess(call_t *call, phone_t *phone)
|
---|
[e8039a86] | 43 | {
|
---|
[334c103] | 44 | /*
|
---|
| 45 | * Create the new phone and capability, but don't publish them yet.
|
---|
| 46 | * That will be done once the phone is connected.
|
---|
| 47 | */
|
---|
[6769005] | 48 | cap_phone_handle_t phandle;
|
---|
| 49 | kobject_t *pobj;
|
---|
| 50 | errno_t rc = phone_alloc(TASK, false, &phandle, &pobj);
|
---|
[09d01f2] | 51 | if (rc != EOK) {
|
---|
[6769005] | 52 | call->priv = 0;
|
---|
[09d01f2] | 53 | return rc;
|
---|
| 54 | }
|
---|
[48bcf49] | 55 |
|
---|
[6769005] | 56 | /* Move pobj's reference to call->priv */
|
---|
| 57 | call->priv = (sysarg_t) pobj;
|
---|
| 58 | pobj = NULL;
|
---|
[e8039a86] | 59 |
|
---|
[50dd854] | 60 | /* Remember the handle */
|
---|
[fafb8e5] | 61 | ipc_set_arg5(&call->data, (sysarg_t) phandle);
|
---|
[50dd854] | 62 |
|
---|
[e8039a86] | 63 | return EOK;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[b7fd2a0] | 66 | static errno_t request_forget(call_t *call)
|
---|
[b1e6269] | 67 | {
|
---|
[fafb8e5] | 68 | cap_phone_handle_t phandle = (cap_handle_t) ipc_get_arg5(&call->data);
|
---|
[09d01f2] | 69 |
|
---|
[bb97118] | 70 | if (cap_handle_raw(phandle) < 0)
|
---|
[09d01f2] | 71 | return EOK;
|
---|
| 72 |
|
---|
[6769005] | 73 | /* Move reference from call->priv to pobj */
|
---|
| 74 | kobject_t *pobj = (kobject_t *) call->priv;
|
---|
| 75 | call->priv = 0;
|
---|
| 76 | /* Drop pobj's reference */
|
---|
| 77 | kobject_put(pobj);
|
---|
| 78 | cap_free(TASK, phandle);
|
---|
[50dd854] | 79 |
|
---|
[466e95f7] | 80 | return EOK;
|
---|
[b1e6269] | 81 | }
|
---|
| 82 |
|
---|
[b7fd2a0] | 83 | static errno_t answer_preprocess(call_t *answer, ipc_data_t *olddata)
|
---|
[e8039a86] | 84 | {
|
---|
[6769005] | 85 | /* Get an extra reference for phone */
|
---|
| 86 | kobject_t *pobj = (kobject_t *) answer->priv;
|
---|
| 87 | kobject_add_ref(pobj);
|
---|
[e8039a86] | 88 |
|
---|
[6769005] | 89 | /* Set the recipient-assigned label */
|
---|
[fafb8e5] | 90 | pobj->phone->label = ipc_get_arg5(&answer->data);
|
---|
[6769005] | 91 |
|
---|
| 92 | /* Restore phone handle in answer's ARG5 */
|
---|
[fafb8e5] | 93 | ipc_set_arg5(&answer->data, ipc_get_arg5(olddata));
|
---|
[50dd854] | 94 |
|
---|
| 95 | /* If the user accepted the call, connect */
|
---|
[fafb8e5] | 96 | if (ipc_get_retval(&answer->data) == EOK) {
|
---|
[6769005] | 97 | /* Hand over reference from pobj to the answerbox */
|
---|
| 98 | (void) ipc_phone_connect(pobj->phone, &TASK->answerbox);
|
---|
[48bcf49] | 99 | } else {
|
---|
[6769005] | 100 | /* Drop the extra reference */
|
---|
| 101 | kobject_put(pobj);
|
---|
[48bcf49] | 102 | }
|
---|
[e8039a86] | 103 |
|
---|
| 104 | return EOK;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[b7fd2a0] | 107 | static errno_t answer_process(call_t *answer)
|
---|
[1b186ed] | 108 | {
|
---|
[fafb8e5] | 109 | cap_phone_handle_t phandle = (cap_handle_t) ipc_get_arg5(&answer->data);
|
---|
[6769005] | 110 | /* Move the reference from answer->priv to pobj */
|
---|
| 111 | kobject_t *pobj = (kobject_t *) answer->priv;
|
---|
| 112 | answer->priv = 0;
|
---|
[022d72ff] | 113 |
|
---|
[fafb8e5] | 114 | if (ipc_get_retval(&answer->data)) {
|
---|
[bb97118] | 115 | if (cap_handle_raw(phandle) >= 0) {
|
---|
[022d72ff] | 116 | /*
|
---|
[50dd854] | 117 | * Cleanup the unpublished capability and drop
|
---|
| 118 | * phone->kobject's reference.
|
---|
[022d72ff] | 119 | */
|
---|
[6769005] | 120 | kobject_put(pobj);
|
---|
| 121 | cap_free(TASK, phandle);
|
---|
[022d72ff] | 122 | }
|
---|
[eab9689] | 123 | } else {
|
---|
[50dd854] | 124 | /*
|
---|
| 125 | * Publish the capability. Publishing the capability this late
|
---|
| 126 | * is important for ipc_cleanup() where we want to have a
|
---|
| 127 | * capability for each phone that wasn't hung up by the user.
|
---|
| 128 | */
|
---|
[6769005] | 129 | cap_publish(TASK, phandle, pobj);
|
---|
[eab9689] | 130 | }
|
---|
[a35b458] | 131 |
|
---|
[1b186ed] | 132 | return EOK;
|
---|
| 133 | }
|
---|
[e8039a86] | 134 |
|
---|
| 135 | sysipc_ops_t ipc_m_connect_me_to_ops = {
|
---|
| 136 | .request_preprocess = request_preprocess,
|
---|
[b1e6269] | 137 | .request_forget = request_forget,
|
---|
[f0defd2] | 138 | .request_process = null_request_process,
|
---|
[b1e6269] | 139 | .answer_cleanup = null_answer_cleanup,
|
---|
[e8039a86] | 140 | .answer_preprocess = answer_preprocess,
|
---|
[1b186ed] | 141 | .answer_process = answer_process,
|
---|
[f0defd2] | 142 | };
|
---|
| 143 |
|
---|
| 144 | /** @}
|
---|
| 145 | */
|
---|