Exemple #1
0
psa_status_t psa_mac_abort(psa_mac_operation_t *operation)
{
    if (operation->handle <= PSA_NULL_HANDLE) {
        return (PSA_SUCCESS);
    }

    psa_crypto_ipc_t psa_crypto_ipc = {
        .func   = PSA_MAC_ABORT,
        .handle = 0,
        .alg    = 0
    };

    psa_invec in_vec = { &psa_crypto_ipc, sizeof(psa_crypto_ipc) };

    psa_status_t status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, true);
    return (status);
}

static psa_status_t psa_mac_setup(psa_mac_operation_t *operation,
                                  psa_key_handle_t key_handle,
                                  psa_algorithm_t alg,
                                  psa_sec_function_t func)
{
    if (operation->handle != PSA_NULL_HANDLE) {
        return (PSA_ERROR_BAD_STATE);
    }

    psa_crypto_ipc_t psa_crypto_ipc = {
        .func   = func,
        .handle = key_handle,
        .alg    = alg
    };

    psa_invec in_vec = { &psa_crypto_ipc, sizeof(psa_crypto_ipc) };

    psa_status_t status = ipc_connect(PSA_MAC_ID, &operation->handle);
    if (status != PSA_SUCCESS) {
        return (status);
    }
    status = ipc_call(&operation->handle, &in_vec, 1, NULL, 0, false);
    if (status != PSA_SUCCESS) {
        ipc_close(&operation->handle);
    }
    return (status);
}

psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
                                psa_key_handle_t key_handle,
                                psa_algorithm_t alg)
{
    psa_status_t status = psa_mac_setup(operation, key_handle, alg, PSA_MAC_SIGN_SETUP);
    return (status);
}
Exemple #2
0
/** Make an asynchronous IPC call allowing to transmit the entire payload.
 *
 * @param phoneid Phone handle for the call.
 * @param data    Userspace address of call data with the request.
 *
 * @return See sys_ipc_call_async_fast().
 *
 */
sysarg_t sys_ipc_call_async_slow(sysarg_t phoneid, ipc_data_t *data)
{
	phone_t *phone;
	if (phone_get(phoneid, &phone) != EOK)
		return IPC_CALLRET_FATAL;

	if (check_call_limit(phone))
		return IPC_CALLRET_TEMPORARY;

	call_t *call = ipc_call_alloc(0);
	int rc = copy_from_uspace(&call->data.args, &data->args,
	    sizeof(call->data.args));
	if (rc != 0) {
		ipc_call_free(call);
		return (sysarg_t) rc;
	}
	
	int res = request_preprocess(call, phone);
	
	if (!res)
		ipc_call(phone, call);
	else
		ipc_backsend_err(phone, call, res);
	
	return (sysarg_t) call;
}
Exemple #3
0
/** Make a fast asynchronous call over IPC.
 *
 * This function can only handle four arguments of payload, but is faster than
 * the generic function sys_ipc_call_async_slow().
 *
 * @param phoneid Phone handle for the call.
 * @param imethod Interface and method of the call.
 * @param arg1    Service-defined payload argument.
 * @param arg2    Service-defined payload argument.
 * @param arg3    Service-defined payload argument.
 * @param arg4    Service-defined payload argument.
 *
 * @return Call hash on success.
 * @return IPC_CALLRET_FATAL in case of a fatal error.
 * @return IPC_CALLRET_TEMPORARY if there are too many pending
 *         asynchronous requests; answers should be handled first.
 *
 */
sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
{
	phone_t *phone;
	if (phone_get(phoneid, &phone) != EOK)
		return IPC_CALLRET_FATAL;
	
	if (check_call_limit(phone))
		return IPC_CALLRET_TEMPORARY;
	
	call_t *call = ipc_call_alloc(0);
	IPC_SET_IMETHOD(call->data, imethod);
	IPC_SET_ARG1(call->data, arg1);
	IPC_SET_ARG2(call->data, arg2);
	IPC_SET_ARG3(call->data, arg3);
	IPC_SET_ARG4(call->data, arg4);
	
	/*
	 * To achieve deterministic behavior, zero out arguments that are beyond
	 * the limits of the fast version.
	 */
	IPC_SET_ARG5(call->data, 0);
	
	int res = request_preprocess(call, phone);
	
	if (!res)
		ipc_call(phone, call);
	else
		ipc_backsend_err(phone, call, res);
	
	return (sysarg_t) call;
}
Exemple #4
0
static psa_status_t ipc_oneshot(uint32_t sid, psa_invec *in_vec, size_t in_vec_size,
                                psa_outvec *out_vec, size_t out_vec_size)
{
    psa_handle_t handle = PSA_NULL_HANDLE;
    psa_status_t status = ipc_connect(sid, &handle);
    if (status != PSA_SUCCESS) {
        return status;
    }
    status = ipc_call(&handle, in_vec, in_vec_size, out_vec, out_vec_size, true);
    return (status);
}
Exemple #5
0
/** Forwards call from one answerbox to another one.
 *
 * @param call     Call structure to be redirected.
 * @param newphone Phone structure to target answerbox.
 * @param oldbox   Old answerbox structure.
 * @param mode     Flags that specify mode of the forward operation.
 *
 * @return 0 if forwarding succeeded or an error code if
 *         there was an error.
 *
 * The return value serves only as an information for the forwarder,
 * the original caller is notified automatically with EFORWARD.
 *
 */
int ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox,
    unsigned int mode)
{
	/* Count forwarded calls */
	irq_spinlock_lock(&TASK->lock, true);
	TASK->ipc_info.forwarded++;
	irq_spinlock_pass(&TASK->lock, &oldbox->lock);
	list_remove(&call->ab_link);
	irq_spinlock_unlock(&oldbox->lock, true);
	
	if (mode & IPC_FF_ROUTE_FROM_ME) {
		call->data.phone = newphone;
		call->data.task_id = TASK->taskid;
	}
	
	return ipc_call(newphone, call);
}
Exemple #6
0
int foo()
{
    struct calc_args calc;
    calc.left = 123;
    calc.right = 321;
    calc.opcode = '+';
    int ret;
    logi("calc string=\"%d %c %d\"\n", calc.left, calc.opcode, calc.right);
    struct ipc *ipc = ipc_create(IPC_CLIENT, 5555);
    logi("before ipc_call\n");
    if (0 != ipc_call(ipc, IPC_CALC, &calc, sizeof(calc), &ret, sizeof(ret))) {
        loge("ipc_call %d failed!\n", IPC_CALC);
        return -1;
    }
    logi("ipc_call IPC_CALC success!\n");
    logi("return value = %d\n", ret);
    ipc_destroy(ipc);
    return 0;
}
Exemple #7
0
int shell_test()
{
    char buf[1024];
    char cmd[512];
    int loop = 1;
    struct ipc *ipc = ipc_create(IPC_CLIENT, 5555);
    if (!ipc) {
        loge("ipc_create failed!\n");
        return -1;
    }
    while (loop) {
        memset(buf, 0, sizeof(buf));
        printf("hack shell$ ");
        scanf("%s", cmd);
        printf("cmd = %s\n", cmd);
        ipc_call(ipc, IPC_SHELL_HELP, cmd, sizeof(cmd), buf, sizeof(buf));
        printf("ret = %s\n", buf);
    }
    ipc_destroy(ipc);
    return 0;

}
Exemple #8
0
psa_status_t psa_mac_update(psa_mac_operation_t *operation,
                            const uint8_t *input,
                            size_t input_length)
{
    psa_crypto_ipc_t psa_crypto_ipc = {
        .func   = PSA_MAC_UPDATE,
        .handle = 0,
        .alg    = 0
    };

    psa_invec in_vec[2] = {
        { &psa_crypto_ipc, sizeof(psa_crypto_ipc) },
        { input, input_length }
    };

    psa_status_t status = ipc_call(&operation->handle, in_vec, 2, NULL, 0, false);
    if (status != PSA_SUCCESS) {
        ipc_close(&operation->handle);
    }
    return (status);
}

psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation,
                                 uint8_t *mac,
                                 size_t mac_size,
                                 size_t *mac_length)
{
    psa_crypto_ipc_t psa_crypto_ipc = {
        .func   = PSA_MAC_SIGN_FINISH,
        .handle = 0,
        .alg    = 0