forked from lecotex/vtuner.apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtuner-network.c
396 lines (374 loc) · 16.7 KB
/
vtuner-network.c
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#include "vtuner-network.h"
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <arpa/inet.h>
#define NTOHB(host,net,field) host->field=net.field
#define NTOHS(host,net,field) host->field=ntohs(net.field)
#define NTOHL(host,net,field) host->field=ntohl(net.field)
#define HTONB(net, host, field) net.field=host->field
#define HTONS(net, host, field) net.field=htons(host->field);
#define HTONL(net, host, field) net.field=htonl(host->field);
#define HTONLc(net,field) net.field=htonl(net.field)
#define HTONSc(net,field) net.field=htons(net.field)
#define NTOHLc(net,field) net.field=ntohl(net.field)
#define NTOHSc(net,field) net.field=ntohs(net.field)
#if HAVE_DVB_API_VERSION < 3
void get_dvb_frontend_parameters( FrontendParameters* hfe, vtuner_message_t* netmsg, vtuner_type_t type) {
memset(hfe, 0, sizeof(hfe));
hfe->Frequency = netmsg->body.fe_params.frequency;
hfe->Inversion = netmsg->body.fe_params.inversion;
switch(type) {
case VT_S :
case VT_S2:
hfe->u.qpsk.SymbolRate = netmsg->body.fe_params.u.qpsk.symbol_rate;
switch(netmsg->body.fe_params.u.qpsk.fec_inner) {
case 0: hfe->u.qpsk.FEC_inner = FEC_NONE; break;
case 1: hfe->u.qpsk.FEC_inner = FEC_1_2; break;
case 2: hfe->u.qpsk.FEC_inner = FEC_2_3; break;
case 3: hfe->u.qpsk.FEC_inner = FEC_3_4; break;
case 5: hfe->u.qpsk.FEC_inner = FEC_5_6; break;
case 7: hfe->u.qpsk.FEC_inner = FEC_7_8; break;
default: hfe->u.qpsk.FEC_inner = FEC_AUTO; break;
}
break;
case VT_C:
hfe->u.qam.SymbolRate = netmsg->body.fe_params.u.qam.symbol_rate;
switch(netmsg->body.fe_params.u.qam.fec_inner) {
case 0: hfe->u.qam.FEC_inner = FEC_NONE; break;
case 1: hfe->u.qam.FEC_inner = FEC_1_2; break;
case 2: hfe->u.qam.FEC_inner = FEC_2_3; break;
case 3: hfe->u.qam.FEC_inner = FEC_3_4; break;
case 5: hfe->u.qam.FEC_inner = FEC_5_6; break;
case 7: hfe->u.qam.FEC_inner = FEC_7_8; break;
default: hfe->u.qam.FEC_inner = FEC_AUTO; break;
}
hfe->u.qam.QAM = netmsg->body.fe_params.u.qam.modulation;
break;
case VT_T:
hfe->u.ofdm.bandWidth = netmsg->body.fe_params.u.ofdm.bandwidth;
hfe->u.ofdm.HP_CodeRate = netmsg->body.fe_params.u.ofdm.code_rate_HP;
hfe->u.ofdm.LP_CodeRate = netmsg->body.fe_params.u.ofdm.code_rate_LP;
hfe->u.ofdm.Constellation = netmsg->body.fe_params.u.ofdm.constellation;
hfe->u.ofdm.TransmissionMode = netmsg->body.fe_params.u.ofdm.transmission_mode;
hfe->u.ofdm.guardInterval = netmsg->body.fe_params.u.ofdm.guard_interval;
hfe->u.ofdm.HierarchyInformation = netmsg->body.fe_params.u.ofdm.hierarchy_information;
break;
case VT_A:
//hfe->u.atsc.vsb = netmsg->body.fe_params.u.vsb.modulation;
hfe->u.vsb.modulation = netmsg->body.fe_params.u.vsb.modulation;
break;
}
}
void set_dvb_frontend_parameters( vtuner_message_t* netmsg, FrontendParameters* hfe, vtuner_type_t type) {
netmsg->body.fe_params.frequency = hfe->Frequency;
netmsg->body.fe_params.inversion = hfe->Inversion;
switch(type) {
case VT_S :
case VT_S2:
netmsg->body.fe_params.u.qpsk.symbol_rate = hfe->u.qpsk.SymbolRate;
switch(hfe->u.qpsk.FEC_inner) {
case FEC_NONE: netmsg->body.fe_params.u.qpsk.fec_inner = 0; break;
case FEC_1_2: netmsg->body.fe_params.u.qpsk.fec_inner = 1; break;
case FEC_2_3: netmsg->body.fe_params.u.qpsk.fec_inner = 2; break;
case FEC_3_4: netmsg->body.fe_params.u.qpsk.fec_inner = 3; break;
case FEC_5_6: netmsg->body.fe_params.u.qpsk.fec_inner = 5; break;
case FEC_7_8: netmsg->body.fe_params.u.qpsk.fec_inner = 7; break;
default: netmsg->body.fe_params.u.qpsk.fec_inner = FEC_AUTO; break;
}
break;
case VT_C:
netmsg->body.fe_params.u.qam.symbol_rate = hfe->u.qam.SymbolRate;
switch(hfe->u.qam.FEC_inner) {
case FEC_NONE: netmsg->body.fe_params.u.qam.fec_inner = 0; break;
case FEC_1_2: netmsg->body.fe_params.u.qam.fec_inner = 1; break;
case FEC_2_3: netmsg->body.fe_params.u.qam.fec_inner = 2; break;
case FEC_3_4: netmsg->body.fe_params.u.qam.fec_inner = 3; break;
case FEC_5_6: netmsg->body.fe_params.u.qam.fec_inner = 5; break;
case FEC_7_8: netmsg->body.fe_params.u.qam.fec_inner = 7; break;
default: netmsg->body.fe_params.u.qam.fec_inner = FEC_AUTO; break;
}
netmsg->body.fe_params.u.qam.modulation = hfe->u.qam.QAM;
break;
case VT_T:
netmsg->body.fe_params.u.ofdm.bandwidth = hfe->u.ofdm.bandWidth;
netmsg->body.fe_params.u.ofdm.code_rate_HP = hfe->u.ofdm.HP_CodeRate;
netmsg->body.fe_params.u.ofdm.code_rate_LP = hfe->u.ofdm.LP_CodeRate;
netmsg->body.fe_params.u.ofdm.constellation = hfe->u.ofdm.Constellation;
netmsg->body.fe_params.u.ofdm.transmission_mode = hfe->u.ofdm.TransmissionMode;
netmsg->body.fe_params.u.ofdm.guard_interval = hfe->u.ofdm.guardInterval;
netmsg->body.fe_params.u.ofdm.hierarchy_information = hfe->u.ofdm.HierarchyInformation;
break;
case VT_A:
netmsg->body.fe_params.u.vsb.modulation = hfe->u.vsb.VSB_8;
break;
}
}
#else
void get_dvb_frontend_parameters(struct dvb_frontend_parameters* hfe, vtuner_message_t* netmsg, vtuner_type_t type) {
memset(hfe, 0, sizeof(hfe));
hfe->frequency = netmsg->body.fe_params.frequency;
hfe->inversion = netmsg->body.fe_params.inversion;
switch (type) {
case VT_S :
case VT_S2:
hfe->u.qpsk.symbol_rate = netmsg->body.fe_params.u.qpsk.symbol_rate;
hfe->u.qpsk.fec_inner = netmsg->body.fe_params.u.qpsk.fec_inner;
break;
case VT_C:
hfe->u.qam.symbol_rate = netmsg->body.fe_params.u.qam.symbol_rate;
hfe->u.qam.fec_inner = netmsg->body.fe_params.u.qam.fec_inner;
hfe->u.qam.modulation = netmsg->body.fe_params.u.qam.modulation;
break;
case VT_T:
hfe->u.ofdm.bandwidth = netmsg->body.fe_params.u.ofdm.bandwidth;
hfe->u.ofdm.code_rate_HP = netmsg->body.fe_params.u.ofdm.code_rate_HP;
hfe->u.ofdm.code_rate_LP = netmsg->body.fe_params.u.ofdm.code_rate_LP;
hfe->u.ofdm.constellation = netmsg->body.fe_params.u.ofdm.constellation;
hfe->u.ofdm.transmission_mode = netmsg->body.fe_params.u.ofdm.transmission_mode;
hfe->u.ofdm.guard_interval = netmsg->body.fe_params.u.ofdm.guard_interval;
hfe->u.ofdm.hierarchy_information = netmsg->body.fe_params.u.ofdm.hierarchy_information;
break;
case VT_A:
hfe->u.vsb.modulation = netmsg->body.fe_params.u.vsb.modulation;
}
}
void set_dvb_frontend_parameters( vtuner_message_t* netmsg, struct dvb_frontend_parameters* hfe, vtuner_type_t type) {
netmsg->body.fe_params.frequency = hfe->frequency;
netmsg->body.fe_params.inversion = hfe->inversion;
switch (type) {
case VT_S :
case VT_S2:
netmsg->body.fe_params.u.qpsk.symbol_rate = hfe->u.qpsk.symbol_rate;
netmsg->body.fe_params.u.qpsk.fec_inner = hfe->u.qpsk.fec_inner;
break;
case VT_C:
netmsg->body.fe_params.u.qam.symbol_rate = hfe->u.qam.symbol_rate;
netmsg->body.fe_params.u.qam.fec_inner = hfe->u.qam.fec_inner;
netmsg->body.fe_params.u.qam.modulation = hfe->u.qam.modulation;
break;
case VT_T:
netmsg->body.fe_params.u.ofdm.bandwidth = hfe->u.ofdm.bandwidth;
netmsg->body.fe_params.u.ofdm.code_rate_HP = hfe->u.ofdm.code_rate_HP;
netmsg->body.fe_params.u.ofdm.code_rate_LP = hfe->u.ofdm.code_rate_LP;
netmsg->body.fe_params.u.ofdm.constellation = hfe->u.ofdm.constellation;
netmsg->body.fe_params.u.ofdm.transmission_mode = hfe->u.ofdm.transmission_mode;
netmsg->body.fe_params.u.ofdm.guard_interval = hfe->u.ofdm.guard_interval;
netmsg->body.fe_params.u.ofdm.hierarchy_information = hfe->u.ofdm.hierarchy_information;
break;
case VT_A:
netmsg->body.fe_params.u.vsb.modulation = hfe->u.vsb.modulation;
}
}
#endif
int ntoh_get_message_type( vtuner_net_message_t* netmsg ) {
int hmsgtype = ntohs(netmsg->msg_type);
return hmsgtype;
}
void hton_vtuner_net_message(vtuner_net_message_t* netmsg, vtuner_type_t type) {
DEBUGNET(" v%d/%x %d %d", netmsg->ver, netmsg->cap, netmsg->msg_type, netmsg->u.vtuner.type );
switch (netmsg->msg_type) {
case MSG_GET_FRONTEND:
case MSG_SET_FRONTEND:
DEBUGNETC(" %d %d %d %d", netmsg->u.vtuner.body.fe_params.frequency, netmsg->u.vtuner.body.fe_params.inversion, netmsg->u.vtuner.body.fe_params.u.qpsk.symbol_rate, netmsg->u.vtuner.body.fe_params.u.qpsk.fec_inner);
HTONLc(netmsg->u.vtuner.body.fe_params, frequency);
switch (type) {
case VT_S :
case VT_S2:
case VT_S|VT_S2:
DEBUGNETC(" VT_S/VT_S2");
HTONLc( netmsg->u.vtuner.body.fe_params, u.qpsk.symbol_rate);
HTONLc( netmsg->u.vtuner.body.fe_params, u.qpsk.fec_inner);
break;
case VT_C:
DEBUGNETC(" VT_C");
HTONLc( netmsg->u.vtuner.body.fe_params, u.qam.symbol_rate);
HTONLc( netmsg->u.vtuner.body.fe_params, u.qam.fec_inner);
HTONLc( netmsg->u.vtuner.body.fe_params, u.qam.modulation);
break;
case VT_T:
DEBUGNETC(" VT_T");
HTONLc( netmsg->u.vtuner.body.fe_params, u.ofdm.bandwidth);
HTONLc( netmsg->u.vtuner.body.fe_params, u.ofdm.code_rate_HP);
HTONLc( netmsg->u.vtuner.body.fe_params, u.ofdm.code_rate_LP);
HTONLc( netmsg->u.vtuner.body.fe_params, u.ofdm.constellation);
HTONLc( netmsg->u.vtuner.body.fe_params, u.ofdm.transmission_mode);
HTONLc( netmsg->u.vtuner.body.fe_params, u.ofdm.guard_interval);
HTONLc( netmsg->u.vtuner.body.fe_params, u.ofdm.hierarchy_information);
break;
case VT_A:
DEBUGNETC(" VT_A");
HTONLc( netmsg->u.vtuner.body.fe_params, u.vsb.modulation);
break;
default:
WARN(MSG_NET, "unkown frontend type %d (known types are %d,%d,%d,%d)\n",type,VT_S,VT_C,VT_T,VT_S2,VT_A);
};
break;
case MSG_READ_STATUS:
HTONLc( netmsg->u.vtuner.body, status);
DEBUGNETC(" %d", netmsg->u.vtuner.body.status);
break;
case MSG_READ_BER:
DEBUGNETC(" %d", netmsg->u.vtuner.body.ber);
HTONLc( netmsg->u.vtuner.body, ber);
break;
case MSG_READ_SIGNAL_STRENGTH:
DEBUGNETC(" %d", netmsg->u.vtuner.body.ss);
HTONSc( netmsg->u.vtuner.body, ss);
break;
case MSG_READ_SNR:
DEBUGNETC(" %d", netmsg->u.vtuner.body.snr);
HTONSc( netmsg->u.vtuner.body, snr);
break;
case MSG_READ_UCBLOCKS:
DEBUGNETC(" %d", netmsg->u.vtuner.body.ucb);
HTONLc( netmsg->u.vtuner.body, ucb);
break;
case MSG_SET_PROPERTY:
case MSG_GET_PROPERTY:
HTONLc( netmsg->u.vtuner.body, prop.cmd );
HTONLc( netmsg->u.vtuner.body, prop.u.data );
break;
case MSG_PIDLIST: {
int i;
for(i=0; i<30; ++i) {
DEBUGNETC(" %d", netmsg->u.vtuner.body.pidlist[i]);
HTONSc( netmsg->u.vtuner.body, pidlist[i]);
}
break;
case MSG_DISCOVER:
// DEBUGNETC(" %d %d %d %d", netmsg->u.discover.port, netmsg->u.discover.fe_info.type, netmsg->u.discover.fe_info.frequency_min, netmsg->u.discover.fe_info.frequency_max);
HTONSc( netmsg->u.discover, tuner_group);
HTONSc( netmsg->u.discover, port);
HTONSc( netmsg->u.discover, tsdata_port);
HTONLc( netmsg->u.discover, vtype);
break;
case MSG_UPDATE:
HTONLc( netmsg->u.update, status);
HTONLc( netmsg->u.update, ber);
HTONLc( netmsg->u.update, ucb);
HTONSc( netmsg->u.update, ss);
HTONSc( netmsg->u.update, snr);
break;
default:
if(netmsg->msg_type < 1 || (netmsg->msg_type > MSG_GET_PROPERTY && netmsg->msg_type < MSG_NULL ) || netmsg->msg_type > MSG_UPDATE)
WARN(MSG_NET, "unkown message type %d\n",netmsg->msg_type);
}
}
if(netmsg->msg_type < MSG_DISCOVER) HTONLc( netmsg->u.vtuner, type );
netmsg->msg_type = htons( netmsg->msg_type );
netmsg->ver = VTUNER_PROTO2;
DEBUGNETC(" %x %x\n", netmsg->msg_type, netmsg->u.vtuner.type);
#ifdef DEBUG_NET
print_vtuner_net_message(netmsg);
#endif
}
void ntoh_vtuner_net_message(vtuner_net_message_t* netmsg, vtuner_type_t type) {
#ifdef DEBUG_NET
print_vtuner_net_message(netmsg);
#endif
DEBUGNET(" v%d/%x %d %d", netmsg->ver, netmsg->cap, netmsg->msg_type, netmsg->u.vtuner.type );
netmsg->msg_type = ntohs( netmsg->msg_type );
if(netmsg->msg_type < MSG_DISCOVER) HTONLc( netmsg->u.vtuner, type );
netmsg->ver = VTUNER_PROTO2;
DEBUGNETC(" %d %d", netmsg->msg_type, netmsg->u.vtuner.type );
switch (netmsg->msg_type) {
case MSG_GET_FRONTEND:
case MSG_SET_FRONTEND:
NTOHLc( netmsg->u.vtuner.body.fe_params, frequency);
switch (type) {
case VT_S :
case VT_S2:
case VT_S|VT_S2:
DEBUGNETC(" VT_S/VT_S2");
NTOHLc( netmsg->u.vtuner.body.fe_params, u.qpsk.symbol_rate);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.qpsk.fec_inner);
break;
case VT_C:
DEBUGNETC(" VT_C");
NTOHLc( netmsg->u.vtuner.body.fe_params, u.qam.symbol_rate);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.qam.fec_inner);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.qam.modulation);
break;
case VT_T:
DEBUGNETC(" VT_T");
NTOHLc( netmsg->u.vtuner.body.fe_params, u.ofdm.bandwidth);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.ofdm.code_rate_HP);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.ofdm.code_rate_LP);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.ofdm.constellation);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.ofdm.transmission_mode);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.ofdm.guard_interval);
NTOHLc( netmsg->u.vtuner.body.fe_params, u.ofdm.hierarchy_information);
break;
case VT_A:
DEBUGNETC(" VT_A");
NTOHLc( netmsg->u.vtuner.body.fe_params, u.vsb.modulation);
break;
default:
WARN(MSG_NET, "unkown frontend type %d (known types are %d,%d,%d,%d)\n",type,VT_S,VT_C,VT_T,VT_S2,VT_A);
}
DEBUGNETC(" %d %d %d %d", netmsg->u.vtuner.body.fe_params.frequency, netmsg->u.vtuner.body.fe_params.inversion, netmsg->u.vtuner.body.fe_params.u.qpsk.symbol_rate, netmsg->u.vtuner.body.fe_params.u.qpsk.fec_inner);
break;
case MSG_READ_STATUS:
NTOHLc( netmsg->u.vtuner.body, status);
DEBUGNETC(" %d", netmsg->u.vtuner.body.status);
break;
case MSG_READ_BER:
NTOHLc( netmsg->u.vtuner.body, ber);
DEBUGNETC(" %d", netmsg->u.vtuner.body.ber);
break;
case MSG_READ_SIGNAL_STRENGTH:
NTOHSc( netmsg->u.vtuner.body, ss);
DEBUGNETC(" %d", netmsg->u.vtuner.body.ss);
break;
case MSG_READ_SNR:
NTOHSc( netmsg->u.vtuner.body, snr);
DEBUGNETC(" %d", netmsg->u.vtuner.body.snr);
break;
case MSG_READ_UCBLOCKS:
NTOHLc( netmsg->u.vtuner.body, ucb);
DEBUGNETC(" %d", netmsg->u.vtuner.body.ucb);
break;
case MSG_PIDLIST: {
int i;
for(i=0; i<30; ++i) {
NTOHSc( netmsg->u.vtuner.body, pidlist[i]);
DEBUGNETC(" %d", netmsg->u.vtuner.body.pidlist[i]);
}
break;
case MSG_SET_PROPERTY:
case MSG_GET_PROPERTY:
NTOHLc( netmsg->u.vtuner.body, prop.u.data );
NTOHLc( netmsg->u.vtuner.body, prop.cmd );
break;
case MSG_DISCOVER:
NTOHSc( netmsg->u.discover, tuner_group);
NTOHSc( netmsg->u.discover, port);
NTOHSc( netmsg->u.discover, tsdata_port);
NTOHLc( netmsg->u.discover, vtype);
break;
case MSG_UPDATE:
NTOHLc( netmsg->u.update, status);
NTOHLc( netmsg->u.update, ber);
NTOHLc( netmsg->u.update, ucb);
NTOHSc( netmsg->u.update, ss);
NTOHSc( netmsg->u.update, snr);
break;
default:
if(netmsg->msg_type < 1 || (netmsg->msg_type > MSG_GET_PROPERTY && netmsg->msg_type < MSG_NULL ) || netmsg->msg_type > MSG_UPDATE)
WARN(MSG_NET, "unknown message type %d\n",netmsg->msg_type);
}
}
DEBUGNETC("\n");
}
void print_vtuner_net_message(vtuner_net_message_t* netmsg) {
char* bytes;
int i;
bytes=(char*)netmsg;
DEBUGNET(" (%d) ",sizeof(vtuner_net_message_t));
for(i=0; i<sizeof(vtuner_net_message_t); ++i) {
DEBUGNETC("%x ", bytes[i]);
}
DEBUGNETC("\n");
}