[go: up one dir, main page]

File: unicorn_status.c

package info (click to toggle)
unicorn 0.8.7-1.1
  • links: PTS
  • area: non-free
  • in suites: sarge
  • size: 3,984 kB
  • ctags: 3,428
  • sloc: ansic: 20,028; cpp: 1,265; sh: 1,033; makefile: 710; yacc: 316; sed: 16
file content (425 lines) | stat: -rw-r--r-- 11,163 bytes parent folder | download
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#include <stdio.h>
#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <errno.h>
#include <sys/ioctl.h>
#include "amu.h"
#include "unicorn.h"
#include "unicorn_status.h"


static const char *modem_state_string(AMSW_ModemState modemState)
{
	switch(modemState) {
	case C_AMSW_IDLE: return ("IDLE");
	case C_AMSW_L3:  return ("L3");
	case C_AMSW_LISTENING:  return ("LISTENING");
	case C_AMSW_ACTIVATING:  return ("ACTIVATING");
	case C_AMSW_Ghs_HANDSHAKING:  return ("Ghs_HANDSHAKING");
	case C_AMSW_ANSI_HANDSHAKING:  return ("ANSI_HANDSHAKING");
	case C_AMSW_INITIALIZING:  return ("INITIALIZING");
	case C_AMSW_RESTARTING:  return ("RESTARTING");
	case C_AMSW_FAST_RETRAIN:  return ("FAST_RETRAIN");
	case C_AMSW_SHOWTIME_L0:  return ("SHOWTIME_L0");
	case C_AMSW_SHOWTIME_LQ:  return ("SHOWTIME_LQ");
	case C_AMSW_SHOWTIME_L1:  return ("SHOWTIME_L1");
	case C_AMSW_EXCHANGE:  return ("EXCHANGE");
	case C_AMSW_TRUNCATE:  return ("TRUNCATE");
	case C_AMSW_ESCAPE:  return ("ESCAPE");
	case C_AMSW_RETRY:  return ("RETRY");
	case C_AMSW_DISORDERLY:  return ("DISORDERLY");
	default: return (" ");
	}
}

static const char *modem_event_string(AMSW_ModemEvent event)
{
	switch(event) {
	case C_AMSW_PEER_ATU_FOUND: return ("Peer ATU Found");
	case C_AMSW_RESTART_REQUEST: return ("Restart Request");
	case C_AMSW_ACTIVATION_REQUEST: return ("Activation Request");
	case C_AMSW_TO_INITIALIZING: return ("Initializing");
	case C_AMSW_SHOWTIME: return ("Showtime");
	case C_AMSW_L3_EXECUTED: return ("L3 Executed");
	case C_AMSW_L3_REJECTED: return ("L3 Rejected");
	case C_AMSW_L1_EXECUTED: return ("L1 Executed");
	case C_AMSW_L1_REJECTED: return ("L1 Rejected");
	case C_AMSW_L0_REJECTED: return ("L0 Rejected");
	case C_AMSW_RESTART_ACCEPTABLE: return ("Restart Acceptable");
	case C_AMSW_SUICIDE_REQUEST: return ("Suicide Request");
	case C_AMSW_RESTART_NOT_ACCEPTABLE: return ("Restart Not Acceptable");
	default: return (" ");
	}
}

static const char *modem_failure_string(AMSW_ModemFailure failure)
{
	switch(failure) {
	case C_AMSW_UNCOMPATIBLE_LINECONDITIONS: return ("Uncompatible Line Conditions");
	case C_AMSW_NO_LOCK_POSSIBLE: return ("No Lock Possible");
	case C_AMSW_PROTOCOL_ERROR: return ("Protocol Error");
	case C_AMSW_MESSAGE_ERROR: return ("Message Error");
	case C_AMSW_SPURIOUS_ATU_DETECTED: return ("Spurious ATU Detected");
	case C_AMSW_DS_REQ_BITRATE_TOO_HIGH_FOR_LITE: return ("Requested Bit Rate Too High");
	case C_AMSW_INTERLEAVED_PROFILE_REQUIRED_FOR_LITE: return ("Interleaved Profile Required for LITE");
	case C_AMSW_FORCED_SILENCE: return ("Forced Silence");
	case C_AMSW_UNSELECTABLE_OPERATION_MODE: return ("Unselectable Operation Mode");
	case C_AMSW_STATE_REFUSED_BY_GOLDEN: return ("State Refused By Golden");
	case C_AMSW_AMU_EVENT_ACT_TIMEOUT: return ("Activation Timeout");
	case C_AMSW_AMU_EVENT_INI_TIMEOUT: return ("Initialization Timeout");
	case C_AMSW_AMU_EVENT_SHUTDOWN: return ("Bringing Down Line due to persistent faults");
	case C_AMSW_EVENT_RETRY: return ("Retry");
	case C_AMSW_UNKNOWN: return ("Unknown");
	case C_AMSW_UNKNOWN_FAILURE: return ("Unknown failure");
	case C_AMSW_NO_HARDWARE: return ("No hardware detected");
	case C_AMSW_NO_USB_BANDWIDTH: return ("USB bandwidth unavailable");
	default: return (" ");
	}
}

static const char *modulation_string(unsigned long operationalMode)
{
	switch(operationalMode) {
	case AMSW_ANSI: return ("ANSI");
	case AMSW_G_LITE: return ("G.lite");
	case AMSW_G_DMT: return ("G.dmt");
	default: return (" ");
	}
}

static const char *time_connected_string(unsigned long TimeCnctd)
{
		if (TimeCnctd == 0L) {
			return ("--:--:--");
		} else {
			unsigned long t = TimeCnctd/1000UL;
			static char time_str[16];
			unsigned long h = t/3600;
			unsigned long s = t%3600;
			unsigned long m = s/60;
			s = s%60;
			snprintf(time_str,16,"%2.2ld:%2.2ld:%2.2ld",h,m,s);
			return time_str;
		}
}


AMSW_ModemState get_modem_state(ADSL_DEVICE *device)
{
	AMSW_ModemState state=C_AMSW_IDLE;
	T_MswCtrl ctrl = {MSW_CTL_GET_STATE,0,0,&state,sizeof(state)};
	msw_ctrl(device,&ctrl);
	return state;
}


static void get_state_info(ADSL_DEVICE *device,T_StateInfo *info)
{
	T_MswCtrl ctrl;

	info->State = 0;
	info->Report = -1;
	info->Failure = C_AMSW_NO_HARDWARE;
	info->TimeCnctd = 0L;

	ctrl.code = MSW_CTL_STATE_INFO;
	ctrl.subcode = 0;
	ctrl.retcode = 0;
	ctrl.buffer = info;
	ctrl.length = sizeof(T_StateInfo);

	msw_ctrl(device,&ctrl);
}

static void get_bit_rates(ADSL_DEVICE *device,unsigned short *bit_rates)
{
	int i;

	for (i=0; i < 4; i++) {
		T_AMSW_NT_ChannelOperData cod;
		T_MswCtrl ctrl = 
			{MSW_CTL_GET_DATA,C_AMSW_NEAR_END_CHANNEL_DATA_FAST+i,
			 0,&cod,sizeof(T_AMSW_NT_ChannelOperData)};
		bit_rates[i] = 0;
		msw_ctrl(device,&ctrl);
		if (ctrl.retcode == 0) {
			bit_rates[i] = cod.actualBitrate;
		} else {
			bit_rates[i] = 0;
		}
	}	
}

static void get_near_end_line_oper_data(ADSL_DEVICE *device,T_AMSW_NT_NearEndLineOperData *nelod)
{	
	T_MswCtrl ctrl = {MSW_CTL_GET_DATA,C_AMSW_NEAR_END_LINE_DATA,0,
			  nelod,sizeof(T_AMSW_NT_NearEndLineOperData)};
	memset(nelod,0,sizeof(T_AMSW_NT_NearEndLineOperData));
	msw_ctrl(device,&ctrl);
}

static void get_far_end_line_oper_data(ADSL_DEVICE *device,T_AMSW_NT_FarEndLineOperData *felod)
{	
	T_MswCtrl ctrl = {MSW_CTL_GET_DATA,C_AMSW_FAR_END_LINE_DATA,0,
			  felod,sizeof(T_AMSW_NT_FarEndLineOperData)};
	memset(felod,0,sizeof(T_AMSW_NT_FarEndLineOperData));
	msw_ctrl(device,&ctrl);
}

static void get_counters(ADSL_DEVICE *device,T_AMSW_def_counter_set *dcs)
{	
	T_MswCtrl ctrl = {MSW_CTL_GET_DATA,C_AMSW_PM_DATA,0,dcs,sizeof(T_AMSW_def_counter_set)};
	memset(dcs,0,sizeof(T_AMSW_def_counters));
	msw_ctrl(device,&ctrl);
}


const char *get_modem_state_string(ADSL_DEVICE *device)
{
	return modem_state_string(get_modem_state(device));	
}

const char *get_modem_event_string(ADSL_DEVICE *device)
{
	T_StateInfo info;

	get_state_info(device,&info);
	return modem_event_string(info.Report);	
}

const char *get_modem_failure_string(ADSL_DEVICE *device)
{
	T_StateInfo info;

	get_state_info(device,&info);
	return modem_failure_string(info.Failure);	
}

const char *get_time_connected_string(ADSL_DEVICE *device)
{
	T_StateInfo info;

	get_state_info(device,&info);
	return time_connected_string(info.TimeCnctd);	
}

const char *get_modulation_string(ADSL_DEVICE *device)
{
	T_AMSW_NT_NearEndLineOperData nelod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_near_end_line_oper_data(device,&nelod);
		return modulation_string(nelod.operationalMode);
	} else {
		return "";
	}
}

int get_us_rate(ADSL_DEVICE *device)
{
	short bit_rates[4];
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_bit_rates(device,bit_rates);
		return bit_rates[1]+bit_rates[3];
	} else {
		return 0;
	}
}

int get_ds_rate(ADSL_DEVICE *device)
{
	short bit_rates[4];
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_bit_rates(device,bit_rates);
		return bit_rates[0]+bit_rates[2];
	} else {
		return 0;
	}
}

int get_us_cap_occ(ADSL_DEVICE *device)
{
	T_AMSW_NT_FarEndLineOperData felod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_far_end_line_oper_data(device,&felod);
		return felod.relCapacityOccupationUpstr;
	} else {
		return 0;
	}
}

int get_ds_cap_occ(ADSL_DEVICE *device)
{
	T_AMSW_NT_NearEndLineOperData nelod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_near_end_line_oper_data(device,&nelod);
		return nelod.relCapacityOccupationDnstr;
	} else {
		return 0;
	}
}

int get_us_noise_margin(ADSL_DEVICE *device)
{
	T_AMSW_NT_FarEndLineOperData felod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_far_end_line_oper_data(device,&felod);
		return felod.noiseMarginUpstr/2;
	} else {
		return 0;
	}
}

int get_ds_noise_margin(ADSL_DEVICE *device)
{
	T_AMSW_NT_NearEndLineOperData nelod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_near_end_line_oper_data(device,&nelod);
		return nelod.noiseMarginDnstr/2;
	} else {
		return 0;
	}
}

int get_us_attenuation(ADSL_DEVICE *device)
{
	T_AMSW_NT_FarEndLineOperData felod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_far_end_line_oper_data(device,&felod);
		return felod.attenuationUpstr/2;
	} else {
		return 0;
	}
}

int get_ds_attenuation(ADSL_DEVICE *device)
{
	T_AMSW_NT_NearEndLineOperData nelod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_near_end_line_oper_data(device,&nelod);
		return nelod.attenuationDnstr/2;
	} else {
		return 0;
	}
}

int get_us_output_power(ADSL_DEVICE *device)
{
	T_AMSW_NT_NearEndLineOperData nelod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_near_end_line_oper_data(device,&nelod);
		return  nelod.outputPowerUpstr/2;
	} else {
		return 0;
	}
}

int get_ds_output_power(ADSL_DEVICE *device)
{
	T_AMSW_NT_FarEndLineOperData felod;
	
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_far_end_line_oper_data(device,&felod);
		return felod.outputPowerDnstr/2;
	} else {
		return 0;
	}
}

int get_us_fec_errors(ADSL_DEVICE *device)
{
	T_AMSW_def_counter_set dcs;
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_counters(device,&dcs);
		return dcs.near_end.FecNotInterleaved+dcs.near_end.FecInterleaved;
	} else {
		return 0;
	}
}

int get_ds_fec_errors(ADSL_DEVICE *device)
{
	T_AMSW_def_counter_set dcs;
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_counters(device,&dcs);
		return dcs.far_end.FecNotInterleaved+dcs.far_end.FecInterleaved;
	} else {
		return 0;
	}
}

int get_us_crc_errors(ADSL_DEVICE *device)
{
	T_AMSW_def_counter_set dcs;
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_counters(device,&dcs);
		return dcs.near_end.CrcNotInterleaved+dcs.near_end.CrcInterleaved;
	} else {
		return 0;
	}
}

int get_ds_crc_errors(ADSL_DEVICE *device)
{
	T_AMSW_def_counter_set dcs;
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_counters(device,&dcs);
		return dcs.far_end.CrcNotInterleaved+dcs.far_end.CrcInterleaved;
	} else {
		return 0;
	}
}

int get_us_hec_errors(ADSL_DEVICE *device)
{
	T_AMSW_def_counter_set dcs;
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_counters(device,&dcs);
		return dcs.near_end.HecNotInterleaved+dcs.near_end.HecInterleaved;
	} else {
		return 0;
	}
}

int get_ds_hec_errors(ADSL_DEVICE *device)
{
	T_AMSW_def_counter_set dcs;
	if (get_modem_state(device) == C_AMSW_SHOWTIME_L0) {
		get_counters(device,&dcs);
		return dcs.far_end.HecNotInterleaved+dcs.far_end.HecInterleaved;
	} else {
		return 0;
	}
}

const char *get_version_string(ADSL_DEVICE *device)
{
	static T_AMSW_VersionMS version;
	T_MswCtrl ctrl = {MSW_CTL_GET_DATA,C_AMSW_VERSIONMS,0,&version,sizeof(T_AMSW_VersionMS)};
	
	version.versionA[0] = 0;
	msw_ctrl(device,&ctrl);
	return version.versionA;
}

const char *get_driver_version_string(ADSL_DEVICE *device)
{
	unsigned long driver_version=0;
	static char s[16];
	T_MswCtrl ctrl = {MSW_CTL_VERSION_INFO,0,0,&driver_version,sizeof(driver_version)};
	msw_ctrl(device,&ctrl);
	sprintf(s,"%ld.%ld.%ld",(driver_version>>8)&0xf,(driver_version>>4)&0xf,driver_version&0xf);
	return s;
}