summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2019-05-31 14:38:50 +0200
committerBjørn Mork <bjorn@mork.no>2019-05-31 14:38:54 +0200
commit708c5c87c7a4b3f824493612edfd773eac9ff2a2 (patch)
treecc3bd0b3d7c46d4921ef6d47f4188b9a5ca370be
parent932fa0cff30c4eb2a566e08257e91540f3e2d471 (diff)
unlocking and wifi scanningdevel-wip-branch
05-31 14:37:36.432 9678 9697 D Defogger MainActivity: : hashit string is DCS-8000LH-CC73123947kzinr98nlcpe8ur4 05-31 14:37:36.433 9678 9697 D Defogger MainActivity: : doUnlock(), key is zXtSkCAbEov6xaK4 05-31 14:37:37.150 9678 9697 D Defogger MainActivity: : Write to 0000a001-0000-1000-8000-00805f9b34fb status=0, value is now: M=0;K=zXtSkCAbEov6xaK4 05-31 14:37:37.150 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:39.547 9678 9678 D Defogger Scanning: : stopped scanning 05-31 14:37:39.809 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=1;L=I=1,M=0,C=11,S=4,E=2,P=100&L=I=2,M=0,C=11,S=4,E=2,P=100&L=I=3,M=0,C=11,S=4,E=2,P=100&L=I=62400037-2,M=0,C=10,S=4,E=2, 05-31 14:37:39.811 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:40.392 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=2;P=72&L=I=78648756387465873,M=0,C=9,S=4,E=2,P=100&L=I=aaaa7,M=0,C=4,S=4,E=2,P=100&L=I=ALHN-2C78,M=0,C=6,S=4,E=2,P=100&L= 05-31 14:37:40.392 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:40.932 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=3;I=BBF,M=0,C=1,S=4,E=2,P=92&L=I=CDK-PROD,M=0,C=7,S=4,E=2,P=75&L=I=CDK-Terminator,M=0,C=1,S=4,E=2,P=74&L=I=CHANGE_ME,M=0, 05-31 14:37:40.933 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:41.472 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=4;C=1,S=4,E=2,P=94&L=I=Desk-kristo,M=0,C=11,S=4,E=2,P=100&L=I=DeskAnders,M=0,C=11,S=4,E=2,P=100&L=I=emp,M=0,C=1,S=4,E=2,P 05-31 14:37:41.473 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:42.104 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=5;=92&L=I=FooBar,M=0,C=2,S=4,E=2,P=69&L=I=getworkdone,M=0,C=9,S=4,E=2,P=100&L=I=HalvProd,M=0,C=11,S=4,E=2,P=94&L=I=HalvPr 05-31 14:37:42.105 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:42.732 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=6;od-Guest,M=0,C=11,S=4,E=2,P=92&L=I=IP%20Operations,M=0,C=2,S=4,E=2,P=76&L=I=Kaffekrok,M=0,C=6,S=4,E=2,P=100&L=I=Telenor 05-31 14:37:42.733 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:43.317 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=7;-0001,M=0,C=6,S=4,E=2,P=100&L=I=Telenor-104B,M=0,C=6,S=4,E=2,P=100&L=I=Telenor0036fil,M=0,C=11,S=4,E=2,P=68&L=I=Telenor 05-31 14:37:43.317 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:43.901 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=8;0669ode,M=0,C=4,S=4,E=2,P=100&L=I=Telenor1445fot,M=0,C=3,S=4,E=2,P=100&L=I=Telenor4021ett,M=0,C=8,S=4,E=2,P=90&L=I=Tele 05-31 14:37:43.901 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:44.442 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=9;nor5421kur,M=0,C=6,S=4,E=2,P=100&L=I=Telenor6884bit,M=0,C=4,S=4,E=2,P=98&L=I=Telenor7086som,M=0,C=6,S=4,E=2,P=100&L=I=T 05-31 14:37:44.443 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:44.982 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=10;elenor_employee,M=0,C=11,S=4,E=2,P=74&L=I=Telenor_Guest,M=0,C=11,S=0,E=0,P=74&L=I=TelenorInpli,M=0,C=1,S=4,E=2,P=100&L 05-31 14:37:44.983 9678 9697 D Defogger MainActivity: : doWifiScan() 05-31 14:37:45.479 9678 9697 D Defogger MainActivity: : 0000a100-0000-1000-8000-00805f9b34fb read N=11;P=11;=I=This_WIFI,M=0,C=1,S=4,E=2,P=100&L=I=Zyxel%20Speedtest,M=0,C=1,S=4,E=2,P=100 05-31 14:37:45.479 9678 9697 D Defogger MainActivity: : L=I=1,M=0,C=11,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=2,M=0,C=11,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=3,M=0,C=11,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=62400037-2,M=0,C=10,S=4,E=2,P=72 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=78648756387465873,M=0,C=9,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=aaaa7,M=0,C=4,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=ALHN-2C78,M=0,C=6,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=BBF,M=0,C=1,S=4,E=2,P=92 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=CDK-PROD,M=0,C=7,S=4,E=2,P=75 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=CDK-Terminator,M=0,C=1,S=4,E=2,P=74 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=CHANGE_ME,M=0,C=1,S=4,E=2,P=94 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=Desk-kristo,M=0,C=11,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=DeskAnders,M=0,C=11,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=emp,M=0,C=1,S=4,E=2,P=92 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=FooBar,M=0,C=2,S=4,E=2,P=69 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=getworkdone,M=0,C=9,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=HalvProd,M=0,C=11,S=4,E=2,P=94 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=HalvProd-Guest,M=0,C=11,S=4,E=2,P=92 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=IP%20Operations,M=0,C=2,S=4,E=2,P=76 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=Kaffekrok,M=0,C=6,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=Telenor-0001,M=0,C=6,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=Telenor-104B,M=0,C=6,S=4,E=2,P=100 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=Telenor0036fil,M=0,C=11,S=4,E=2,P=68 05-31 14:37:45.480 9678 9697 D Defogger MainActivity: : L=I=Telenor0669ode,M=0,C=4,S=4,E=2,P=100 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=Telenor1445fot,M=0,C=3,S=4,E=2,P=100 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=Telenor4021ett,M=0,C=8,S=4,E=2,P=90 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=Telenor5421kur,M=0,C=6,S=4,E=2,P=100 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=Telenor6884bit,M=0,C=4,S=4,E=2,P=98 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=Telenor7086som,M=0,C=6,S=4,E=2,P=100 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=Telenor_employee,M=0,C=11,S=4,E=2,P=74 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=Telenor_Guest,M=0,C=11,S=0,E=0,P=74 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=TelenorInpli,M=0,C=1,S=4,E=2,P=100 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=This_WIFI,M=0,C=1,S=4,E=2,P=100 05-31 14:37:45.481 9678 9697 D Defogger MainActivity: : L=I=Zyxel%20Speedtest,M=0,C=1,S=4,E=2,P=100 Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r--Defogger/src/no/mork/android/defogger/MainActivity.java100
1 files changed, 87 insertions, 13 deletions
diff --git a/Defogger/src/no/mork/android/defogger/MainActivity.java b/Defogger/src/no/mork/android/defogger/MainActivity.java
index 603d35f..730b72e 100644
--- a/Defogger/src/no/mork/android/defogger/MainActivity.java
+++ b/Defogger/src/no/mork/android/defogger/MainActivity.java
@@ -142,6 +142,7 @@ public class MainActivity extends Activity {
// Gatt connection
private class GattClientCallback extends BluetoothGattCallback {
+ private String multimsg;
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.d(msg, "onConnectionStateChange() " + status + " " + newState);
@@ -151,35 +152,79 @@ public class MainActivity extends Activity {
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
List<BluetoothGattService> serviceList = gatt.getServices();
BluetoothGattService s;
- BluetoothGattCharacteristic a001;
for (BluetoothGattService service : serviceList) {
Log.d(msg, service.getUuid().toString());
}
- s = gatt.getService(ipcamService);
- for (BluetoothGattCharacteristic c : s.getCharacteristics()) {
- Log.d(msg, "ipcam char: " + c.getUuid().toString());
- }
+ // FIXME: bail out if not found
+ // s = getIPCamService();
+
+ // build a map of code to Characteristic
+ // Map<BluetoothGattCharacteristic, > cmap = new HashMap();
+ // for (BluetoothGattCharacteristic c : s.getCharacteristics()) {
+ // int code = (int)(c.getUuid().getMostSignificantBits() >> 32);
+ // Log.d(msg, "ipcam char: " + c.getUuid().toString() + String.format(" - %#06x", code));
+
+ // cmap.put(c, code);
+ //}
- a001 = s.getCharacteristic(UUID.fromString("0000a001-0000-1000-8000-00805f9b34fb"));
- gatt.readCharacteristic(a001);
+ notifications(true);
+ getLock();
}
public void onCharacteristicRead (BluetoothGatt gatt, BluetoothGattCharacteristic c, int status) {
- EditText pincode = (EditText) findViewById(R.id.pincode);
+ int code = (int)(c.getUuid().getMostSignificantBits() >> 32);
Map<String,String> kv = splitKV(c.getStringValue(0));
Log.d(msg, c.getUuid().toString() + " read " + c.getStringValue(0));
- Log.d(msg, "pincode is " + pincode.getText());
+
+ switch (code) {
+ case 0xa001:
+ EditText pincode = (EditText) findViewById(R.id.pincode);
+ Log.d(msg, "pincode is " + pincode.getText());
- String hashit = gatt.getDevice().getName() + pincode.getText() + kv.get("C");
- Log.d(msg, "hashit string is " + hashit);
- Log.d(msg, "key is " + calculateKey(hashit));
-
+ String hashit = gatt.getDevice().getName() + pincode.getText() + kv.get("C");
+ Log.d(msg, "hashit string is " + hashit);
+ String key = calculateKey(hashit);
+
+ doUnlock(key);
+ break;
+ case 0xa100:
+ multimsg += c.getStringValue(0).split(";",3)[2];
+ // repeat until result is complete
+ if (!kv.get("N").equals(kv.get("P")))
+ doWifiScan();
+ else
+ for (String net : multimsg.split("&")) {
+ Log.d(msg, net);
+ }
+ break;
+ default:
+ Log.d(msg, "Read unhandled characteristic: " + c.getUuid().toString());
+ }
}
+ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic c) {
+ Log.d(msg, c.getUuid().toString() + " changed to " + c.getStringValue(0));
+ }
+
+ public void onCharacteristicWrite (BluetoothGatt gatt, BluetoothGattCharacteristic c, int status) {
+ int code = (int)(c.getUuid().getMostSignificantBits() >> 32);
+ Map<String,String> kv = splitKV(c.getStringValue(0));
+
+ Log.d(msg, "Write to " + c.getUuid().toString() + " status=" + status + ", value is now: " + c.getStringValue(0));
+
+ switch (code) {
+ case 0xa001:
+ multimsg = "";
+ doWifiScan();
+ break;
+ default:
+ Log.d(msg, "No action defined after " + c.getUuid().toString());
+ }
+ }
}
private void connectDevice(BluetoothDevice device) {
@@ -195,4 +240,33 @@ public class MainActivity extends Activity {
mGatt.close();
}
+
+ // camera specific code
+ private BluetoothGattService getIPCamService() {
+ // FIXME: bail out if not found
+ return mGatt.getService(ipcamService);
+ }
+
+ private void notifications(boolean enable) {
+ BluetoothGattCharacteristic a000 = getIPCamService().getCharacteristic(UUID.fromString("0000a000-0000-1000-8000-00805f9b34fb"));
+ mGatt.setCharacteristicNotification(a000, enable);
+ }
+
+ private void getLock() {
+ BluetoothGattCharacteristic a001 = getIPCamService().getCharacteristic(UUID.fromString("0000a001-0000-1000-8000-00805f9b34fb"));
+ mGatt.readCharacteristic(a001);
+ }
+
+ private void doUnlock(String key) {
+ Log.d(msg, "doUnlock(), key is " + key);
+ BluetoothGattCharacteristic a001 = getIPCamService().getCharacteristic(UUID.fromString("0000a001-0000-1000-8000-00805f9b34fb"));
+ a001.setValue("M=0;K=" + key);
+ mGatt.writeCharacteristic(a001);
+ }
+
+ private void doWifiScan() {
+ Log.d(msg, "doWifiScan()");
+ BluetoothGattCharacteristic a100 = getIPCamService().getCharacteristic(UUID.fromString("0000a100-0000-1000-8000-00805f9b34fb"));
+ mGatt.readCharacteristic(a100);
+ }
}