mesh: Add support for meshd to use RAW channel
[platform/upstream/bluez.git] / mesh / mesh-io-generic.c
index 3ad1305..593d5a4 100644 (file)
@@ -49,6 +49,9 @@ struct mesh_io_private {
        uint16_t interval;
        bool sending;
        bool active;
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       bool use_raw;
+#endif
 };
 
 struct pvt_rx_reg {
@@ -261,10 +264,18 @@ static void configure_hci(struct mesh_io_private *io)
        cmd_slem.mask[6] = 0x00;
        cmd_slem.mask[7] = 0x00;
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (!(io->use_raw)) {
+               /* Reset Command in case of user channel */
+               bt_hci_send(io->hci, BT_HCI_CMD_RESET, NULL, 0, hci_generic_callback,
+                                                                       NULL, NULL);
+       }
+#else
        /* TODO: Move to suitable place. Set suitable masks */
        /* Reset Command */
        bt_hci_send(io->hci, BT_HCI_CMD_RESET, NULL, 0, hci_generic_callback,
                                                                NULL, NULL);
+#endif
 
        /* Read local supported commands */
        bt_hci_send(io->hci, BT_HCI_CMD_READ_LOCAL_COMMANDS, NULL, 0,
@@ -368,7 +379,24 @@ static void hci_init(void *user_data)
                bt_hci_unref(io->pvt->hci);
        }
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (io->pvt->use_raw) {
+               l_debug("Use HCI RAW channel");
+
+               /* Power up HCI device */
+               uint16_t mode = 0x01;
+               if (!set_powered(mode, io->pvt->index))
+                       return;
+
+               io->pvt->hci = bt_hci_new_raw_device(io->pvt->index);
+       } else {
+               l_debug("Use HCI USER channel");
+               io->pvt->hci = bt_hci_new_user_channel(io->pvt->index);
+       }
+#else
        io->pvt->hci = bt_hci_new_user_channel(io->pvt->index);
+#endif
+
        if (!io->pvt->hci) {
                l_error("Failed to start mesh io (hci %u): %s", io->pvt->index,
                                                        strerror(errno));
@@ -412,7 +440,14 @@ static bool dev_init(struct mesh_io *io, void *opts,
                return false;
 
        io->pvt = l_new(struct mesh_io_private, 1);
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       struct mesh_io_opts *io_opts;
+       io_opts = (struct mesh_io_opts *)opts;
+       io->pvt->index = io_opts->index;
+       io->pvt->use_raw = io_opts->use_raw;
+#else
        io->pvt->index = *(int *)opts;
+#endif
 
        io->pvt->rx_regs = l_queue_new();
        io->pvt->tx_pkts = l_queue_new();