From e93e52702e31813318ecb549f4714151d8f7da0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BB=D0=B8=D0=BC=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9=20=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Sun, 8 Oct 2023 17:43:30 +0300 Subject: [PATCH] XNova CRYPT,SHAREDSECRET,PROTECTED_PINS,PULSEPIN12 --- build-flags/build_flags_mega2560-optiboot | 1 + compiled/DUE_16u2_reflash/reflash16u2DUE.bat | 16 +++++ compiled/lighthub21/ListSerialPorts.bat | 1 + compiled/lighthub21/{ => unlock}/unlock.bat | 0 compiled/lighthub21/upload.bat | 2 +- lighthub/abstractout.h | 2 +- lighthub/colorchannel.cpp | 5 +- lighthub/colorchannel.h | 2 +- lighthub/item.cpp | 71 +++++++++++--------- lighthub/item.h | 6 +- lighthub/main.cpp | 56 +++++++++++++++ lighthub/main.h | 2 + lighthub/modules/out_ac.cpp | 2 +- lighthub/modules/out_ac.h | 2 +- lighthub/modules/out_counter.cpp | 2 +- lighthub/modules/out_counter.h | 2 +- lighthub/modules/out_dmx.h | 2 +- lighthub/modules/out_mercury.cpp | 3 +- lighthub/modules/out_mercury.h | 2 +- lighthub/modules/out_modbus.cpp | 2 +- lighthub/modules/out_modbus.h | 2 +- lighthub/modules/out_motor.cpp | 4 +- lighthub/modules/out_motor.h | 2 +- lighthub/modules/out_multivent.cpp | 2 +- lighthub/modules/out_multivent.h | 2 +- lighthub/modules/out_pid.cpp | 2 +- lighthub/modules/out_pid.h | 2 +- lighthub/modules/out_relay.cpp | 2 +- lighthub/modules/out_relay.h | 2 +- lighthub/modules/out_uartbridge.cpp | 2 +- lighthub/modules/out_uartbridge.h | 2 +- lighthub/options.h | 14 ++++ lighthub/utils.cpp | 19 ++++-- lighthub/utils.h | 3 +- 34 files changed, 173 insertions(+), 68 deletions(-) create mode 100644 compiled/DUE_16u2_reflash/reflash16u2DUE.bat create mode 100644 compiled/lighthub21/ListSerialPorts.bat rename compiled/lighthub21/{ => unlock}/unlock.bat (100%) diff --git a/build-flags/build_flags_mega2560-optiboot b/build-flags/build_flags_mega2560-optiboot index 7f69bf2..604ae4c 100644 --- a/build-flags/build_flags_mega2560-optiboot +++ b/build-flags/build_flags_mega2560-optiboot @@ -15,6 +15,7 @@ -DPID_DISABLE -DOTA -DMOTOR_DISABLE +-DMULTIVENT_DISABLE #-DWiz5100 -DARDUINO_OTA_MDNS_DISABLE -DMDNS_ENABLE diff --git a/compiled/DUE_16u2_reflash/reflash16u2DUE.bat b/compiled/DUE_16u2_reflash/reflash16u2DUE.bat new file mode 100644 index 0000000..4e8cc9d --- /dev/null +++ b/compiled/DUE_16u2_reflash/reflash16u2DUE.bat @@ -0,0 +1,16 @@ +REM fetch DeviceID of Arduino Port from WMI Service +FOR /f "tokens=* skip=1" %%a IN ('wmic PATH Win32_SerialPort Where "Caption LIKE '%%Arduino Uno%%'" get DeviceID') DO ( + SET COMX=%%a + GOTO exit1 +) + +REM Arduino Due Programming Port not exist +GOTO error_comport + +:exit1 + +REM remove blank +SET COMPORT=%COMX: =% + + +..\tools\win\tool-avrdude\avrdude -C ..\tools\win\tool-avrdude\avrdude.conf -c arduino -P %COMPORT% -b 19200 -p m16u2 -vvv -U flash:w:16u2.hex:i diff --git a/compiled/lighthub21/ListSerialPorts.bat b/compiled/lighthub21/ListSerialPorts.bat new file mode 100644 index 0000000..121c89f --- /dev/null +++ b/compiled/lighthub21/ListSerialPorts.bat @@ -0,0 +1 @@ +wmic PATH Win32_SerialPort get DeviceID diff --git a/compiled/lighthub21/unlock.bat b/compiled/lighthub21/unlock/unlock.bat similarity index 100% rename from compiled/lighthub21/unlock.bat rename to compiled/lighthub21/unlock/unlock.bat diff --git a/compiled/lighthub21/upload.bat b/compiled/lighthub21/upload.bat index 49098ce..e7c91e1 100644 --- a/compiled/lighthub21/upload.bat +++ b/compiled/lighthub21/upload.bat @@ -28,7 +28,7 @@ REM bin file exist? IF NOT EXIST "%BINFILE%" GOTO error_binfile REM fetch DeviceID of Arduino Due Programming Port from WMI Service -FOR /f "tokens=* skip=1" %%a IN ('wmic PATH Win32_SerialPort Where "Caption LIKE '%%USB%%'" get DeviceID') DO ( +FOR /f "tokens=* skip=1" %%a IN ('wmic PATH Win32_SerialPort Where "Caption LIKE '%%Due%%'" get DeviceID') DO ( SET COMX=%%a GOTO exit1 ) diff --git a/lighthub/abstractout.h b/lighthub/abstractout.h index a87cd0a..504375d 100644 --- a/lighthub/abstractout.h +++ b/lighthub/abstractout.h @@ -8,7 +8,7 @@ class chPersistent {}; class abstractOut : public abstractCh{ public: abstractOut(Item * _item):abstractCh(){item=_item;}; - virtual int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) =0; + virtual int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) =0; virtual int isActive(); virtual bool isAllowed(itemCmd cmd){return true;}; virtual itemCmd getDefaultOnVal(){return itemCmd().Percents255(255);}; diff --git a/lighthub/colorchannel.cpp b/lighthub/colorchannel.cpp index 36e7ff1..33edc9c 100644 --- a/lighthub/colorchannel.cpp +++ b/lighthub/colorchannel.cpp @@ -44,7 +44,7 @@ return val; } */ -int colorChannel::Ctrl(itemCmd cmd, char* subItem, bool toExecute) +int colorChannel::Ctrl(itemCmd cmd, char* subItem, bool toExecute, bool authorized) { debugSerial<=0) + vol=cmd.getPercents(); + if (vol=0) { cmd.setPercents(INIT_VOLUME); cmd.saveItem(item); diff --git a/lighthub/colorchannel.h b/lighthub/colorchannel.h index 78c4bcb..d1f163c 100644 --- a/lighthub/colorchannel.h +++ b/lighthub/colorchannel.h @@ -14,7 +14,7 @@ public: if (iaddr<0) iaddr=-iaddr; numArgs = item->getArgCount(); // and how many addresses is configured }; - int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override; + int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized=false) override; int getDefaultStorageType()override; virtual int PixelCtrl(itemCmd cmd, char* subItem=NULL, bool show=true ) =0; short getChannelAddr(short n =0); diff --git a/lighthub/item.cpp b/lighthub/item.cpp index d74b603..2bf650a 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -696,7 +696,7 @@ st.setSuffix(suffixCode); default:; } - return Ctrl(st,subItem); + return Ctrl(st,subItem,true,authorized); } case CMD_UP: case CMD_DN: @@ -704,13 +704,13 @@ st.setSuffix(suffixCode); itemCmd Par0 = getNumber((char **) &payload); Par0.Cmd(cmd); Par0.setSuffix(suffixCode); - return Ctrl(Par0, subItem); + return Ctrl(Par0, subItem,true,authorized); } default: //some known command { int32_t intParam = getInt((char **) &payload); if (intParam) st.Int(intParam); - return Ctrl(st, subItem); + return Ctrl(st,NULL, true, authorized); } } //ctrl return 0; @@ -719,7 +719,7 @@ return 0; // Recursive function with small stack consumption // if cmd defined - execute Ctrl for any group members recursively // else performs Activity check for group members and return true if any member is active -bool digGroup (aJsonObject *itemArr, itemCmd *cmd, char* subItem) +bool digGroup (aJsonObject *itemArr, itemCmd *cmd, char* subItem, bool authorized) { if (!itemArr || itemArr->type!=aJson_Array) return false; // Iterate across array of names aJsonObject *i = itemArr->child; @@ -731,13 +731,13 @@ bool digGroup (aJsonObject *itemArr, itemCmd *cmd, char* subItem) if (nextItem && nextItem->type == aJson_Array) //nextItem is correct item { Item it(nextItem); - if (cmd && it.isValid()) it.Ctrl(*cmd,subItem,false); //Execute (non recursive) + if (cmd && it.isValid()) it.Ctrl(*cmd,subItem,false,authorized); //Execute (non recursive) //Retrieve itemType aJsonObject * itemtype = aJson.getArrayItem(nextItem,0); if (itemtype && itemtype->type == aJson_Int && itemtype->valueint == CH_GROUP) { //is Group aJsonObject * itemSubArray = aJson.getArrayItem(nextItem,1); - short res = digGroup(itemSubArray,cmd,subItem); + short res = digGroup(itemSubArray,cmd,subItem,authorized); if (!cmd && res) { configLocked--; @@ -769,7 +769,7 @@ aJsonObject *timestampObj = aJson.getArrayItem(itemArr, I_TIMESTAMP); return 0; } -int Item::scheduleOppositeCommand(itemCmd cmd) +int Item::scheduleOppositeCommand(itemCmd cmd,bool authorized) { itemCmd nextCmd=cmd; @@ -798,11 +798,11 @@ int Item::scheduleOppositeCommand(itemCmd cmd) default: return 0; } debugSerial<valueint = millis()+cmd.getInt(); timestampObj->type = aJson_Int; - timestampObj->subtype=cmd.getCmd(); + timestampObj->subtype=(cmd.getCmd() & 0xF) | ((authorized?1:0)<<4); + debugSerial<valueint<type == aJson_Array && operation) { chActive=(isActive()>0); - digGroup(itemArg,&cmd,subItem); + digGroup(itemArg,&cmd,subItem,authorized); } res=1; @@ -1046,7 +1048,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized case CMD_RESTORE: // individual for group members switch (t = getCmd()) { case CMD_HALT: //previous command was HALT ? - if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd); + if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); debugSerial << F("CTRL: Restored from:") << t << endl; cmd.loadItemDef(this); cmd.Cmd(CMD_ON); //turning on @@ -1060,7 +1062,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized case CMD_XOFF: // individual for group members switch (t = getCmd()) { case CMD_XON: //previous command was CMD_XON ? - if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd); + if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); debugSerial << F("CTRL: Turned off from:") << t << endl; cmd.Cmd(CMD_OFF); //turning Off status2Send |= FLAG_COMMAND | FLAG_SEND_IMMEDIATE; @@ -1077,7 +1079,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized { if (chActive == -1) chActive=(isActive()>0); - if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd); + if ((suffixCode==S_CMD) && cmd.isValue() && (!chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); if (!chActive) //if channel was'nt active before CMD_XON @@ -1104,7 +1106,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized break; case CMD_HALT: if (chActive == -1) chActive=(isActive()>0); - if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd); + if ((suffixCode==S_CMD) && cmd.isValue() && (chActive || isScheduled())) scheduleOppositeCommand(cmd,authorized); if (chActive) //if channel was active before CMD_HALT /// HERE bug - if cmd == On but 0 = active { cmd.Cmd(CMD_OFF); @@ -1147,7 +1149,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized } else // Fast track for commands to subitems { - if (driver) return driver->Ctrl(cmd,subItem,toExecute); + if (driver) return driver->Ctrl(cmd,subItem,toExecute,authorized); ///// return 0; } } @@ -1160,7 +1162,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized switch (t = getCmd()) { case CMD_HALT: //previous command was HALT ? if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd); + scheduleOppositeCommand(cmd,authorized); debugSerial << F("CTRL: Restored from:") << t << endl; cmd.loadItemDef(this); @@ -1178,7 +1180,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized switch (t = getCmd()) { case CMD_XON: //previous command was CMD_XON ? if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd); + scheduleOppositeCommand(cmd,authorized); debugSerial << F("CTRL: Turned off from:") << t << endl; toExecute=true; cmd.Cmd(CMD_OFF); //turning Off @@ -1195,7 +1197,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized if (!getFlag(FLAG_DISABLED)) { if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (!chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd); + scheduleOppositeCommand(cmd,authorized); if (!chActive) //if channel was'nt active before CMD_XON { @@ -1222,7 +1224,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized case CMD_HALT: if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd); + scheduleOppositeCommand(cmd,authorized); if (chActive) //if channel was active before CMD_HALT { cmd.Cmd(CMD_OFF); @@ -1247,7 +1249,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized if (getCmd() == CMD_HALT) return 3; //Halted, ignore OFF if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd); + scheduleOppositeCommand(cmd,authorized); status2Send |= FLAG_COMMAND | FLAG_SEND_IMMEDIATE; toExecute=true; break; @@ -1255,7 +1257,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized case CMD_ON: if ((suffixCode==S_CMD) && allowRecursion && cmd.isValue() && (!chActive || isScheduled())) //invoked not as group part, delayed, non Active or re-schedule - scheduleOppositeCommand(cmd); + scheduleOppositeCommand(cmd,authorized); if (!cmd.isChannelCommand()) //Command for driver, not for whole channel { @@ -1298,7 +1300,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem, bool allowRecursion, bool authorized toExecute=true; //debugSerial<isAllowed(cmd)) && (!getFlag(FLAG_FREEZED))) if (driver) //New style modular code { - res = driver->Ctrl(cmd, subItem, toExecute); + res = driver->Ctrl(cmd, subItem, toExecute,authorized); if (driver->getChanType() == CH_THERMO) status2Send |= FLAG_SEND_IMMEDIATE; //if (res==-1) status2Send=0; ///////not working if (status2Send & FLAG_FLAGS) res =1; //ENABLE & DISABLE processed by core @@ -1361,6 +1363,7 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED))) short iaddr=getArg(); short icmd =cmd.getCmd(); + if (!authorized && isProtectedPin(iaddr)) {errorSerial<isAllowed(cmd)) && (!getFlag(FLAG_FREEZED))) */ debugSerial<subtype; + uint8_t cmd = timestampObj->subtype & 0xF; + bool authorized = timestampObj->subtype & 0x10; int32_t remain = (uint32_t) timestampObj->valueint - (uint32_t)millis(); if (cmd) { @@ -1588,9 +1593,9 @@ if (timestampObj) errorSerial<subtype=0; + Ctrl(itemCmd(ST_VOID,cmd),NULL,true,authorized); + //timestampObj->subtype=0; //// } } } diff --git a/lighthub/item.h b/lighthub/item.h index ebdbd20..2b8fda3 100644 --- a/lighthub/item.h +++ b/lighthub/item.h @@ -103,7 +103,7 @@ extern aJsonObject *items; extern short thermoSetCurTemp(char *name, float t); int txt2cmd (char * payload); -bool digGroup (aJsonObject *itemArr, itemCmd *cmd = NULL, char* subItem = NULL); +bool digGroup (aJsonObject *itemArr, itemCmd *cmd = NULL, char* subItem = NULL, bool authorized = false); class Item { public: @@ -148,8 +148,8 @@ class Item inline int On (){return Ctrl(itemCmd(ST_VOID,CMD_ON));}; inline int Off(){return Ctrl(itemCmd(ST_VOID,CMD_OFF));}; inline int Toggle(){return Ctrl(itemCmd(ST_VOID,CMD_TOGGLE));}; - int scheduleCommand(itemCmd cmd); - int scheduleOppositeCommand(itemCmd cmd); + int scheduleCommand(itemCmd cmd, bool authorized); + int scheduleOppositeCommand(itemCmd cmd,bool authorized); int isScheduled(); protected: diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 0f72194..354e2cc 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -98,6 +98,10 @@ lan_status lanStatus = INITIAL_STATE; const char configserver[] PROGMEM = CONFIG_SERVER; const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV); +#ifdef CRYPT +char cryptoKey[] = QUOTE(SHAREDSECRET); +#endif + #if defined(__SAM3X8E__) UID UniqueID; #endif @@ -2046,6 +2050,56 @@ int16_t attachTimer(double microseconds, timerCallback callback, const char* Tim } #endif +#if defined(__SAM3X8E__) && defined (PULSEPIN12) +#define MATURA_PULSE 100 +#define MATURA_PERIOD 2500 + +void maturaTimerHandler(void){ } + +volatile int maturaTimerNumber = -1; +int16_t attachMaturaTimer() +{ + if (maturaTimerNumber==-1) + { + DueTimerInterrupt dueTimerInterrupt = DueTimerInterrupt(8); + dueTimerInterrupt.attachInterruptInterval(MATURA_PERIOD*1000, maturaTimerHandler); + maturaTimerNumber = dueTimerInterrupt.getTimerNumber(); + TC_SetRB(TC2,2,REG_TC2_RC2 - (REG_TC2_RC2 / MATURA_PERIOD * MATURA_PULSE)); + REG_TC2_CMR2 |= TC_CMR_BCPB_SET | TC_CMR_BCPC_CLEAR | TC_CMR_EEVT_XC0; // on CTR==A -> SET; on CTR == C - CLEAR pin, enable TIOB as out + } + debugSerial< SET; on CTR == C - CLEAR pin, enable TIOB as out + + + + //REG_PIOD_WPMR = PIO_WPMR_WPKEY(0x50494f) | 1; //Write protect whole IOD + return maturaTimerNumber; +} +#else +int16_t attachMaturaTimer(){}; +#endif + #if defined(WIFI_ENABLE) #if defined (ESP32) void WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) @@ -2804,6 +2858,8 @@ configLocked++; #if defined(__SAM3X8E__) && defined (TIMER_INT) // Interval in microsecs attachTimer(TIMER_CHECK_INPUT * 1000, TimerHandler, "ITimer"); + attachMaturaTimer(); + #endif configLocked--; } diff --git a/lighthub/main.h b/lighthub/main.h index 91494ab..9918f17 100644 --- a/lighthub/main.h +++ b/lighthub/main.h @@ -319,4 +319,6 @@ void printCurentLanConfig(); void onMQTTConnect(); +int16_t attachMaturaTimer(); + //void printFreeRam(); diff --git a/lighthub/modules/out_ac.cpp b/lighthub/modules/out_ac.cpp index 444651d..acd63df 100644 --- a/lighthub/modules/out_ac.cpp +++ b/lighthub/modules/out_ac.cpp @@ -433,7 +433,7 @@ debugSerial<> "); return true; }; -int out_AC::Ctrl(itemCmd cmd, char* subItem , bool toExecute) +int out_AC::Ctrl(itemCmd cmd, char* subItem , bool toExecute, bool authorized) { //char s_mode[10]; char s_speed[10]; diff --git a/lighthub/modules/out_ac.h b/lighthub/modules/out_ac.h index 17562c1..0e3d998 100644 --- a/lighthub/modules/out_ac.h +++ b/lighthub/modules/out_ac.h @@ -44,7 +44,7 @@ public: int isActive() override; int getChanType() override; int getDefaultStorageType(){return ST_FLOAT_CELSIUS;}; - int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override; + int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override; void SubmitParameters(const char * name, itemCmd value); protected: diff --git a/lighthub/modules/out_counter.cpp b/lighthub/modules/out_counter.cpp index f9286b9..465cc91 100644 --- a/lighthub/modules/out_counter.cpp +++ b/lighthub/modules/out_counter.cpp @@ -69,7 +69,7 @@ uint32_t timer = item->getExt(); }; -int out_counter::Ctrl(itemCmd cmd, char* subItem, bool toExecute) +int out_counter::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized) { debugSerial<driverStatus == CST_FAILED) return 0; if (!getConfig()) return 0; switch (Status()) @@ -474,7 +475,7 @@ int out_Mercury::getChanType() //!Control unified item -int out_Mercury::Ctrl(itemCmd cmd, char* subItem, bool toExecute) +int out_Mercury::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized) { if (!store) return -1; diff --git a/lighthub/modules/out_mercury.h b/lighthub/modules/out_mercury.h index 70c862e..4d9c0f5 100644 --- a/lighthub/modules/out_mercury.h +++ b/lighthub/modules/out_mercury.h @@ -49,7 +49,7 @@ public: int Stop() override; int Status() override; int getChanType() override; - int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override; + int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override; int getDefaultStorageType(){return ST_INT32;}; diff --git a/lighthub/modules/out_modbus.cpp b/lighthub/modules/out_modbus.cpp index c25658b..1810fff 100644 --- a/lighthub/modules/out_modbus.cpp +++ b/lighthub/modules/out_modbus.cpp @@ -856,7 +856,7 @@ else return 0; // 2. custom textual subItem // 3. non-standard numeric suffix Code equal param id -int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute) +int out_Modbus::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized) { if (!store) return -1; diff --git a/lighthub/modules/out_modbus.h b/lighthub/modules/out_modbus.h index 64e0a3d..0a1b9dc 100644 --- a/lighthub/modules/out_modbus.h +++ b/lighthub/modules/out_modbus.h @@ -39,7 +39,7 @@ public: int Stop() override; int Status() override; int getChanType() override; - int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override; + int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override; int getDefaultStorageType(){return ST_INT32;}; //int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override; diff --git a/lighthub/modules/out_motor.cpp b/lighthub/modules/out_motor.cpp index 79f8db8..546daaa 100644 --- a/lighthub/modules/out_motor.cpp +++ b/lighthub/modules/out_motor.cpp @@ -151,7 +151,7 @@ else if (curPos>=0) else dif=targetPos-255/2; // Have No feedback -debugSerial<")<")<pid || (Status() != CST_INITIALIZED)) return 0; int suffixCode = cmd.getSuffix(); diff --git a/lighthub/modules/out_pid.h b/lighthub/modules/out_pid.h index 804f257..8372abe 100644 --- a/lighthub/modules/out_pid.h +++ b/lighthub/modules/out_pid.h @@ -34,7 +34,7 @@ public: int isActive() override; int getChanType() override; int getDefaultStorageType(){return ST_FLOAT;}; - int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override; + int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override; void alarm(bool); diff --git a/lighthub/modules/out_relay.cpp b/lighthub/modules/out_relay.cpp index 475aca8..b4582ab 100644 --- a/lighthub/modules/out_relay.cpp +++ b/lighthub/modules/out_relay.cpp @@ -143,7 +143,7 @@ bool needToOff = isTimeOver(timer,millis(),period*val/255); }; -int out_relay::Ctrl(itemCmd cmd, char* subItem, bool toExecute) +int out_relay::Ctrl(itemCmd cmd, char* subItem, bool toExecute,bool authorized) { debugSerial<isActive(); //bool toExecute = (chActive>0); diff --git a/lighthub/modules/out_uartbridge.h b/lighthub/modules/out_uartbridge.h index df403a4..f54b911 100644 --- a/lighthub/modules/out_uartbridge.h +++ b/lighthub/modules/out_uartbridge.h @@ -65,7 +65,7 @@ public: int Stop() override; int Status() override; int getChanType() override; - int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true) override; + int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override; int getDefaultStorageType(){return ST_INT32;}; //int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override; diff --git a/lighthub/options.h b/lighthub/options.h index cfc7e86..112e0c9 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -361,4 +361,18 @@ #define minimalMemory 200 #else #define minimalMemory 1200 +#endif + +#if not defined PROTECTED_PINS +#define PROTECTED_PINS +#endif + +const short protectedPins[]={PROTECTED_PINS}; +#define protectedPinsNum (sizeof(protectedPins)/sizeof(short)) + +#ifdef CRYPT +#if not defined SHAREDSECRET +#define SHAREDSECRET "12345678" +#endif + #endif \ No newline at end of file diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index 52f25c4..e3b1b12 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -99,12 +99,12 @@ void SetAddr(char *out, uint8_t *addr) { // chan is pointer to pointer to string // Function return first retrived integer and move pointer to position next after ',' -int getInt(char **chan) { +long getInt(char **chan) { if (chan && *chan && **chan) { //Skip non-numeric values while (**chan && !(**chan == '-' || (**chan >= '0' && **chan<='9'))) *chan += 1; - int ch = atoi(*chan); + long ch = atol(*chan); //Move pointer to next element (after ,) *chan = strchr(*chan, ','); @@ -362,7 +362,8 @@ uint32_t ReadUniqueID( uint32_t * pdwUniqueID ) return *(uint32_t *)(IFLASH1_ADDR + 128); // dont remove: SAM defect workaround - MPU dont leave Unique Identifier mode until read flash out UID of range - +#else +return 0; #endif } //#pragma optimize("", on) @@ -814,13 +815,12 @@ bool getPinVal(uint8_t pin) { return (0!=(*portOutputRegister( digitalPinToPort(pin) ) & digitalPinToBitMask(pin))); } -#ifdef CRYPT +#ifdef CRYPT #define HASH_SIZE 32 SHA256 sha256; extern uint32_t cryptoSalt; -//extern -const char cryptoKey[] ="12345678"; +extern char cryptoKey[]; bool checkToken(char * token, char * data) { @@ -864,5 +864,12 @@ bool checkToken(char * token, char * data) {return true;} #endif + bool isProtectedPin(short pin) + { + for (short i=0; i