kard-network-ble-mesh 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/build.gradle
CHANGED
|
@@ -66,12 +66,12 @@ android {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
compileOptions {
|
|
69
|
-
sourceCompatibility JavaVersion.
|
|
70
|
-
targetCompatibility JavaVersion.
|
|
69
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
70
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
kotlinOptions {
|
|
74
|
-
jvmTarget = "
|
|
74
|
+
jvmTarget = "17"
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
sourceSets {
|
|
@@ -481,7 +481,9 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
481
481
|
BluetoothProfile.STATE_CONNECTED -> {
|
|
482
482
|
Log.d(TAG, "Connected to GATT server: $address")
|
|
483
483
|
gattConnections[address] = gatt
|
|
484
|
-
|
|
484
|
+
// Request larger MTU for bigger packets (512 bytes)
|
|
485
|
+
Log.d(TAG, "Requesting MTU 512 for $address")
|
|
486
|
+
gatt.requestMtu(512)
|
|
485
487
|
}
|
|
486
488
|
BluetoothProfile.STATE_DISCONNECTED -> {
|
|
487
489
|
Log.d(TAG, "Disconnected from GATT server: $address")
|
|
@@ -500,9 +502,12 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
500
502
|
|
|
501
503
|
@SuppressLint("MissingPermission")
|
|
502
504
|
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
|
|
505
|
+
Log.d(TAG, "onServicesDiscovered: status=$status for ${gatt.device.address}")
|
|
503
506
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
|
504
507
|
val service = gatt.getService(serviceUUID)
|
|
508
|
+
Log.d(TAG, "Found service: ${service != null}, UUID: $serviceUUID")
|
|
505
509
|
val characteristic = service?.getCharacteristic(characteristicUUID)
|
|
510
|
+
Log.d(TAG, "Found characteristic: ${characteristic != null}")
|
|
506
511
|
|
|
507
512
|
if (characteristic != null) {
|
|
508
513
|
gatt.setCharacteristicNotification(characteristic, true)
|
|
@@ -510,21 +515,40 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
510
515
|
val descriptor = characteristic.getDescriptor(
|
|
511
516
|
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")
|
|
512
517
|
)
|
|
518
|
+
Log.d(TAG, "Found descriptor: ${descriptor != null}")
|
|
513
519
|
descriptor?.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
|
|
514
520
|
gatt.writeDescriptor(descriptor)
|
|
515
521
|
|
|
516
522
|
// Send announce
|
|
523
|
+
Log.d(TAG, "Sending announce after services discovered")
|
|
517
524
|
sendAnnounce()
|
|
525
|
+
} else {
|
|
526
|
+
Log.e(TAG, "Characteristic not found on remote device!")
|
|
518
527
|
}
|
|
528
|
+
} else {
|
|
529
|
+
Log.e(TAG, "Service discovery failed with status: $status")
|
|
519
530
|
}
|
|
520
531
|
}
|
|
521
532
|
|
|
522
533
|
override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
|
|
523
534
|
val data = characteristic.value
|
|
535
|
+
Log.d(TAG, "onCharacteristicChanged: received ${data?.size ?: 0} bytes from ${gatt.device.address}")
|
|
524
536
|
if (data != null) {
|
|
525
537
|
handleReceivedPacket(data, gatt.device.address)
|
|
526
538
|
}
|
|
527
539
|
}
|
|
540
|
+
|
|
541
|
+
@SuppressLint("MissingPermission")
|
|
542
|
+
override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) {
|
|
543
|
+
Log.d(TAG, "MTU changed to $mtu for ${gatt.device.address}, status: $status")
|
|
544
|
+
if (status == BluetoothGatt.GATT_SUCCESS) {
|
|
545
|
+
// Now discover services after MTU is set
|
|
546
|
+
gatt.discoverServices()
|
|
547
|
+
} else {
|
|
548
|
+
Log.e(TAG, "MTU negotiation failed, discovering services anyway")
|
|
549
|
+
gatt.discoverServices()
|
|
550
|
+
}
|
|
551
|
+
}
|
|
528
552
|
}
|
|
529
553
|
|
|
530
554
|
private val gattServerCallback = object : BluetoothGattServerCallback() {
|
|
@@ -553,8 +577,12 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
553
577
|
offset: Int,
|
|
554
578
|
value: ByteArray
|
|
555
579
|
) {
|
|
580
|
+
Log.d(TAG, "onCharacteristicWriteRequest: ${value.size} bytes from ${device.address}, uuid=${characteristic.uuid}")
|
|
556
581
|
if (characteristic.uuid == characteristicUUID) {
|
|
582
|
+
Log.d(TAG, "Characteristic matches, handling packet")
|
|
557
583
|
handleReceivedPacket(value, device.address)
|
|
584
|
+
} else {
|
|
585
|
+
Log.d(TAG, "Characteristic UUID mismatch: expected $characteristicUUID")
|
|
558
586
|
}
|
|
559
587
|
if (responseNeeded) {
|
|
560
588
|
gattServer?.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, null)
|
|
@@ -579,26 +607,41 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
579
607
|
// MARK: - Packet Handling
|
|
580
608
|
|
|
581
609
|
private fun handleReceivedPacket(data: ByteArray, fromAddress: String) {
|
|
582
|
-
|
|
610
|
+
Log.d(TAG, "handleReceivedPacket: ${data.size} bytes from $fromAddress")
|
|
611
|
+
val packet = BitchatPacket.decode(data)
|
|
612
|
+
if (packet == null) {
|
|
613
|
+
Log.e(TAG, "Failed to decode packet!")
|
|
614
|
+
return
|
|
615
|
+
}
|
|
583
616
|
|
|
584
617
|
val senderId = packet.senderId.joinToString("") { "%02x".format(it) }
|
|
618
|
+
Log.d(TAG, "Packet from sender: $senderId, type: ${packet.type}, myPeerId: $myPeerId")
|
|
585
619
|
|
|
586
620
|
// Skip our own packets
|
|
587
|
-
if (senderId == myPeerId)
|
|
621
|
+
if (senderId == myPeerId) {
|
|
622
|
+
Log.d(TAG, "Skipping own packet")
|
|
623
|
+
return
|
|
624
|
+
}
|
|
588
625
|
|
|
589
626
|
// Deduplication
|
|
590
627
|
val messageId = "$senderId-${packet.timestamp}-${packet.type}"
|
|
591
|
-
if (processedMessages.contains(messageId))
|
|
628
|
+
if (processedMessages.contains(messageId)) {
|
|
629
|
+
Log.d(TAG, "Duplicate packet, skipping")
|
|
630
|
+
return
|
|
631
|
+
}
|
|
592
632
|
processedMessages.add(messageId)
|
|
593
633
|
|
|
634
|
+
val messageType = MessageType.fromValue(packet.type)
|
|
635
|
+
Log.d(TAG, "Processing packet type: $messageType")
|
|
636
|
+
|
|
594
637
|
// Handle by type
|
|
595
|
-
when (
|
|
638
|
+
when (messageType) {
|
|
596
639
|
MessageType.ANNOUNCE -> handleAnnounce(packet, senderId)
|
|
597
640
|
MessageType.MESSAGE -> handleMessage(packet, senderId)
|
|
598
641
|
MessageType.NOISE_HANDSHAKE -> handleNoiseHandshake(packet, senderId)
|
|
599
642
|
MessageType.NOISE_ENCRYPTED -> handleNoiseEncrypted(packet, senderId)
|
|
600
643
|
MessageType.LEAVE -> handleLeave(senderId)
|
|
601
|
-
else -> {}
|
|
644
|
+
else -> Log.d(TAG, "Unknown message type: ${packet.type}")
|
|
602
645
|
}
|
|
603
646
|
|
|
604
647
|
// Relay if TTL > 0
|
|
@@ -633,6 +676,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
633
676
|
}
|
|
634
677
|
|
|
635
678
|
private fun handleAnnounce(packet: BitchatPacket, senderId: String) {
|
|
679
|
+
Log.d(TAG, "handleAnnounce from $senderId, payload size: ${packet.payload.size}")
|
|
636
680
|
// Parse TLV payload
|
|
637
681
|
var nickname = senderId
|
|
638
682
|
var noisePublicKey: ByteArray? = null
|
|
@@ -656,6 +700,8 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
656
700
|
}
|
|
657
701
|
}
|
|
658
702
|
|
|
703
|
+
Log.d(TAG, "Parsed announce: nickname=$nickname from peer $senderId")
|
|
704
|
+
|
|
659
705
|
peers[senderId] = PeerInfo(
|
|
660
706
|
peerId = senderId,
|
|
661
707
|
nickname = nickname,
|
|
@@ -665,6 +711,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
665
711
|
isVerified = false
|
|
666
712
|
)
|
|
667
713
|
|
|
714
|
+
Log.d(TAG, "Peer added, total peers: ${peers.size}")
|
|
668
715
|
notifyPeerListUpdated()
|
|
669
716
|
}
|
|
670
717
|
|
|
@@ -1041,7 +1088,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1041
1088
|
REQUEST_SYNC(0x08);
|
|
1042
1089
|
|
|
1043
1090
|
companion object {
|
|
1044
|
-
fun fromValue(value: Byte): MessageType? =
|
|
1091
|
+
fun fromValue(value: Byte): MessageType? = values().find { it.value == value }
|
|
1045
1092
|
}
|
|
1046
1093
|
}
|
|
1047
1094
|
|
|
@@ -1054,7 +1101,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1054
1101
|
VERIFY_RESPONSE(0x06);
|
|
1055
1102
|
|
|
1056
1103
|
companion object {
|
|
1057
|
-
fun fromValue(value: Byte): NoisePayloadType? =
|
|
1104
|
+
fun fromValue(value: Byte): NoisePayloadType? = values().find { it.value == value }
|
|
1058
1105
|
}
|
|
1059
1106
|
}
|
|
1060
1107
|
|
package/package.json
CHANGED