-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCellInfoView.m
More file actions
226 lines (205 loc) · 8.65 KB
/
CellInfoView.m
File metadata and controls
226 lines (205 loc) · 8.65 KB
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
//
// CellInfoView.m
// CellularInfo
//
// Created by Nahum Getachew on 2/22/15.
// Copyright (c) 2015 Nahum Getachew. All rights reserved.
//
#import "CellInfoView.h"
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import "dlfcn.h"
#import "CTCellMonitor.h"
@implementation CellInfoView
-(id)initWithFrame:(CGRect)frame {
self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class])
owner:self
options:nil] objectAtIndex:0];
self.frame = frame;
CALayer* layer = [CALayer layer];
layer.frame = CGRectMake(0.0f, 99.5f, self.frame.size.width, 0.5f);
layer.backgroundColor = [UIColor whiteColor].CGColor;
[self.layer addSublayer:layer];
return self;
}
- (void)setData:(NSDictionary*)data
{
NSString* currentRadioAccess = data[(__bridge __strong id)(kCTCellMonitorCellRadioAccessTechnology)];
self.lblMain.text = [currentRadioAccess componentsSeparatedByString:@"kCTCellMonitorRadioAccessTechnology"][1];
if (!currentRadioAccess)
{
self.lblMain.text = @"No Mobile Data";
[self.lblMain sizeToFit];
self.lblSignal.text = @"";
self.lblTxAntennas.text = @"";
self.lblBandwidth.text = @"";
self.lblExtra1.text = @"";
self.lblExtra2.text = @"";
self.lblExtra3.text = @"";
}
else if ([currentRadioAccess isEqual:@"kCTCellMonitorRadioAccessTechnologyCDMA1x"])
{
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
int (*CTGetSignalStrength)();
CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength");
if( CTGetSignalStrength == NULL) NSLog(@"Could not find CTGetSignalStrength");
int result = CTGetSignalStrength();
int dBm = 0;
if(result <= 0)
dBm = -100;
else if(result >= 100)
dBm = -50;
else
dBm = (result / 2) - 100;
self.lblSignal.text = [NSString stringWithFormat:@"RSSI: %d dBm", dBm];
dlclose(libHandle);
self.lblTxAntennas.text = [NSString stringWithFormat:@"Channel #: %@", data[(__bridge __strong id)(kCTCellMonitorChannelNumber)]];
NSString* bandClass;
switch ([data[(__bridge __strong id)(kCTCellMonitorBandClass)] integerValue])
{
case 0:
bandClass = @"800";
break;
case 1:
bandClass = @"1900 PCS";
break;
case 2:
bandClass = @"TACS";
break;
case 3:
bandClass = @"JTACS";
break;
case 4:
bandClass = @"Korean PCS";
break;
case 5:
bandClass = @"450";
break;
case 6:
bandClass = @"2 Ghz";
break;
case 7:
bandClass = @"Upper 700 Mhz";
break;
case 8:
bandClass = @"1800";
break;
case 9:
bandClass = @"900";
break;
case 10:
bandClass = @"Secondary 800 Mhz";
default:
bandClass = data[(__bridge __strong id)(kCTCellMonitorBandClass)];
break;
}
self.lblBandwidth.text = [NSString stringWithFormat:@"Band Class: %@", bandClass];
self.lblExtra1.text = [NSString stringWithFormat:@"SID: %@", data[(__bridge __strong id)(kCTCellMonitorSID)]];
self.lblExtra2.text = [NSString stringWithFormat:@"NID: %@", data[(__bridge __strong id)(kCTCellMonitorNID)]];
self.lblExtra3.text = [NSString stringWithFormat:@"BID: %@", data[(__bridge __strong id)(kCTCellMonitorBaseStationId)]];
}
else if ([currentRadioAccess isEqual:@"kCTCellMonitorRadioAccessTechnologyCDMAEVDO"] || [currentRadioAccess isEqual:@"kCTCellMonitorRadioAccessTechnologyeHRPD"])
{
CTTelephonyNetworkInfo* networkInfo = [CTTelephonyNetworkInfo new];
if (networkInfo.currentRadioAccessTechnology == CTRadioAccessTechnologyeHRPD)
{
self.lblMain.text = @"eHRPD";
}
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
int (*CTGetSignalStrength)();
CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength");
if( CTGetSignalStrength == NULL) NSLog(@"Could not find CTGetSignalStrength");
int result = CTGetSignalStrength();
int dBm = 0;
if(result <= 0)
dBm = -100;
else if(result >= 100)
dBm = -50;
else
dBm = (result / 2) - 100;
self.lblSignal.text = [NSString stringWithFormat:@"RSSI: %d dBm", dBm];
dlclose(libHandle);
self.lblTxAntennas.text = [NSString stringWithFormat:@"Channel #: %@", data[(__bridge __strong id)(kCTCellMonitorChannelNumber)]];
NSString* bandClass;
switch ([data[(__bridge __strong id)(kCTCellMonitorBandClass)] integerValue])
{
case 0:
bandClass = @"800";
break;
case 1:
bandClass = @"1900 PCS";
break;
case 2:
bandClass = @"TACS";
break;
case 3:
bandClass = @"JTACS";
break;
case 4:
bandClass = @"Korean PCS";
break;
case 5:
bandClass = @"450";
break;
case 6:
bandClass = @"2 Ghz";
break;
case 7:
bandClass = @"Upper 700 Mhz";
break;
case 8:
bandClass = @"1800";
break;
case 9:
bandClass = @"900";
break;
case 10:
bandClass = @"Secondary 800 Mhz";
break;
default:
bandClass = data[(__bridge __strong id)(kCTCellMonitorBandClass)];
break;
}
self.lblBandwidth.text = [NSString stringWithFormat:@"Band Class: %@", bandClass];
self.lblExtra1.text = [NSString stringWithFormat:@"MCC: %@", data[(__bridge __strong id)(kCTCellMonitorMCC)]];
self.lblExtra2.text = [NSString stringWithFormat:@"PN Offset: %@", data[(__bridge __strong id)(kCTCellMonitorPNOffset)]];
}
else if ([currentRadioAccess isEqual:@"kCTCellMonitorRadioAccessTechnologyLTE"])
{
self.lblMain.text = [NSString stringWithFormat:@"LTE: Band %@", data[(__bridge __strong id)(kCTCellMonitorBandInfo)]];
self.lblSignal.text = [NSString stringWithFormat:@"RSRP: %@ dBm", data[(__bridge __strong id)(kCTCellMonitorRSRP)]];
self.lblTxAntennas.text = [NSString stringWithFormat:@"SNR: %@ dB", data[(__bridge __strong id)(kCTCellMonitorSNR)]];
int bw = [data[(__bridge __strong id)(kCTCellMonitorBandwidth)] intValue];
if ([data[(__bridge __strong id)(kCTCellMonitorBandInfo)] isEqual:@41])
{
if ([data[(__bridge __strong id)(kCTCellMonitorMCC)] isEqual:@310] && [data[(__bridge __strong id)(kCTCellMonitorMNC)] isEqual:@120])
{
self.lblBandwidth.text = @"Type: TDD 1x20 MHz (Sprint)";
}
else self.lblBandwidth.text = @"Type: TDD 1x20 MHz (Clear)";
}
else self.lblBandwidth.text = [NSString stringWithFormat:@"Type: FDD %dx%d MHz", bw / 5, bw / 5];
id CTConnection = _CTServerConnectionCreate(NULL, NULL, NULL);
int CID;
_CTServerConnectionGetCellID(CTConnection, &CID);
NSString* CIDstring = [NSString stringWithFormat:@"%X", CID];
NSInteger length = CIDstring.length;
if (length < 8)
{
for (NSInteger i = length; i < 8; i++) CIDstring = [@"0" stringByAppendingString:CIDstring];
}
self.lblExtra1.text = [NSString stringWithFormat:@"GCI: %@", CIDstring];
self.lblExtra2.text = [NSString stringWithFormat:@"PID: %@", data[(__bridge __strong id)(kCTCellMonitorPID)]];
self.lblExtra3.text = [NSString stringWithFormat:@"EARFCN: %@", data[(__bridge __strong id)(kCTCellMonitorUARFCN)]];
self.lblExtra4.text = [NSString stringWithFormat:@"TAC: %@", data[(__bridge __strong id)(kCTCellMonitorTAC)]];
}
else
{
self.lblSignal.text = @"";
self.lblTxAntennas.text = @"";
self.lblBandwidth.text = @"";
self.lblExtra1.text = @"Unknown Connection Type";
self.lblExtra2.text = @"";
self.lblExtra3.text = @"";
}
}
@end