# nRF9160 (4G module)

## Getting started

Make sure you have installed all the necessary software. Like what has been told in [this part of the documentation.](https://redbullettooling.gitbook.io/keyvilboard-apt/downloading-and-installing-relevant-files#windows) You can also install all software located within: "Crypsis\Crypsis Hardware\Radio\DEPENDENCIES" **Modem should allready be updated.**

Once you have done this connect the hardware in the following manner.

1. Start off by connecting the Edge Connect Cable to the Crypsis Radio board in the following manner

![Make sure the Edge Connect cable is facing down so that you see this side. Also make sure the red wire is on the same side.](https://1957962940-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWEjxvYparZinAu2pan%2Fuploads%2FEpCsAcyL8Yr9BLdpYUy5%2F7f13bfe3b11dcb5fbd969f0bfc6f8da2.jpg?alt=media\&token=cc63bd57-6176-4a5c-b9eb-1829d9bedbd4)

2\. Connect the EDGE connect the cable to the breakout board like in the picture above. Connect the breakout board to the Segger J-link. There should be an Identical color matching pattern connect already connected to the Jlink if not use the picture and pinout table below.

| [Breakout](https://i.gyazo.com/397cb5a32cb13bf5276d7cafbc7f52a0.png) | [Segger Jlink](https://i.gyazo.com/397cb5a32cb13bf5276d7cafbc7f52a0.png) |
| -------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| VCC                                                                  | 5V-Supply(Pin 19)                                                        |
| GND                                                                  | GND(Pin 4)                                                               |
| RESET                                                                | RESET(Pin 15)                                                            |
| SWO                                                                  | TDO(Pin 13)                                                              |
| SWDCLK                                                               | TCK(Pin 9)                                                               |
| SWDIO                                                                | TMS(Pin 7)                                                               |
| 1.8v                                                                 | VTref(Pin 1)                                                             |

![](https://1957962940-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWEjxvYparZinAu2pan%2Fuploads%2FrLqXccquyToHA3IH2ISU%2F80a9e7a6f85a4cdbf59133ac511dd0c8.jpg?alt=media\&token=00680ca8-f480-45a8-8a38-cbfca053e734)

3\. Connect the Segger J-link to your PC. **Also, Connect the Crypsis to a USB power source**(Can be the same PC) If you have opted on your embedded version that the headers are not solderd to have a lower profile pleas provide the nrf with either 5v power or solder the leads.

## Replacing the project

Once all software has been installed and hardware has been connecting we must replace a project of the NRFSDK with our project. The current codebase doesn't allow "Unique" Project names or locations.

1.Navigate to your NRFSDK install location and go to the following path: \*\v1.5.0\nrf\samples\nrf9160

2\.  Put the "crypsis\_radio" folder from the Crypsis Project folder there. This folder is in the following path of the Project Folder: Crypsis\Crypsis Hardware\Radio\\

## Changing Relevant Settings

This part is about changing the settings in the code so you can then build the code and program the device.

### Changing Network Configuration Settings

The first thing we will do is put the base device settings. These settings are "hardwired" and will always be a fallback in case you put a nonfunctioning config on the crypsis through the C2 enviroment. So make sure these settings are correct.

1. Navigate to the main.c file and open it with your favorite IDE or notepad. The path to this file is: "\*\v1.5.0\nrf\samples\nrf9160\mqtt\_simple\src\main.c"

2\. In the file navigate to the following lines of code/text

```bash
/*MQTT Variabels*/
char ImplantProject[100] = "projectx"; // NO ID, These ID's are reference to the blocks they are stored in once in Non Volitaile Storage
char mqtt_dns[100] = "mqtt.keyvilboard.com"; //ID2
char ImplantID[100] = "keyvilboard"; //ID3
char password1[100] = "helemooie"; //ID4
char username[100] = "luc"; //ID5
char topicsub[100]; //ID6 This Variable is populated by Implant Project or By the NVS once pushed
char topicpub[100]; //ID7 This Variable is populated by Implant Project or By the NVS once pushed
```

3\. Change the settings to what you want them to be. Below is an explanation of what each line means.

```bash
/*MQTT Variabels*/

char ImplantProject[100] = ""; #This is where you put the name of the project
char mqtt_dns[100] = ""; # This where you put your base Domain name
char ImplantID[100] = ""; # This contains your Implant ID this is technically also you MQTT Client-id
char password1[100]  = ""; # Here you put a authentication password make sure you put a password authentication happens on SSL lvl or MQTT lvl
char username[100]  = ""; # This contains the username same thing here accounts for the password
# The full MQTT address will always consist off mqtt_dns/ImplantProject/ImplantID/send or recieve
```

4\. Save the changes you made.

### Putting SSL Certificate

If you don't want to use SSL navigate to "SSL? No thank you!"

#### SSL? Yes, please!

So you want to use SSL we will have to do a couple of things. First off we have to make the needed certificates how to do that you can find in the following part of the documentation: HERE. Once you have made your 3 certificates please follow the following steps.

1. Navigate to the certificates.h file in the following path: "v1.5.0\nrf\samples\nrf9160\mqtt\_simple\src\certificates.h" then open the file.

2\. In this text file you will see the space for the 3 needed certificates.

```bash
#define CLIENT_PRIVATE_KEY \
```

```bash
#define CLIENT_PUBLIC_CERTIFICATE \
```

```bash
 #define CA_CERTIFICATE \
```

3\. Open your own certificates and place yours within this file. Make sure you stick to the same formatting as used before, definitely when it comes down to line length.

4\. Once you have replaced all and saved the file you can proceed.&#x20;

#### SSL? No thank you!

In case you don't want to use SSL follow these steps:

1. Navigate to prj.conf in the following path: "\*\v1.5.0\nrf\samples\nrf9160\mqtt\_simple" open it with a text editor.
2. Navigate to the following line and change the "y" to "n"

```bash
CONFIG_MQTT_LIB_TLS=y
```

3\. Save the file and close it and follow the rest of the tutorial.

## Building & Programming Project

For security please make sure debugging output is turned off. This is done by opening the following file and changing this line:\
\
To this line:

For the following steps please make sure you have installed Python, West, NRFCLI, git & Cmake like said in this [paragraph.](https://redbullettooling.gitbook.io/keyvilboard-apt/development-environment/downloading-and-installing-relevant-files) Once you have made that sure please follow the following steps:

1. Start by directing yourself to the home path of the project path should be the following: "\*\v1.5.0\nrf\samples\nrf9160\mqtt\_simple"

2\. Once in this path, Open Powershell and or cmd in this location by holding shift and click open Powershell.

3\. Now execute the following commands. If you are haveing trouble open Powershell or Cmd as an admin.

```bash
#cd "PATH TO mqtt_simple" "\v1.5.0\nrf\samples\nrf9160\mqtt_simple"
west init
west update
west config build.board nrf9160dk_nrf9160ns
west build -p always -b nrf9160dk_nrf9160ns 
```

4\. Then use the following commands to program the device. Make sure the Jlink and the crypsis are connected like said above.&#x20;

```bash
nrfjprog -f NRF91 --recover
nrfjprog -f NRF91 --program build\zephyr\merged.hex --chiperase
nrfjprog -f NRF91 --rbp ALL
```

You are now all done! The last command is very important since it makes sure memory can't be read and data like DNS addresses and certificates cant be stolen!

### Security(OPSEC)

By defeault because of security, all debugging has been disabled in case you want. To debug or want more information over the uart channel. You can enable it by changing the following lines in 2 different Configuration files.

First Config file is: prj.conf reverse the lines from y too n and n too y

```
CONFIG_MQTT_SIMPLE_LOG_LEVEL_DBG=n
CONFIG_NVS_LOG_LEVEL_DBG=n
CONFIG_PRINTK=n
CONFIG_LOG=n
CONFIG_STDOUT_CONSOLE=n
CONFIG_BOOT_BANNER=n
CONFIG_SPM_BOOT_SILENTLY=y
```

Second Config file is: spm.conf reverse the lines from y too n and n too y

```
CONFIG_SERIAL=n
CONFIG_STDOUT_CONSOLE=n
CONFIG_LOG=n
CONFIG_BOOT_BANNER=n
CONFIG_PRINTK=n
CONFIG_SPM_BOOT_SILENTLY=y
```
