Skip to content

Commit 0563b78

Browse files
authored
Rf improvement HEADLESS MODE (#2224)
* Fix buffers and clean up SMB/NTLM responder code Adjust buffer sizes and validation, set TFT defaults, and refactor the SMB/NTLM responder for clarity and safety. Changes include: - include/globals.h: increase timeStr to 16 to avoid truncation. - src/core/settings.cpp: remove redundant >= 0 check for key delay validation. - src/core/utils.cpp: enlarge local sprintf buffer for time formatting. - src/modules/badusb_ble: set default TFT color to TFT_WHITE and ensure prints use a valid color. - src/modules/wifi/responder.cpp: reorder includes, normalize whitespace/formatting, and refactor many SMB/NTLM routines (NetBIOS name encode, NTLM Type 2 builder, SMB1/SMB2 negotiate handlers, NTLM hash extraction, UI updates). The NTLM Type 2 assembly and AV pair handling were rewritten for clarity, offsets/lengths and NBSS length calculations were made explicit, and I/O (SD save, serial prints) preserved. Overall these changes aim to prevent buffer issues, provide sane defaults for display calls, and improve maintainability and correctness of the SMB/NTLM responder logic. * Fix Fix compilation issue * Add headless mode to RCSwitch_Read Introduce a new bool headless parameter (default false) to RCSwitch_Read and propagate it to the header and implementation. When headless is true, UI operations (drawMainBorder, TFT prints, and display_info) are skipped so RF reads can be performed without touching the display. Update JS bindings to call RCSwitch_Read(..., headless=true) for headless operation when invoked from JavaScript.
1 parent 44bcd3c commit 0563b78

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/modules/bjs_interpreter/subghz_js.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ JSValue native_subghzRead(JSContext *ctx, JSValue *this_val, int argc, JSValue *
7070
if (argc > 0 && JS_IsNumber(ctx, argv[0])) {
7171
int t;
7272
JS_ToInt32(ctx, &t, argv[0]);
73-
r = RCSwitch_Read(bruceConfigPins.rfFreq, t); // custom timeout
73+
r = RCSwitch_Read(bruceConfigPins.rfFreq, t, false, true); // headless mode for JS
7474
} else {
75-
r = RCSwitch_Read(bruceConfigPins.rfFreq, 10);
75+
r = RCSwitch_Read(bruceConfigPins.rfFreq, 10, false, true);
7676
}
7777
return JS_NewString(ctx, r.c_str());
7878
}
@@ -82,9 +82,9 @@ JSValue native_subghzReadRaw(JSContext *ctx, JSValue *this_val, int argc, JSValu
8282
if (argc > 0 && JS_IsNumber(ctx, argv[0])) {
8383
int t;
8484
JS_ToInt32(ctx, &t, argv[0]);
85-
r = RCSwitch_Read(bruceConfigPins.rfFreq, t, true); // custom timeout
85+
r = RCSwitch_Read(bruceConfigPins.rfFreq, t, true, true); // raw + headless for JS
8686
} else {
87-
r = RCSwitch_Read(bruceConfigPins.rfFreq, 10, true);
87+
r = RCSwitch_Read(bruceConfigPins.rfFreq, 10, true, true);
8888
}
8989
return JS_NewString(ctx, r.c_str());
9090
}

src/modules/rf/rf_scan.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ String rf_scan(float start_freq, float stop_freq, int max_loops) {
712712
return out;
713713
}
714714

715-
String RCSwitch_Read(float frequency, int max_loops, bool raw) {
715+
String RCSwitch_Read(float frequency, int max_loops, bool raw, bool headless) {
716716
RCSwitch rcswitch = RCSwitch();
717717
RfCodes received;
718718

@@ -721,10 +721,12 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) {
721721
char hexString[64];
722722

723723
RestartRec:
724-
drawMainBorder();
725-
tft.setCursor(10, 28);
726-
tft.setTextSize(FP);
727-
tft.println("Waiting for a " + String(frequency) + " MHz " + "signal.");
724+
if (!headless) {
725+
drawMainBorder();
726+
tft.setCursor(10, 28);
727+
tft.setTextSize(FP);
728+
tft.println("Waiting for a " + String(frequency) + " MHz " + "signal.");
729+
}
728730

729731
// init receive
730732
if (!initRfModule("rx", frequency)) return "";
@@ -765,7 +767,7 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) {
765767
// Serial.println(received.data);
766768
decimalToHexString(received.key, hexString);
767769

768-
display_info(received, 1, raw);
770+
if (!headless) display_info(received, 1, raw);
769771
}
770772
rcswitch.resetAvailable();
771773
}
@@ -790,7 +792,7 @@ String RCSwitch_Read(float frequency, int max_loops, bool raw) {
790792
received.filepath = "unsaved";
791793
received.data = "";
792794

793-
display_info(received, 1, raw);
795+
if (!headless) display_info(received, 1, raw);
794796
}
795797
// ResetSignal:
796798
rcswitch.resetAvailable();

src/modules/rf/rf_scan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ void display_signal_data(RfCodes received);
8888
bool RCSwitch_SaveSignal(float frequency, RfCodes codes, bool raw, char *key, bool autoSave = false);
8989

9090
String rf_scan(float start_freq, float stop_freq, int max_loops = -1);
91-
String RCSwitch_Read(float frequency = 0, int max_loops = -1, bool raw = false);
91+
String RCSwitch_Read(float frequency = 0, int max_loops = -1, bool raw = false, bool headless = false);
9292

9393
#endif

0 commit comments

Comments
 (0)