Angaza Nexus Keycode Testing

Hi, I am trying to integrate Nexus keycode (only) in my code using small keycode protocol (CONFIG_NEXUS_KEYCODE_USE_SMALL_KEYCODE_PROTOCOL). How to generate or I can get these small tokens to test my application?

@ricehornet Can you guide on the above query ?

1 Like

Anoop, did you try to use the nexus-java library - which can be run on a server running Java?

You can generate a code or sequence of them using that on a desktop and then key it into your app - before that of course you can key it into their desktop app example to make sure everything works:

1 Like

Thanks Vaibhav for the reply. I am not much familiar with java as I am embedded guy. I have bit experience on Pyhton. Can you let me know if any scripts are available on that?

I am able to generate small keycodes (Add days, set days, unlock payg) using python scripts.
Also I have integrated Nexus_Keycode in my existing firmware & which is working well.
Do I need to keep nexus-channel files in my code or I can remove them?

Hi Anoop,

Very sorry for the delay here. I’m glad you were able to generate keycodes with your scripts. I want to let you know that there is already an official set of Python scripts here with examples in the README.

You can keep the Nexus Channel files in your code. You do not need to change any of the source files in the src directory. This will likely cause problems. Instead, update conf_nexus.py and preprocessor flags in the source code will be turned on that will compile out all of the Nexus Channel code from your final binary. Let me know if you are having problems with this.

Eric

Hi Eric,

Thanks for your reply.
I will try to integrate again with all the src files (Channel as well).
I am facing issue in running conf_nexus.py , getting some error of windows-curses but this package is already installed in my system (checked pip list).
Some screenshots are attached.

Hi Eric,
I am able to run conf_nexus.py by commenting #menuconfig as I am working on windows system, following below steps to change user_config.h file:

  1. Able to see config tool upon running conf_nexus.py file.
  2. Load user_config.h
  3. applied my changes in tool.
  4. Saved the file
  5. Not able to see user_config.h as it was before.

I have attached a screenshot of the output user_config.h file.

Please guide on this.

Thanks
Anoop

Anoop,

Thanks for following up about what the problem was.

The format of the output file is unexpected. I wonder if there are some additional problems of using this tool in Windows. I’ve taken an action to look into this further on my side when I get a chance. In the meantime, can you please replace nexus/include/user_config.h with the code below?

This configuration will set your project to use Nexus Keycode only with the “small” keycode configuration and all other default settings enabled. Please let me know if that isn’t working for you.

/**-------------------------------------------
DO NOT MODIFY, AUTOGENERATED CODE.
TO CHANGE THESE VALUES, RUN
`python conf_nexus.py` FROM THE PROJECT ROOT!
---------------------------------------------*/

#define CONFIG_NEXUS_COMMON_ENABLED 1
#define CONFIG_NEXUS_KEYCODE_ENABLED 1
#define CONFIG_NEXUS_KEYCODE_USE_SMALL_KEYCODE_PROTOCOL 1
#define CONFIG_NEXUS_KEYCODE_RATE_LIMITING_ENABLED 1
#define CONFIG_NEXUS_KEYCODE_PROTOCOL_RATE_LIMIT_BUCKET_MAX 128
#define CONFIG_NEXUS_KEYCODE_PROTOCOL_RATE_LIMIT_BUCKET_INITIAL_COUNT 6
#define CONFIG_NEXUS_KEYCODE_PROTOCOL_RATE_LIMIT_REFILL_SECONDS_PER_ATTEMPT 720
#define CONFIG_NEXUS_KEYCODE_ENABLE_FACTORY_QC_CODES 1
#define CONFIG_NEXUS_KEYCODE_PRO_FACTORY_QC_LONG_LIFETIME_MAX 5
#define CONFIG_NEXUS_KEYCODE_PROTOCOL_ENTRY_TIMEOUT_SECONDS 16

Thanks Eric for your response.
I copied this file to my code, and its working. :slight_smile:
I am able to use below keycodes:

  1. Add Credit
  2. Set Credit
  3. Unlock payg
  4. Wipe (don’t know what it does)??
  5. OQC Keycode (1hr)
  6. Short Test Keycode (2 min)

As I understood, We need to save below data in NV memory:

  1. Secret Key (16 bytes)
  2. Serial ID (4 bytes)
  3. Payg State (bool)
  4. Credit value (4 bytes)

Please let me know if I have missed any ??

Rest, I am still working on it & will get back for any doubts.

Thanks
Anoop

Anoop,

Sounds like you are well on your way! The list of keycodes sounds correct. We recommend to make sure that the wipe keycodes are functional, just in case, because they can do some powerful things. There are currently four kinds:

  • NEXUS_KEYCODE_PRO_FULL_WIPE_STATE_TARGET_CREDIT – this will set the PAYG credit to 0. It is identical to a set credit = 0 keycode.
  • NEXUS_KEYCODE_PRO_FULL_WIPE_STATE_TARGET_CREDIT_AND_MASK – this will set the PAYG credit to 0 and also clear the history of the message IDs that have been so far received. Because the message ID history was cleared, this will allow all previously-entered keycodes to be re-entered. Usually this is not used in production.
  • NEXUS_KEYCODE_PRO_FULL_WIPE_STATE_TARGET_MASK_ONLY– this will clear the message ID history only. It will allow previously-entered keycodes to be replayed and the PAYG credit to be added again. Usually this is not used in production.
  • NEXUS_KEYCODE_PRO_FULL_WIPE_CUSTOM_FLAG_RESTRICTED – this will clear a flag that is stored in PAYG NV. It can be set by your code with nx_keycode_set_custom_flag and cleared when this keycode is entered. It is useful when you want your product state to change for some reason that you decide and for that state to be deactivated by a keycode. You could use it for security, for example: when product tampering is detected, the flag would be set, and reset only when an authorized keycode (this reset code) is entered.

The other keycode types (DEMO_CODE, DEVICE_ID_DISPLAY, DEVICE_ID_CONFIRMATION, PASSTHROUGH) are optional.

Regarding the data that you need to save in your NV:

  1. Secret Key (16 bytes) – Correct
  2. Serial ID (4 bytes) – This is actually 6 bytes – see nx_id. The user-facing ID that is returned is represented by just 4 bytes, though (nx_id.device_id).
  3. Payg State (bool) – You might just want this to be is_unlocked – you can otherwise calculate if the unit is enabled or disabled from the credit value. You could also store a special sentinel value for the credit value for unlocked state and remove this altogether.
  4. Credit value (4 bytes) – Correct

By the way, the PAYG NV will require 24 bytes.

By the way, if you have a new question, please post it in the dedicated Nexus forum: https://forum.nexus.angaza.com/

Thanks,

Eric

Thanks you so much Eric for your response!

I will surely use “https://forum.nexus.angaza.com/” forum to clarify my further doubts.