1/*
2 * Copyright 2016, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(D61_BSD)
11 */
12
13#include "dispatch.h"
14#include "serv_dispatch.h"
15#include "../badge.h"
16#include <refos/error.h>
17#include <refos-rpc/serv_server.h>
18
19/*! @file
20    @brief Handles server connection and session establishment syscalls.
21
22    This file contains the handlers for serv interface syscalls. It should implement the
23    declarations in the generated <refos-rpc/serv_server.h>.
24*/
25
26seL4_CPtr
27serv_connect_direct_handler(void *rpc_userptr , seL4_CPtr rpc_liveness , int* rpc_errno)
28{
29    struct srv_client *anonc = (struct srv_client *) rpc_userptr;
30    srv_msg_t *m = (srv_msg_t *) anonc->rpcClient.userptr;
31    assert(anonc->magic == FS_DISPATCH_ANON_CLIENT_MAGIC);
32    struct srv_client *c = fileServCommon->ctable_connect_direct_handler(
33            fileServCommon, m, rpc_liveness, rpc_errno);
34    return c ? c->session : (seL4_CPtr) 0;
35}
36
37refos_err_t
38serv_ping_handler(void *rpc_userptr)
39{
40    dprintf(COLOUR_M "FILE SERVER RECIEVED PING!!! HI THERE! (������������������� ���������\n" COLOUR_RESET);
41    return ESUCCESS;
42}
43
44refos_err_t
45serv_set_param_buffer_handler(void *rpc_userptr , seL4_CPtr rpc_parambuffer_dataspace ,
46                              uint32_t rpc_parambuffer_size)
47{
48    struct srv_client *c = (struct srv_client *) rpc_userptr;
49    srv_msg_t *m = (srv_msg_t *) c->rpcClient.userptr;
50    assert(c->magic == FS_CLIENT_MAGIC);
51    return fileServCommon->ctable_set_param_buffer_handler(fileServCommon, c, m,
52        rpc_parambuffer_dataspace, rpc_parambuffer_size);
53}
54
55void
56serv_disconnect_direct_handler(void *rpc_userptr)
57{
58    struct srv_client *c = (struct srv_client *) rpc_userptr;
59    assert(c->magic == FS_CLIENT_MAGIC);
60    dprintf("Fileserver disconnecting client cID = %d. Bye! (D:)\n", c->cID);
61    return fileServCommon->ctable_disconnect_direct_handler(fileServCommon, c);
62}
63
64int
65check_dispatch_serv(srv_msg_t *m, void **userptr)
66{
67    int label = seL4_GetMR(0);
68    if (label == RPC_SERV_CONNECT_DIRECT && m->badge != SRV_UNBADGED) {
69        return DISPATCH_PASS;
70    }
71    return check_dispatch_interface(m, userptr, RPC_SERV_LABEL_MIN, RPC_SERV_LABEL_MAX);
72}