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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/**
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2010-2011 Joerie de Gram <j.de.gram@gmail.com>
* 2011 Simon Busch <morphis@gravedo.de>
*
* 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 <unistd.h>
#include <stdint.h>
#include <stdbool.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pthread.h>
#include <radio.h>
#include <crespo_ipc.h>
#define RC_CHECK printf("line %d, rc = %d\n", __LINE__, rc);
void print_help()
{
printf("usage: modemctrl <command>\n");
printf("commands:\n");
printf("\tbootstrap bootstrap modem to be ready for processing\n");
printf("\tpower-on power on the modem\n");
printf("\tpower-off power off the modem\n");
}
int crespo_read_loop(struct ipc_client *client)
{
struct ipc_response resp;
void *io_data = NULL;
int fd = -1;
fd_set fds;
io_data = ipc_client_get_handlers_io_data(client);
fd = *((int *) io_data);
if(fd < 0) {
return -1;
}
memset(&resp, 0, sizeof(resp));
FD_ZERO(&fds);
FD_SET(fd, &fds);
while(1) {
usleep(3000);
select(fd + 1, &fds, NULL, NULL, NULL);
if(FD_ISSET(fd, &fds))
{
ipc_client_recv(client, &resp);
if(resp.data != NULL)
free(resp.data);
}
}
}
int modem_start(struct ipc_client *client)
{
int rc;
ipc_client_set_handlers(client, &ipc_default_handlers);
ipc_client_bootstrap_modem(client);
rc = ipc_client_power_on(client);
if(rc < 0)
return -1;
rc = ipc_client_open(client);
if(rc < 0)
return -1;
return 0;
}
int modem_stop(struct ipc_client *client)
{
ipc_client_close(client);
ipc_client_power_off(client);
return 0;
}
int main(int argc, char *argv[])
{
struct ipc_client *crespo_fmt_client;
struct ipc_client *crespo_rfs_client;
int rc;
if (argc != 2) {
print_help();
exit(1);
}
crespo_fmt_client = ipc_client_new(IPC_CLIENT_TYPE_FMT);
crespo_rfs_client = ipc_client_new(IPC_CLIENT_TYPE_RFS);
if (!strncmp(argv[1], "power-on", sizeof("power-on"))) {
ipc_client_power_on(crespo_fmt_client);
}
else if (!strncmp(argv[1], "power-off", sizeof("power-off"))) {
ipc_client_power_off(crespo_fmt_client);
}
else if (!strncmp(argv[1], "stop-all", 8)) {
ipc_client_close(crespo_fmt_client);
ipc_client_close(crespo_rfs_client);
ipc_client_power_off(crespo_fmt_client);
}
else if (!strncmp(argv[1], "start-fmt", 9)) {
printf("Starting modem on FMT client\n");
rc = modem_start(crespo_fmt_client);
if(rc < 0) {
printf("Somethign went wrong\n");
modem_stop(crespo_fmt_client);
return 1;
}
printf("Starting crespo_read_loop on FMT client\n");
crespo_read_loop(crespo_fmt_client);
modem_stop(crespo_fmt_client);
}
else if (!strncmp(argv[1], "start-rfs", 9)) {
printf("Starting modem on RFS client\n");
rc = modem_start(crespo_rfs_client);
if(rc < 0) {
printf("Somethign went wrong\n");
modem_stop(crespo_rfs_client);
return 1;
}
printf("Starting crespo_read_loop on RFS client\n");
crespo_read_loop(crespo_rfs_client);
modem_stop(crespo_rfs_client);
}
else {
printf("Unknown command!\n");
}
ipc_client_free(crespo_fmt_client);
ipc_client_free(crespo_rfs_client);
return 0;
}
|