aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/ipc.c
blob: e25ba7e711e3ae73e6621b0368b00e02779b09c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
 * This file is part of libsamsung-ipc.
 *
 * Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
 *
 * libsamsung-ipc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * libsamsung-ipc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with libsamsung-ipc.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <radio.h>

#include "ipc_private.h"

struct ipc_ops *ops = NULL;

extern struct ipc_ops crespo_ipc_ops;
extern struct ipc_ops h1_ipc_ops;

int ipc_init(int client_type)
{
    int rc = 0;

    switch (client_type)
    {
        case IPC_CLIENT_TYPE_CRESPO:
            ops = &crespo_ipc_ops;
            break;
        case IPC_CLIENT_TYPE_H1:
            ops = &h1_ipc_ops;
            break;
        default:
            rc = -1;
            break;
    }

    return rc;
}

int ipc_open(void)
{
    return ops != NULL && ops->open != NULL ? ops->open() : -1;
}

int ipc_close(void)
{
    return ops != NULL && ops->close != NULL ? ops->close() : -1;
}

void ipc_power_on(void)
{
    if (ops != NULL && ops->power_on != NULL)
        ops->power_on();
}

void ipc_power_off(void)
{
    if (ops != NULL && ops->power_off != NULL)
        ops->power_off();
}

void ipc_send(struct ipc_request *request)
{
    if (ops != NULL && ops->send != NULL)
        ops->send(request);
}

/* Convenience functions for ipc_send */
inline void ipc_msg_send_get(const int command, unsigned char aseq)
{
	ipc_msg_send(command, IPC_TYPE_GET, 0, 0, aseq);
}

inline void ipc_msg_send_exec(const int command, unsigned char aseq)
{
	ipc_msg_send(command, IPC_TYPE_EXEC, 0, 0, aseq);
}

/* Wrapper for ipc_send */
void ipc_msg_send(const int command, const int type, unsigned char *data, const int length, unsigned char mseq)
{
	struct ipc_request request;

	request.mseq = mseq;
	request.aseq = 0xff;
	request.group = IPC_GROUP(command);
	request.index = IPC_INDEX(command);
	request.type = type;
	request.length = length;
	request.data = data;

    ipc_send(&request);
}

int ipc_recv(struct ipc_response *response)
{
    return ops != NULL && ops->recv != NULL ? ops->recv(response) : -1;
}