title: How to enable Long Range for BLE Mesh in Zephyr OS
body: <p>I’m working on Bluetooth mesh network solution and I have requirement to increase range.</p>
  
  <p>I’m using nrf52840 DK and nrf52840 dongles, nrf5SDKforMeshv310.
  In Nordic <a href="https://devzone.nordicsemi.com/f/nordic-q-a/29813/change-phy-in-mesh" rel="nofollow noreferrer">Devzone</a>
  I found solution which, enables BLE long range mode in NRF SDK for mesh.</p>
  
  <p><b>NOTE!</b> I'm aware solution doesn't comply with Bluetooth Mesh standard.</p>
  
  <p>Following changes were applied to nrf5 SDK for Mesh v310:</p>
  
  <ol>
  <li>In advertise.c, set_default_broadcast_configuration() changed radio_mode to use RADIO_MODE_NRF_62K5BIT instead of RADIO_MODE_BLE_1MBIT.</li>
  <li>In scanner.c, scanner_config_reset() changed scanner_config_radio_mode_set() to use RADIO_MODE_NRF_62K5BIT instead of RADIO_MODE_BLE_1MBIT.</li>
  <li>In radio_config.c, radio_config_config() added the following code at the end:
  
  <pre><code>if (p_config-&gt;radio_mode==RADIO_MODE_NRF_62K5BIT ){
      NRF_RADIO-&gt;PCNF0 |=(
                  ((RADIO_PCNF0_PLEN_LongRange &lt;&lt; RADIO_PCNF0_PLEN_Pos) &amp; RADIO_PCNF0_PLEN_Msk) |
                  ((2 &lt;&lt; RADIO_PCNF0_CILEN_Pos) &amp; RADIO_PCNF0_CILEN_Msk) |
                  ((3 &lt;&lt; RADIO_PCNF0_TERMLEN_Pos) &amp; RADIO_PCNF0_TERMLEN_Msk) );
  }
  </code></pre></li>
  <li><p>In broadcast.c, time_required_to_send_us() added:</p>
  
  <pre><code>if (radio_mode == RADIO_MODE_NRF_62K5BIT)
  {
      packet_length_in_bytes +=RADIO_PREAMBLE_LENGTH_LR_EXTRA_BYTES;
  }
  </code></pre>
  
  <p>Defined RADIO_PREAMBLE_LENGTH_LR_EXTRA_BYTES = 9 in same file</p>
  
  <p>Changed 5th element in radio_mode_to_us_per_byte[] from 128 to 64.</p>
  
  <p><b>NOTE.</b> that the long-range mode is mislabeled. It is called RADIO_MODE_NRF_62K5BIT in the header file but corresponds to the 125kbps BLE long range mode instead.</p></li>
  </ol>
  
  <p>Unfortunately for relays I’m pushed to use Zephyr to support friend feature and Zephyr is not relaying messages after applying changes to NRF SDK. I did brief investigation on Zephyr side and found that code bits for BLE long range described above for NRF SDK are in place and can be enabled using following Kconfig settings:</p>
  
  <pre><code>CONFIG_BT_AUTO_PHY_UPDATE=y
  CONFIG_BT_PHY_UPDATE=y
  CONFIG_BT_HCI_MESH_EXT=y
  CONFIG_BT_CTLR_PHY=y
  CONFIG_BT_CTLR_ADV_EXT=y
  CONFIG_BT_CTLR_ADVANCED_FEATURES=y
  CONFIG_BT_CTLR_PHY_2M=y
  CONFIG_BT_CTLR_PHY_CODED=y
  
  </code></pre>
  
  <p>But still I don’t see that messages are being relayed on Zephyr side (using J-Link RTT Viewer). I also tried to increase log level for Bluetooth and Mesh to DEBUG, but I don’t see any signs that messages are malformed or rejected.</p>
  
  <p>May be someone has ideas in which direction I should dig in on Zephyr side?</p>