dsc-itv2-client 1.0.12 → 1.0.16

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ITV2Client.js +44 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsc-itv2-client",
3
3
  "author": "fajitacat",
4
- "version": "1.0.12",
4
+ "version": "1.0.16",
5
5
  "description": "Reverse engineered DSC ITV2 Protocol Client Library for TL280R Communicator - Monitor and control DSC alarm panels",
6
6
  "main": "src/index.js",
7
7
  "type": "module",
package/src/ITV2Client.js CHANGED
@@ -198,12 +198,18 @@ export class ITV2Client extends EventEmitter {
198
198
  this.session = new ITv2Session(this.integrationId, this.accessCode, logger);
199
199
  }
200
200
 
201
+ // DEBUG: Log all incoming packets
202
+ this._logMinimal(`[DEBUG] RX ${data.length} bytes, state=${this.handshakeState}`);
203
+
201
204
  const parsed = this.session.parsePacket(data);
202
205
  if (!parsed) {
203
- this._log('[Error] Failed to parse packet');
206
+ this._logMinimal('[DEBUG] Failed to parse packet');
204
207
  return;
205
208
  }
206
209
 
210
+ // DEBUG: Log parsed command
211
+ this._logMinimal(`[DEBUG] Parsed cmd=${parsed.command} (${CMD_NAMES[parsed.command] || 'unknown'})`);
212
+
207
213
  // Verbose logging only
208
214
  this._log(`\n[UDP] RX from ${this.panelAddress}:${this.panelPort} (${data.length} bytes)`);
209
215
  this._hexDump(data);
@@ -440,7 +446,32 @@ export class ITV2Client extends EventEmitter {
440
446
  const response = this.session.buildCommandResponseWithAppSeq(appSeq, 0x00);
441
447
  this._sendPacket(response);
442
448
 
443
- this.handshakeState = 'WAITING_TO_SEND_REQUEST_ACCESS';
449
+ // Send our REQUEST_ACCESS immediately (panel doesn't ACK our COMMAND_RESPONSE)
450
+ this._logMinimal('[Handshake] Sending our REQUEST_ACCESS...');
451
+
452
+ // Enable encryption with SEND key
453
+ this.session.sendAesActive = true;
454
+ this.session.sendAesKey = this.session.derivedSendKey;
455
+ this._log(`[Handshake] Encrypting REQUEST_ACCESS with SEND key`);
456
+
457
+ // Build REQUEST_ACCESS based on detected encryption type
458
+ let reqAccessPacket;
459
+ if (this.detectedEncryptionType === 2) {
460
+ this._log(`[Handshake] Using Type 2 REQUEST_ACCESS`);
461
+ reqAccessPacket = this.session.buildRequestAccessType2();
462
+ } else {
463
+ this._log(`[Handshake] Using Type 1 REQUEST_ACCESS`);
464
+ reqAccessPacket = this.session.buildRequestAccessType1();
465
+ }
466
+
467
+ this._sendPacket(reqAccessPacket);
468
+
469
+ // Enable receive encryption
470
+ this.session.receiveAesActive = true;
471
+ this.session.receiveAesKey = this.session.pendingReceiveKey;
472
+ this._log(`[Handshake] Enabled receive encryption`);
473
+
474
+ this.handshakeState = 'SENT_REQUEST_ACCESS';
444
475
  }
445
476
 
446
477
  _handleCommandResponse(parsed) {
@@ -477,6 +508,17 @@ export class ITV2Client extends EventEmitter {
477
508
  // ==================== Notification Handlers ====================
478
509
 
479
510
  _handleLifestyleZoneStatus(parsed) {
511
+ // If we receive encrypted zone data, session is established (even if we missed the final ACK)
512
+ if (this.handshakeState === 'SENT_REQUEST_ACCESS') {
513
+ this.handshakeState = 'ESTABLISHED';
514
+ this._logMinimal(`[Handshake] Session established (Type ${this.detectedEncryptionType} encryption)`);
515
+ this.emit('session:established', {
516
+ encryptionType: this.detectedEncryptionType,
517
+ sendKey: this.session.derivedSendKey?.toString('hex'),
518
+ recvKey: this.session.pendingReceiveKey?.toString('hex')
519
+ });
520
+ }
521
+
480
522
  const data = parsed.commandData;
481
523
 
482
524
  if (data && data.length >= 2) {