Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Source routing #4

Merged
merged 10 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: CI

on:
push:
pull_request:

jobs:
checks:
Expand All @@ -14,15 +13,11 @@ jobs:
with:
node-version-file: 'package.json'

- uses: biomejs/setup-biome@v2
with:
version: latest

- run: npm ci

- run: npm run build:prod

- run: biome ci
- run: npm run check:ci

tests:
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# ZoH
*.save
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,20 @@ Some quick guidelines to keep the codebase maintainable:
- [ ] FULLENCR & auth tag checking codepaths
- [x] Encoding/decoding of ZigBee NWK APS frames
- [x] Network forming
- [~] Network state saving (de facto backups)
- [ ] Deal with frame counters (avoiding too many writes, but preventing mismatch issues)
- [ ] Runtime changing of network parameters (ZDO channel, PAN ID...)
- [~] Joining/Rejoining
- [x] Network state saving (de facto backups)
- [x] Joining/Rejoining
- [x] APS TC link key update mechanism (global)
- [x] Direct child router
- [x] Direct child end device
- [ ] Nested device
- [x] Nested device
- [x] Indirect transmission mechanism
- _Crude implementation_
- [ ] Deal with devices lying on `rxOnWhenIdle` property (bad firmware, resulting in transmission type mismatch)
- [ ] Routing
- [ ] Source routing
- [x] Source routing
- [?] Regular routing
- [ ] Coordinator binding
- [ ] InterPAN / Touchlink
- [ ] LQI reporting in messages
- [ ] LQI reporting in messages (currently showing RSSI - in dBm)
- [ ] Install codes
- [?] APS APP link keys
- [ ] R23 (need reference sniffs...)
Expand Down
13 changes: 11 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
"recommended": true,
"style": {
"noNonNullAssertion": "off",
"noParameterAssign": "off"
"noParameterAssign": "off",
"useNamingConvention": {
"level": "error",
"options": {
"strictCase": false,
"requireAscii": true,
"enumMemberCase": "CONSTANT_CASE"
}
}
},
"correctness": {
"noUnusedImports": "error",
Expand All @@ -39,7 +47,8 @@
"noReExportAll": "error"
},
"suspicious": {
"noConstEnum": "off"
"noConstEnum": "off",
"useAwait": "error"
}
}
},
Expand Down
592 changes: 262 additions & 330 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"test": "vitest run --config ./test/vitest.config.mts",
"test:cov": "vitest run --config ./test/vitest.config.mts --coverage",
"bench": "vitest bench --run --config ./test/vitest.config.mts",
"check": "npx @biomejs/biome check --write .",
"check": "biome check --write .",
"check:ci": "biome check .",
"clean": "rm -rf dist *.tsbuildinfo",
"dev:cli": "node dist/dev/cli.js"
},
Expand All @@ -31,10 +32,10 @@
"homepage": "https://github.com/Nerivec/zigbee-on-host#readme",
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/node": "^22.10.7",
"@vitest/coverage-v8": "^3.0.2",
"serialport": "^12.0.0",
"@types/node": "^22.13.4",
"@vitest/coverage-v8": "^3.0.6",
"serialport": "^13.0.0",
"typescript": "^5.7.3",
"vitest": "^3.0.2"
"vitest": "^3.0.6"
}
}
14 changes: 7 additions & 7 deletions src/dev/minimal-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class MinimalAdapter {
this.closing = false;

if (sendMACToZEP) {
this.driver.on("MAC_FRAME", (payload, rssi) => {
this.driver.on("macFrame", (payload, rssi) => {
const wsZEPFrame = createWiresharkZEPFrame(this.driver.netParams.channel, 1, 0, rssi ?? 0, this.nextWiresharkSeqNum(), payload);

this.wiresharkSocket.send(wsZEPFrame, this.wiresharkPort, this.wiresharkAddress);
Expand Down Expand Up @@ -182,7 +182,7 @@ export class MinimalAdapter {
* Handle port closing
* @param err A boolean for Socket, an Error for serialport
*/
private async onPortClose(error: boolean | Error): Promise<void> {
private onPortClose(error: boolean | Error): void {
if (error) {
logger.error("Port closed unexpectedly.", NS);
} else {
Expand All @@ -194,7 +194,7 @@ export class MinimalAdapter {
* Handle port error
* @param error
*/
private async onPortError(error: Error): Promise<void> {
private onPortError(error: Error): void {
logger.error(`Port ${error}`, NS);

throw new Error("Port error");
Expand Down Expand Up @@ -223,10 +223,10 @@ export class MinimalAdapter {
// allow joins on start for 254 seconds
this.driver.allowJoins(0xfe, true);

this.driver.on("FRAME", this.onFrame.bind(this));
this.driver.on("DEVICE_JOINED", this.onDeviceJoined.bind(this));
this.driver.on("DEVICE_REJOINED", this.onDeviceRejoined.bind(this));
this.driver.on("DEVICE_LEFT", this.onDeviceLeft.bind(this));
this.driver.on("frame", this.onFrame.bind(this));
this.driver.on("deviceJoined", this.onDeviceJoined.bind(this));
this.driver.on("deviceRejoined", this.onDeviceRejoined.bind(this));
this.driver.on("deviceLeft", this.onDeviceLeft.bind(this));
}

public async stop(): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/endpoints.ts → src/drivers/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const MAC_CAPABILITIES =
((0 << 5) & 0x20) | // reserved2
((0 << 6) & 0x40) | // securityCapability
((1 << 7) & 0x80); // allocateAddress
const MANUFACTURER_CODE = 0xffff;
const MANUFACTURER_CODE = 0xc5a0; // CONNECTIVITY_STANDARDS_ALLIANCE
const SERVER_MASK =
(1 & 0x01) | // primaryTrustCenter
((0 << 1) & 0x02) | // backupTrustCenter
Expand Down Expand Up @@ -97,7 +97,7 @@ export function encodeCoordinatorDescriptors(eui64: bigint): [address: Buffer, n
offset += 1;
node.writeUInt16LE(MANUFACTURER_CODE, offset);
offset += 2;
node.writeUInt8(0xff, offset);
node.writeUInt8(0x7f, offset);
offset += 1;
node.writeUInt16LE(ZigbeeMACConsts.FRAME_MAX_SIZE, offset);
offset += 2;
Expand Down
Loading