Linux bluetooth development
 help / color / mirror / Atom feed
* Re: [PATCH v2] android/client: Fix various coding style issues
From: Luiz Augusto von Dentz @ 2013-10-25  8:16 UTC (permalink / raw)
  To: Jerzy Kasenberg; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1382608220-25572-1-git-send-email-jerzy.kasenberg@tieto.com>

Hi Jerzy,

On Thu, Oct 24, 2013 at 12:50 PM, Jerzy Kasenberg
<jerzy.kasenberg@tieto.com> wrote:
> Mostly indentation of arguments in functions and calls.
> Prefix p remove from puser/penum_func.
> Some empty lines added after closing } when needed.
> Magic number for string length changed to preprocessor define.
> Added spaces after casts.
> ---
>
> v2:
>  - fixed casts
>
>  android/client/haltest.c       |   18 +++--
>  android/client/if-bt.c         |  154 ++++++++++++++++++++++------------------
>  android/client/if-hh.c         |   64 ++++++++---------
>  android/client/if-main.h       |   12 ++--
>  android/client/if-pan.c        |   34 ++++-----
>  android/client/if-sock.c       |   26 +++----
>  android/client/tabcompletion.c |    8 +--
>  android/client/terminal.c      |    5 ++
>  android/client/textconv.h      |    2 +-
>  9 files changed, 175 insertions(+), 148 deletions(-)
>
> diff --git a/android/client/haltest.c b/android/client/haltest.c
> index 19e81b8..189af0b 100644
> --- a/android/client/haltest.c
> +++ b/android/client/haltest.c
> @@ -47,6 +47,7 @@ struct method *get_method(struct method *methods, const char *name)
>                         return methods;
>                 methods++;
>         }
> +
>         return NULL;
>  }
>
> @@ -103,11 +104,11 @@ static void help_print_interface(const struct interface *i)
>  }
>
>  /* Help completion */
> -static void help_c(int argc, const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +static void help_c(int argc, const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 2)
> -               *penum_func = interface_name;
> +               *enum_func = interface_name;
>  }
>
>  /* Help execution */
> @@ -125,11 +126,13 @@ static void help_p(int argc, const char **argv)
>                                                 (m->help ? m->help : ""));
>                         m++;
>                 }
> +
>                 terminal_print("\nAvailable interfaces to use:\n");
>                 while (NULL != *ip) {
>                         terminal_print("\t%s\n", (*ip)->name);
>                         ip++;
>                 }
> +
>                 terminal_print("\nTo get help on methods for each interface type:\n");
>                 terminal_print("\n\thelp <inerface>\n");
>                 terminal_print("\nBasic scenario:\n\tadapter init\n");
> @@ -138,11 +141,13 @@ static void help_p(int argc, const char **argv)
>                 terminal_print("\thandsfree init\n\n");
>                 return;
>         }
> +
>         i = get_interface(argv[1]);
>         if (i == NULL) {
>                 haltest_error("No such interface\n");
>                 return;
>         }
> +
>         help_print_interface(i);
>  }
>
> @@ -176,6 +181,7 @@ const char *interface_name(void *v, int i)
>  const char *command_name(void *v, int i)
>  {
>         int cmd_cnt = (int) (sizeof(commands)/sizeof(commands[0]) - 1);
> +
>         if (i >= cmd_cnt)
>                 return interface_name(v, i - cmd_cnt);
>         else
> @@ -188,8 +194,7 @@ const char *command_name(void *v, int i)
>   * Output argv is filled with pointers to arguments
>   * returns number of tokens parsed - argc
>   */
> -static int command_line_to_argv(char *line_buffer,
> -                               char *argv[], int argv_size)
> +static int command_line_to_argv(char *line_buffer, char *argv[], int argv_size)
>  {
>         static const char *token_breaks = "\r\n\t ";
>         char *token;
> @@ -220,15 +225,18 @@ static void process_line(char *line_buffer)
>                         i++;
>                         continue;
>                 }
> +
>                 if (argc < 2 || strcmp(argv[1], "?") == 0) {
>                         help_print_interface(interfaces[i]);
>                         return;
>                 }
> +
>                 m = get_method(interfaces[i]->methods, argv[1]);
>                 if (m != NULL) {
>                         m->func(argc, (const char **) argv);
>                         return;
>                 }
> +
>                 haltest_error("No function %s found\n", argv[1]);
>                 return;
>         }
> diff --git a/android/client/if-bt.c b/android/client/if-bt.c
> index f5c84c1..dd5d12e 100644
> --- a/android/client/if-bt.c
> +++ b/android/client/if-bt.c
> @@ -82,13 +82,14 @@ static char *btproperty2str(bt_property_t property)
>         char *p;
>
>         p = buf + sprintf(buf, "type=%s len=%d val=",
> -                         bt_property_type_t2str(property.type), property.len);
> +                                       bt_property_type_t2str(property.type),
> +                                       property.len);
>
>         switch (property.type) {
>         case BT_PROPERTY_BDNAME:
>         case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
>                 sprintf(p, "%*s", property.len,
> -                       ((bt_bdname_t *) property.val)->name);
> +                                       ((bt_bdname_t *) property.val)->name);
>                 break;
>
>         case BT_PROPERTY_BDADDR:
> @@ -160,7 +161,7 @@ static char *btproperty2str(bt_property_t property)
>                         bt_service_record_t *rec = property.val;
>
>                         sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
> -                               rec->channel, rec->name);
> +                                               rec->channel, rec->name);
>                 }
>                 break;
>
> @@ -206,12 +207,14 @@ void add_remote_device(const bt_bdaddr_t *addr)
>                         remote_devices_capacity = 0;
>                         return;
>                 }
> +
>                 remote_devices_capacity = 4;
>         }
>
>         /* Array is sorted, search for right place */
>         for (i = 0; i < remote_devices_cnt; ++i) {
>                 int res = memcmp(&remote_devices[i], addr, sizeof(*addr));
> +
>                 if (res == 0)
>                         return; /* Already added */
>                 else if (res > 0)
> @@ -259,6 +262,7 @@ static void add_remote_device_from_props(int num_properties,
>                  * aligned buffer
>                  */
>                 bt_property_t property;
> +
>                 memcpy(&property, properties + i, sizeof(property));
>                 if (property.type == BT_PROPERTY_BDADDR)
>                         add_remote_device((bt_bdaddr_t *) property.val);
> @@ -270,21 +274,23 @@ static void adapter_state_changed_cb(bt_state_t state)
>         haltest_info("%s: state=%s\n", __func__, bt_state_t2str(state));
>  }
>
> -static void adapter_properties_cb(bt_status_t status,
> -       int num_properties, bt_property_t *properties)
> +static void adapter_properties_cb(bt_status_t status, int num_properties,
> +                                               bt_property_t *properties)
>  {
> -       haltest_info("%s: status=%s num_properties=%d\n",
> -              __func__, bt_status_t2str(status), num_properties);
> +       haltest_info("%s: status=%s num_properties=%d\n", __func__,
> +                               bt_status_t2str(status), num_properties);
>
>         dump_properties(num_properties, properties);
>  }
>
>  static void remote_device_properties_cb(bt_status_t status,
> -       bt_bdaddr_t *bd_addr, int num_properties, bt_property_t *properties)
> +                                       bt_bdaddr_t *bd_addr,
> +                                       int num_properties,
> +                                       bt_property_t *properties)
>  {
> -       haltest_info("%s: status=%s bd_addr=%s num_properties=%d\n",
> -              __func__, bt_status_t2str(status), bdaddr2str(bd_addr),
> -              num_properties);
> +       haltest_info("%s: status=%s bd_addr=%s num_properties=%d\n", __func__,
> +                       bt_status_t2str(status), bdaddr2str(bd_addr),
> +                       num_properties);
>
>         add_remote_device(bd_addr);
>
> @@ -303,7 +309,7 @@ static void device_found_cb(int num_properties, bt_property_t *properties)
>  static void discovery_state_changed_cb(bt_discovery_state_t state)
>  {
>         haltest_info("%s: state=%s\n", __func__,
> -               bt_discovery_state_t2str(state));
> +                                       bt_discovery_state_t2str(state));
>  }
>
>  /*
> @@ -311,16 +317,16 @@ static void discovery_state_changed_cb(bt_discovery_state_t state)
>   * It's stored for command completion.
>   */
>  static char last_remote_addr[MAX_ADDR_STR_LEN];
> -static bt_ssp_variant_t last_ssp_variant = (bt_ssp_variant_t)-1;
> +static bt_ssp_variant_t last_ssp_variant = (bt_ssp_variant_t) -1;
>
>  static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
> -       uint32_t cod)
> +                                                               uint32_t cod)
>  {
>         /* Store for command completion */
>         bt_bdaddr_t2str(remote_bd_addr, last_remote_addr);
>
>         haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x\n", __func__,
> -                                      last_remote_addr, bd_name->name, cod);
> +                                       last_remote_addr, bd_name->name, cod);
>  }
>
>  static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
> @@ -332,26 +338,26 @@ static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
>         last_ssp_variant = pairing_variant;
>
>         haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x pairing_variant=%s pass_key=%d\n",
> -                    __func__, last_remote_addr, bd_name->name, cod,
> -                    bt_ssp_variant_t2str(pairing_variant), pass_key);
> +                       __func__, last_remote_addr, bd_name->name, cod,
> +                       bt_ssp_variant_t2str(pairing_variant), pass_key);
>  }
>
>  static void bond_state_changed_cb(bt_status_t status,
> -                                       bt_bdaddr_t *remote_bd_addr,
> -                                       bt_bond_state_t state)
> +                                               bt_bdaddr_t *remote_bd_addr,
> +                                               bt_bond_state_t state)
>  {
>         haltest_info("%s: status=%s remote_bd_addr=%s state=%s\n", __func__,
> -                      bt_status_t2str(status), bdaddr2str(remote_bd_addr),
> -                      bt_bond_state_t2str(state));
> +                       bt_status_t2str(status), bdaddr2str(remote_bd_addr),
> +                       bt_bond_state_t2str(state));
>  }
>
>  static void acl_state_changed_cb(bt_status_t status,
> -                                       bt_bdaddr_t *remote_bd_addr,
> -                                       bt_acl_state_t state)
> +                                               bt_bdaddr_t *remote_bd_addr,
> +                                               bt_acl_state_t state)
>  {
>         haltest_info("%s: status=%s remote_bd_addr=%s state=%s\n", __func__,
> -                      bt_status_t2str(status), bdaddr2str(remote_bd_addr),
> -                      bt_acl_state_t2str(state));
> +                       bt_status_t2str(status), bdaddr2str(remote_bd_addr),
> +                       bt_acl_state_t2str(state));
>  }
>
>  static void thread_evt_cb(bt_cb_thread_evt evt)
> @@ -409,7 +415,7 @@ static void init_p(int argc, const char **argv)
>         }
>
>         if_bluetooth =
> -           ((bluetooth_device_t *) device)->get_bluetooth_interface();
> +                   ((bluetooth_device_t *) device)->get_bluetooth_interface();
>         if (!if_bluetooth) {
>                 haltest_error("get_bluetooth_interface returned NULL\n");
>                 return;
> @@ -449,11 +455,11 @@ static void get_adapter_properties_p(int argc, const char **argv)
>  }
>
>  static void get_adapter_property_c(int argc, const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +                                       enum_func *enum_func, void **user)
>  {
>         if (argc == 3) {
> -               *puser = TYPE_ENUM(bt_property_type_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(bt_property_type_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -468,21 +474,22 @@ static void get_adapter_property_p(int argc, const char **argv)
>  }
>
>  static const char * const names[] = {
> -               "BT_PROPERTY_BDNAME",
> -               "BT_PROPERTY_ADAPTER_SCAN_MODE",
> -               "BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT", NULL
> +       "BT_PROPERTY_BDNAME",
> +       "BT_PROPERTY_ADAPTER_SCAN_MODE",
> +       "BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT",
> +       NULL
>  };
>
>  static void set_adapter_property_c(int argc, const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +                                       enum_func *enum_func, void **user)
>  {
>         if (argc == 3) {
> -               *puser = (void *) names;
> -               *penum_func = enum_strings;
> +               *user = (void *) names;
> +               *enum_func = enum_strings;
>         } else if (argc == 4) {
>                 if (0 == strcmp(argv[2], "BT_PROPERTY_ADAPTER_SCAN_MODE")) {
> -                       *puser = TYPE_ENUM(bt_scan_mode_t);
> -                       *penum_func = enum_defines;
> +                       *user = TYPE_ENUM(bt_scan_mode_t);
> +                       *enum_func = enum_defines;
>                 }
>         }
>  }
> @@ -529,12 +536,12 @@ static void set_adapter_property_p(int argc, const char **argv)
>  /*
>   * This function is to be used for completion methods that need only address
>   */
> -static void complete_addr_c(int argc, const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +static void complete_addr_c(int argc, const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 3) {
> -               *puser = NULL;
> -               *penum_func = enum_devices;
> +               *user = NULL;
> +               *enum_func = enum_devices;
>         }
>  }
>
> @@ -552,15 +559,15 @@ static void get_remote_device_properties_p(int argc, const char **argv)
>  }
>
>  static void get_remote_device_property_c(int argc, const char **argv,
> -                                               enum_func *penum_func,
> -                                                               void **puser)
> +                                                       enum_func *enum_func,
> +                                                       void **user)
>  {
>         if (argc == 3) {
> -               *puser = NULL;
> -               *penum_func = enum_devices;
> +               *user = NULL;
> +               *enum_func = enum_devices;
>         } else if (argc == 4) {
> -               *puser = TYPE_ENUM(bt_property_type_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(bt_property_type_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -596,7 +603,6 @@ static void set_remote_device_property_p(int argc, const char **argv)
>                 property.len = strlen(argv[4]);
>                 property.val = (char *) argv[4];
>                 break;
> -
>         default:
>                 return;
>         }
> @@ -621,6 +627,7 @@ static void get_remote_service_record_p(int argc, const char **argv)
>                 haltest_error("No uuid specified\n");
>                 return;
>         }
> +
>         str2bt_uuid_t(argv[3], &uuid);
>
>         EXEC(if_bluetooth->get_remote_service_record, &addr, &uuid);
> @@ -692,13 +699,14 @@ static void cancel_bond_p(int argc, const char **argv)
>         EXEC(if_bluetooth->cancel_bond, &addr);
>  }
>
> -static void pin_reply_c(int argc, const char **argv,
> -               enum_func *penum_func, void **puser)
> +static void pin_reply_c(int argc, const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         static const char *const completions[] = { last_remote_addr, NULL };
> +
>         if (argc == 3) {
> -               *puser = (void *) completions;
> -               *penum_func = enum_strings;
> +               *user = (void *) completions;
> +               *enum_func = enum_strings;
>         }
>  }
>
> @@ -721,22 +729,22 @@ static void pin_reply_p(int argc, const char **argv)
>         EXEC(if_bluetooth->pin_reply, &addr, accept, pin_len, &pin);
>  }
>
> -static void ssp_reply_c(int argc, const char **argv,
> -               enum_func *penum_func, void **puser)
> +static void ssp_reply_c(int argc, const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 3) {
> -               *puser = last_remote_addr;
> -               *penum_func = enum_one_string;
> +               *user = last_remote_addr;
> +               *enum_func = enum_one_string;
>         } else if (argc == 5) {
> -               *puser = "1";
> -               *penum_func = enum_one_string;
> +               *user = "1";
> +               *enum_func = enum_one_string;
>         } else if (argc == 4) {
>                 if (-1 != (int) last_ssp_variant) {
> -                       *puser = (void *) bt_ssp_variant_t2str(last_ssp_variant);
> -                       *penum_func = enum_one_string;
> +                       *user = (void *) bt_ssp_variant_t2str(last_ssp_variant);
> +                       *enum_func = enum_one_string;
>                 } else {
> -                       *puser = TYPE_ENUM(bt_ssp_variant_t);
> -                       *penum_func = enum_defines;
> +                       *user = TYPE_ENUM(bt_ssp_variant_t);
> +                       *enum_func = enum_defines;
>                 }
>         }
>  }
> @@ -755,11 +763,13 @@ static void ssp_reply_p(int argc, const char **argv)
>                 haltest_error("No ssp variant specified\n");
>                 return;
>         }
> +
>         var = str2btsspvariant(argv[3]);
>         if (argc < 5) {
>                 haltest_error("No accept value specified\n");
>                 return;
>         }
> +
>         accept = atoi(argv[4]);
>         passkey = 0;
>
> @@ -770,7 +780,7 @@ static void ssp_reply_p(int argc, const char **argv)
>  }
>
>  static void get_profile_interface_c(int argc, const char **argv,
> -               enum_func *penum_func, void **puser)
> +                                       enum_func *enum_func, void **user)
>  {
>         static const char *const profile_ids[] = {
>                 BT_PROFILE_HANDSFREE_ID,
> @@ -787,8 +797,8 @@ static void get_profile_interface_c(int argc, const char **argv,
>         };
>
>         if (argc == 3) {
> -               *puser = (void *) profile_ids;
> -               *penum_func = enum_strings;
> +               *user = (void *) profile_ids;
> +               *enum_func = enum_strings;
>         }
>  }
>
> @@ -803,22 +813,22 @@ static void get_profile_interface_p(int argc, const char **argv)
>         if (strcmp(BT_PROFILE_HANDSFREE_ID, id) == 0)
>                 pif = &dummy; /* TODO: change when if_hf is there */
>         else if (strcmp(BT_PROFILE_ADVANCED_AUDIO_ID, id) == 0)
> -               pif = (const void **)&if_av;
> +               pif = (const void **) &if_av;
>         else if (strcmp(BT_PROFILE_HEALTH_ID, id) == 0)
>                 pif = &dummy; /* TODO: change when if_hl is there */
>         else if (strcmp(BT_PROFILE_SOCKETS_ID, id) == 0)
> -               pif = (const void **)&if_sock;
> +               pif = (const void **) &if_sock;
>         else if (strcmp(BT_PROFILE_HIDHOST_ID, id) == 0)
> -               pif = (const void **)&if_hh;
> +               pif = (const void **) &if_hh;
>         else if (strcmp(BT_PROFILE_PAN_ID, id) == 0)
> -               pif = (const void **)&if_pan;
> +               pif = (const void **) &if_pan;
>  #if PLATFORM_SDK_VERSION > 17
>         else if (strcmp(BT_PROFILE_AV_RC_ID, id) == 0)
>                 pif = &dummy; /* TODO: change when if_rc is there */
>  #endif
>         else
>                 haltest_error("%s is not correct for get_profile_interface\n",
> -                    id);
> +                                                                       id);
>
>         if (pif != NULL) {
>                 *pif = if_bluetooth->get_profile_interface(id);
> @@ -836,6 +846,7 @@ static void dut_mode_configure_p(int argc, const char **argv)
>                 haltest_error("No dut mode specified\n");
>                 return;
>         }
> +
>         mode = strtol(argv[2], NULL, 0);
>
>         EXEC(if_bluetooth->dut_mode_configure, mode);
> @@ -851,7 +862,8 @@ static struct method methods[] = {
>         STD_METHODCH(set_adapter_property, "<prop_type> <prop_value>"),
>         STD_METHODCH(get_remote_device_properties, "<addr>"),
>         STD_METHODCH(get_remote_device_property, "<addr> <property_type>"),
> -       STD_METHODCH(set_remote_device_property, "<addr> <property_type> <value>"),
> +       STD_METHODCH(set_remote_device_property,
> +                                       "<addr> <property_type> <value>"),
>         STD_METHODCH(get_remote_service_record, "<addr> <uuid>"),
>         STD_METHODCH(get_remote_services, "<addr>"),
>         STD_METHOD(start_discovery),
> diff --git a/android/client/if-hh.c b/android/client/if-hh.c
> index e23e4d5..005b13a 100644
> --- a/android/client/if-hh.c
> +++ b/android/client/if-hh.c
> @@ -79,7 +79,7 @@ static void connection_state_cb(bt_bdaddr_t *bd_addr,
>         char addr[MAX_ADDR_STR_LEN];
>
>         haltest_info("%s: bd_addr=%s connection_state=%s\n", __func__,
> -                       bt_bdaddr_t2str(bd_addr, addr),
> +                                       bt_bdaddr_t2str(bd_addr, addr),
>                                         bthh_connection_state_t2str(state));
>         if (state == BTHH_CONN_STATE_CONNECTED)
>                 strcpy(connected_device_addr, addr);
> @@ -94,7 +94,7 @@ static void virtual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status)
>         char addr[MAX_ADDR_STR_LEN];
>
>         haltest_info("%s: bd_addr=%s hh_status=%s\n", __func__,
> -                       bt_bdaddr_t2str(bd_addr, addr),
> +                                               bt_bdaddr_t2str(bd_addr, addr),
>                                                 bthh_status_t2str(hh_status));
>  }
>
> @@ -122,9 +122,9 @@ static void protocol_mode_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
>         char addr[MAX_ADDR_STR_LEN];
>
>         haltest_info("%s: bd_addr=%s hh_status=%s mode=%s\n", __func__,
> -                       bt_bdaddr_t2str(bd_addr, addr),
> -                       bthh_status_t2str(hh_status),
> -                                               bthh_protocol_mode_t2str(mode));
> +                                       bt_bdaddr_t2str(bd_addr, addr),
> +                                       bthh_status_t2str(hh_status),
> +                                       bthh_protocol_mode_t2str(mode));
>  }
>
>  /*
> @@ -136,8 +136,8 @@ static void idle_time_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
>         char addr[MAX_ADDR_STR_LEN];
>
>         haltest_info("%s: bd_addr=%s hh_status=%s idle_rate=%d\n", __func__,
> -                       bt_bdaddr_t2str(bd_addr, addr),
> -                       bthh_status_t2str(hh_status), idle_rate);
> +                               bt_bdaddr_t2str(bd_addr, addr),
> +                               bthh_status_t2str(hh_status), idle_rate);
>  }
>
>
> @@ -152,8 +152,8 @@ static void get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
>
>         /* TODO: print actual report */
>         haltest_info("%s: bd_addr=%s hh_status=%s rpt_size=%d\n", __func__,
> -                       bt_bdaddr_t2str(bd_addr, addr),
> -                       bthh_status_t2str(hh_status), rpt_size);
> +                                       bt_bdaddr_t2str(bd_addr, addr),
> +                                       bthh_status_t2str(hh_status), rpt_size);
>  }
>
>  static bthh_callbacks_t bthh_callbacks = {
> @@ -177,12 +177,12 @@ static void init_p(int argc, const char **argv)
>
>  /* connect */
>
> -static void connect_c(int argc, const const char **argv,
> -                               enum_func *penum_func, void **puser)
> +static void connect_c(int argc, const const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 3) {
> -               *puser = (void *) connected_device_addr;
> -               *penum_func = enum_one_string;
> +               *user = (void *) connected_device_addr;
> +               *enum_func = enum_one_string;
>         }
>  }
>
> @@ -243,14 +243,14 @@ static void set_info_p(int argc, const char **argv)
>  /* get_protocol */
>
>  static void get_protocol_c(int argc, const const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +                                       enum_func *enum_func, void **user)
>  {
>         if (argc == 3) {
> -               *puser = connected_device_addr;
> -               *penum_func = enum_one_string;
> +               *user = connected_device_addr;
> +               *enum_func = enum_one_string;
>         } else if (argc == 4) {
> -               *puser = TYPE_ENUM(bthh_protocol_mode_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(bthh_protocol_mode_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -296,14 +296,14 @@ static void set_protocol_p(int argc, const char **argv)
>  /* get_report */
>
>  static void get_report_c(int argc, const const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +                                       enum_func *enum_func, void **user)
>  {
>         if (argc == 3) {
> -               *puser = connected_device_addr;
> -               *penum_func = enum_one_string;
> +               *user = connected_device_addr;
> +               *enum_func = enum_one_string;
>         } else if (argc == 4) {
> -               *puser = TYPE_ENUM(bthh_report_type_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(bthh_report_type_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -341,14 +341,14 @@ static void get_report_p(int argc, const char **argv)
>  /* set_report */
>
>  static void set_report_c(int argc, const const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +                                       enum_func *enum_func, void **user)
>  {
>         if (argc == 3) {
> -               *puser = connected_device_addr;
> -               *penum_func = enum_one_string;
> +               *user = connected_device_addr;
> +               *enum_func = enum_one_string;
>         } else if (argc == 4) {
> -               *puser = TYPE_ENUM(bthh_report_type_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(bthh_report_type_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -376,12 +376,12 @@ static void set_report_p(int argc, const char **argv)
>
>  /* send_data */
>
> -static void send_data_c(int argc, const const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +static void send_data_c(int argc, const const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 3) {
> -               *puser = connected_device_addr;
> -               *penum_func = enum_one_string;
> +               *user = connected_device_addr;
> +               *enum_func = enum_one_string;
>         }
>  }
>
> diff --git a/android/client/if-main.h b/android/client/if-main.h
> index f2d35d9..eaee914 100644
> --- a/android/client/if-main.h
> +++ b/android/client/if-main.h
> @@ -93,11 +93,11 @@ typedef const char *(*enum_func)(void *user, int i);
>
>  /*
>   * This is prototype of function that when given argc, argv will
> - * fill penum_func with pointer to function that will enumerate
> - * parameters for argc argument, puser will be passed to penum_func.
> + * fill enum_func with pointer to function that will enumerate
> + * parameters for argc argument, user will be passed to enum_func.
>   */
> -typedef void (*tab_complete)(int argc, const char **argv,
> -                                       enum_func *penum_func, void **puser);
> +typedef void (*tab_complete)(int argc, const char **argv, enum_func *enum_func,
> +                                                               void **user);
>
>  /*
>   * For each method there is name and two functions to parse command line
> @@ -145,9 +145,9 @@ struct method *get_command(const char *name);
>
>  #define VERIFY_ADDR_ARG(n, adr) \
>         do { \
> -               if (n < argc) \
> +               if (n < argc) {\
>                         str2bt_bdaddr_t(argv[n], adr); \
> -               else { \
> +               } else { \
>                         haltest_error("No address specified\n");\
>                         return;\
>                 } \
> diff --git a/android/client/if-pan.c b/android/client/if-pan.c
> index e9cfa23..dcc7e80 100644
> --- a/android/client/if-pan.c
> +++ b/android/client/if-pan.c
> @@ -45,12 +45,12 @@ static void control_state_cb(btpan_control_state_t state, bt_status_t error,
>                                         int local_role, const char *ifname)
>  {
>         haltest_info("%s: state=%s error=%s local_role=%s ifname=%s\n",
> -                      __func__, btpan_control_state_t2str(state),
> -                      bt_status_t2str(error), btpan_role_t2str(local_role),
> -                      ifname);
> +                       __func__, btpan_control_state_t2str(state),
> +                       bt_status_t2str(error), btpan_role_t2str(local_role),
> +                       ifname);
>  }
>
> -static char last_used_addr[18];
> +static char last_used_addr[MAX_ADDR_STR_LEN];
>
>  static void connection_state_cb(btpan_connection_state_t state,
>                                 bt_status_t error, const bt_bdaddr_t *bd_addr,
> @@ -79,12 +79,12 @@ static void init_p(int argc, const char **argv)
>
>  /* enable */
>
> -static void enable_c(int argc, const const char **argv, enum_func *penum_func,
> -                                                               void **puser)
> +static void enable_c(int argc, const const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 3) {
> -               *puser = TYPE_ENUM(btpan_role_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(btpan_role_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -120,15 +120,15 @@ static void get_local_role_p(int argc, const char **argv)
>
>  /* connect */
>
> -static void connect_c(int argc, const const char **argv, enum_func *penum_func,
> -                                                               void **puser)
> +static void connect_c(int argc, const const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 3) {
> -               *puser = NULL;
> -               *penum_func = enum_devices;
> +               *user = NULL;
> +               *enum_func = enum_devices;
>         } else if (argc == 4 || argc == 5) {
> -               *puser = TYPE_ENUM(btpan_role_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(btpan_role_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -165,11 +165,11 @@ static void connect_p(int argc, const char **argv)
>  /* disconnect */
>
>  static void disconnect_c(int argc, const const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +                                       enum_func *enum_func, void **user)
>  {
>         if (argc == 3) {
> -               *puser = last_used_addr;
> -               *penum_func = enum_one_string;
> +               *user = last_used_addr;
> +               *enum_func = enum_one_string;
>         }
>  }
>
> diff --git a/android/client/if-sock.c b/android/client/if-sock.c
> index f3125f8..dcaf048 100644
> --- a/android/client/if-sock.c
> +++ b/android/client/if-sock.c
> @@ -52,7 +52,6 @@ static void receive_from_client(struct pollfd *pollfd)
>                 haltest_error("Disconnected fd=%d\n", pollfd->fd);
>                 poll_unregister_fd(pollfd->fd, receive_from_client);
>         } else if (pollfd->revents & POLLIN) {
> -
>                 haltest_info("receiving from client fd=%d\n", pollfd->fd);
>
>                 do {
> @@ -95,9 +94,10 @@ static void receive_sock_connect_signal(struct pollfd *pollfd)
>                         haltest_info("Read on connect return %d\n", ret);
>                         return;
>                 }
> +
>                 haltest_info("Connection to %s channel %d status=%d\n",
>                                 bt_bdaddr_t2str(&cs.bd_addr, addr_str),
> -                                                       cs.channel, cs.status);
> +                               cs.channel, cs.status);
>
>                 if (cs.status == 0)
>                         poll_register_fd(pollfd->fd, POLLIN,
> @@ -106,7 +106,7 @@ static void receive_sock_connect_signal(struct pollfd *pollfd)
>
>         if (pollfd->revents & POLLHUP) {
>                 haltest_error("Disconnected fd=%d revents=0x%X\n", pollfd->fd,
> -                                                       pollfd->revents);
> +                               pollfd->revents);
>                 poll_unregister_fd(pollfd->fd, receive_sock_connect_signal);
>         }
>  }
> @@ -165,6 +165,7 @@ static void read_accepted(int fd)
>                 accepted_fd = descs[0];
>                 break;
>         }
> +
>         haltest_info("Incoming connection from %s channel %d status=%d fd=%d\n",
>                                         bt_bdaddr_t2str(&cs.bd_addr, addr_str),
>                                         cs.channel, cs.status, accepted_fd);
> @@ -184,12 +185,12 @@ static void client_connected(struct pollfd *pollfd)
>
>  /** listen */
>
> -static void listen_c(int argc, const char **argv, enum_func *penum_func,
> -                                                               void **puser)
> +static void listen_c(int argc, const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 3) {
> -               *puser = TYPE_ENUM(btsock_type_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(btsock_type_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -253,14 +254,14 @@ static void listen_p(int argc, const char **argv)
>
>  /** connect */
>
> -static void connect_c(int argc, const char **argv,
> -                                       enum_func *penum_func, void **puser)
> +static void connect_c(int argc, const char **argv, enum_func *enum_func,
> +                                                               void **user)
>  {
>         if (argc == 3) {
> -               *penum_func = enum_devices;
> +               *enum_func = enum_devices;
>         } else if (argc == 4) {
> -               *puser = TYPE_ENUM(btsock_type_t);
> -               *penum_func = enum_defines;
> +               *user = TYPE_ENUM(btsock_type_t);
> +               *enum_func = enum_defines;
>         }
>  }
>
> @@ -313,6 +314,7 @@ static void connect_p(int argc, const char **argv)
>         if (sock_fd > 0) {
>                 int channel = 0;
>                 int ret = read(sock_fd, &channel, 4);
> +
>                 if (ret != 4)
>                         haltest_info("Read channel failed\n");
>                 haltest_info("Channel returned from first read %d\n", channel);
> diff --git a/android/client/tabcompletion.c b/android/client/tabcompletion.c
> index 2b95591..69af609 100644
> --- a/android/client/tabcompletion.c
> +++ b/android/client/tabcompletion.c
> @@ -63,8 +63,8 @@ static void print_matches(enum_func f, void *user, const char *prefix, int len)
>   * buf - output buffer to keep splited arguments list
>   * buf_size_in_bytes - size of buf
>   */
> -static int split_command(const char *line_buffer, int size,
> -                                       split_arg_t *buf, int buf_size_in_bytes)
> +static int split_command(const char *line_buffer, int size, split_arg_t *buf,
> +                                                       int buf_size_in_bytes)
>  {
>         split_arg_t *prev = NULL;
>         split_arg_t *arg = buf;
> @@ -218,8 +218,8 @@ static void method_completion(const struct interface *iface, split_arg_t *arg)
>  static const char *bold = "\x1b[1m";
>  static const char *normal = "\x1b[0m";
>
> -static bool find_nth_argument(const char *str, int n,
> -                                               const char **s, const char **e)
> +static bool find_nth_argument(const char *str, int n, const char **s,
> +                                                               const char **e)
>  {
>         const char *p = str;
>         int argc = 0;
> diff --git a/android/client/terminal.c b/android/client/terminal.c
> index a57068a..88c963b 100644
> --- a/android/client/terminal.c
> +++ b/android/client/terminal.c
> @@ -214,6 +214,7 @@ static void terminal_line_replaced(void)
>                         putchar('\b');
>                         line_buf_ix--;
>                 }
> +
>                 /* If cursor was not at the end, move it to the end */
>                 if (line_buf_ix < line_len)
>                         printf("%.*s", line_len - line_buf_ix,
> @@ -222,6 +223,7 @@ static void terminal_line_replaced(void)
>                 while (line_len >= len++)
>                         putchar(' ');
>         }
> +
>         /* draw new line */
>         printf("\r%s%s", prompt, line_buf);
>         /* set up indexes to new line */
> @@ -321,6 +323,7 @@ static int terminal_convert_sequence(int c)
>                }
>                return c;
>         }
> +
>         /* Inside sequence */
>         current_sequence[current_sequence_len++] = c;
>         current_sequence[current_sequence_len] = '\0';
> @@ -338,6 +341,7 @@ static int terminal_convert_sequence(int c)
>                 /* partial match (not whole sequence yet) */
>                 return KEY_SEQUNCE_NOT_FINISHED;
>         }
> +
>         terminal_print("ansii char 0x%X %c\n", c);
>         /*
>          * Sequence does not match
> @@ -530,6 +534,7 @@ void terminal_process_char(int c, void (*process_line)(char *line))
>                         printf("char-0x%02x\n", c);
>                         break;
>                 }
> +
>                 if (line_buf_ix < LINE_BUF_MAX - 1) {
>                         if (line_len == line_buf_ix) {
>                                 putchar(c);
> diff --git a/android/client/textconv.h b/android/client/textconv.h
> index 056e706..085b141 100644
> --- a/android/client/textconv.h
> +++ b/android/client/textconv.h
> @@ -58,7 +58,7 @@ const char *enum_defines(void *v, int i);
>  const char *enum_strings(void *v, int i);
>  const char *enum_one_string(void *v, int i);
>
> -#define TYPE_ENUM(type) ((void *)&__##type##2str[0])
> +#define TYPE_ENUM(type) ((void *) &__##type##2str[0])
>  #define DECINTMAP(type) \
>  extern struct int2str __##type##2str[]; \
>  const char *type##2##str(type v); \
> --
> 1.7.9.5

Applied, thanks.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH] android: Make haltest and bluetoothd depend on HAL lib
From: Luiz Augusto von Dentz @ 2013-10-25  8:11 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1382624561-9294-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Thu, Oct 24, 2013 at 5:22 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> The patch makes haltest and bluetoothd depend on bluetooth.default target
> which is already defined. glib dependency Android resolves itself.
> Fixes issue that for the fresh build only bluetooth.default.so is built.
> ---
>  android/Android.mk |    1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/android/Android.mk b/android/Android.mk
> index aac5c67..7049a20 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -84,6 +84,7 @@ LOCAL_MODULE := bluetooth.default
>  LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
>  LOCAL_MODULE_TAGS := optional
>  LOCAL_MODULE_CLASS := SHARED_LIBRARIES
> +LOCAL_REQUIRED_MODULES := haltest bluetoothd
>
>  include $(BUILD_SHARED_LIBRARY)
>
> --
> 1.7.10.4

Applied, thanks.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: GATT - How to mark an attribute as requiring encryption
From: Scott James Remnant @ 2013-10-24 20:46 UTC (permalink / raw)
  To: Anderson Lizardo; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CAJdJm_P4kq2WFRhhSbr9KROqTaqwmV2p3u9NzHW1Lt1v8hX0tA@mail.gmail.com>

On Mon, Oct 21, 2013 at 6:31 PM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:

> On Mon, Oct 21, 2013 at 9:01 PM, Scott James Remnant <keybuk@google.com> wrote:
>> While there is a way to mark an attribute as needing authentication
>> and/or authorization, there does not seem to be a way to mark an
>> attribute as requiring encryption (or a particular key size), and I
>> couldn't find any code that would return the ATT_ECODE_INSUFF_ENC or
>> ATT_ECODE_INSUFF_ENCR_KEY_SIZE responses.
>
> There is a FIXME for this on function att_check_reqs()
> (src/attrib-server.c). Feel free to fix it :)
>
Actually the FIXME seems unrelated, that seems to be about looking at
the reported security level of the connection and only considering the
"have authentication" check to be passed if the level is
BT_IO_SEC_HIGH -- right now it would accept BT_IO_SEC_MEDIUM as
evidence of authentication.

At least that's how I read it.


That said, having stared at the standard and the Test Purposes a
little longer, the test isn't even checking for "insufficient
encryption" but "insufficient encryption key size". In these tests the
PTS actually does negotiate encryption, it's expecting the attribute
server to record the key size and allow attributes to declare that
they need a bigger key.

> Note that, as part of the ongoing implementation of a D-Bus API for
> implementing external GATT services, we have patches (currently being
> cleaned up for upstream submission) that will refactor the internal C
> API for creating GATT services. If you are interested, take a look at
> (note that it is work-in-progress code):
>
> git://git.infradead.org/users/cktakahasi/bluez.git (branch gatt-api-devel)
>
> Also take a look at the API document sent by Claudio a few days ago:
> "[RFC BlueZ v0] doc: Add GATT API"
>
I have this on my TODO to read once we're clear through qualification.

Scott
-- 
Scott James Remnant | Chrome OS Systems | keybuk@google.com | Google

^ permalink raw reply

* Re: [PATCH] Bluetooth: Add hci_h4p driver
From: Joe Perches @ 2013-10-24 18:41 UTC (permalink / raw)
  To: Pali Rohár
  Cc: Marcel Holtmann, Gustavo Padovan, Johan Hedberg, Pavel Machek,
	linux-kernel, linux-bluetooth,
	Ивайло Димитров,
	Joni Lapilainen, Sebastian Reichel, Aaro Koskinen
In-Reply-To: <201310181230.45351@pali>

On Fri, 2013-10-18 at 12:30 +0200, Pali Rohár wrote:

> I rebased patch on top of https://git.kernel.org/cgit/linux/kernel/git/bluetooth/bluetooth-next.git branch master

Hi Pali, just some trivial notes:

[]

+static ssize_t hci_h4p_show_bdaddr(struct device *dev,
> +                                  struct device_attribute *attr, char *buf)
> +{
> +       struct hci_h4p_info *info = dev_get_drvdata(dev);
> +
> +       return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
> +                      info->bd_addr[0], info->bd_addr[1], info->bd_addr[2],
> +                      info->bd_addr[3], info->bd_addr[4], info->bd_addr[5]);

sprintf(buf, "%pM", info->bd_addr)

and if this is really bluetooth, does the output need to
be emitted in reverse order?  ie: %pMR

[]

> +#define NBT_DBG(fmt, arg...) \
> +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> +
> +#define NBT_DBG_FW(fmt, arg...) \
> +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> +
> +#define NBT_DBG_POWER(fmt, arg...) \
> +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> +
> +#define NBT_DBG_TRANSFER(fmt, arg...) \
> +               pr_debug("%s: " fmt "" , __func__ , ## arg)
> +
> +#define NBT_DBG_TRANSFER_NF(fmt, arg...) \
> +               pr_debug(fmt "" , ## arg)
> +
> +#define NBT_DBG_DMA(fmt, arg...) \
> +               pr_debug("%s: " fmt "" , __func__ , ## arg)

The "" isn't useful.

dynamic_debugging can add __func__ to each message output
with +f.

I think all of these should be converted to pr_debug
where used or consolidated into a single
#define nbt_dbg(mask, fmt, ...)			\
do {						\
	if (mask & debug)			\
		pr_debug(fmt, ##__VA_ARGS__);
} while (0)

and used like:
	nbt_dbg(TRANSFER, fmt, etc...);
where debug is some static.

Also there are many uses missing "\n" which can
cause interleaving problems with other printks.

[]

> +int hci_h4p_wait_for_cts(struct hci_h4p_info *info, int active,
> +                        int timeout_ms)
> +{
> +       unsigned long timeout;
> +       int state;
> +
> +       timeout = jiffies + msecs_to_jiffies(timeout_ms);
> +       for (;;) {

	while (time_before(jiffies, timeout)) {

> +               state = hci_h4p_inb(info, UART_MSR) & UART_MSR_CTS;
> +               if (active) {
> +                       if (state)
> +                               return 0;
> +               } else {
> +                       if (!state)
> +                               return 0;
> +               }
> +               if (time_after(jiffies, timeout))
> +                       return -ETIMEDOUT;

> +               msleep(1);
> +       }

	return -ETIMEDOUT;

> +}

^ permalink raw reply

* Re: [PATCH] Bluetooth: Add hci_h4p driver
From: Pali Rohár @ 2013-10-24 16:41 UTC (permalink / raw)
  To: Marcel Holtmann
  Cc: Gustavo Padovan, Johan Hedberg, Pavel Machek, linux-kernel,
	linux-bluetooth,
	Ивайло Димитров,
	Joni Lapilainen, Sebastian Reichel, Aaro Koskinen
In-Reply-To: <201310181230.45351@pali>

[-- Attachment #1: Type: Text/Plain, Size: 614 bytes --]

On Friday 18 October 2013 12:30:44 Pali Rohár wrote:
>   On Friday 18 October 2013 00:11:44 Marcel Holtmann wrote:
> > Hi Pali,
> >
> > 
> >
> > > 
> > >
> > > Can somebody look & comment this patch? What is needed to
> > > be part of upstream kernel?
> >
> > 
> >
> > you need to rebase against bluetooth-next at least.
> >
> > 
> >
> > Regards
> >
> > 
> >
> > Marcel
> 
> I rebased patch on top of
> https://git.kernel.org/cgit/linux/kernel/git/bluetooth/blueto
> oth-next.git branch master

Hello Marcel, have you looked at hci_h4p patch?

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply

* Re: [PATCH] android: Fix debug logs when running on Android
From: Luiz Augusto von Dentz @ 2013-10-24 15:40 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1382623538-17510-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Thu, Oct 24, 2013 at 5:05 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> Current Android log backed dones't enable debug logs. Instead of coping
> code from src/log.c, just use it on Android as well.
>
> No functionality is lost as currently Android log backed only prints
> to standard output.
> ---
>  Makefile.android   |  5 ++-
>  android/Android.mk |  2 +-
>  android/log.c      | 90 ------------------------------------------------------
>  3 files changed, 3 insertions(+), 94 deletions(-)
>  delete mode 100644 android/log.c
>
> diff --git a/Makefile.android b/Makefile.android
> index 8e09a78..01b3cea 100644
> --- a/Makefile.android
> +++ b/Makefile.android
> @@ -64,9 +64,8 @@ android_haltest_LDFLAGS = -pthread
>
>  endif
>
> -EXTRA_DIST += android/Android.mk android/log.c android/device.c \
> -               android/adapter.c android/main.c android/hal-msg.h \
> -               android/hal.h
> +EXTRA_DIST += android/Android.mk android/device.c android/adapter.c\
> +               android/main.c android/hal-msg.h android/hal.h
>
>  EXTRA_DIST += android/hal-bluetooth.c \
>                 android/hal-sock.c \
> diff --git a/android/Android.mk b/android/Android.mk
> index aac5c67..890b5ac 100644
> --- a/android/Android.mk
> +++ b/android/Android.mk
> @@ -14,11 +14,11 @@ include $(CLEAR_VARS)
>
>  LOCAL_SRC_FILES := \
>         main.c \
> -       log.c \
>         adapter.c \
>         hid.c \
>         socket.c \
>         ipc.c ipc.h \
> +       ../src/log.c \
>         ../src/shared/mgmt.c \
>         ../src/shared/util.c \
>         ../src/sdpd-database.c \
> diff --git a/android/log.c b/android/log.c
> deleted file mode 100644
> index 98afaa9..0000000
> --- a/android/log.c
> +++ /dev/null
> @@ -1,90 +0,0 @@
> -/*
> - *
> - *  BlueZ - Bluetooth protocol stack for Linux
> - *
> - *  Copyright (C) 2013  Intel Corporation. All rights reserved.
> - *
> - *
> - *  This program is free software; you can redistribute it and/or modify
> - *  it under the terms of the GNU General Public License as published by
> - *  the Free Software Foundation; either version 2 of the License, or
> - *  (at your option) any later version.
> - *
> - *  This program is distributed in the hope that it will be useful,
> - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> - *  GNU General Public License for more details.
> - *
> - *  You should have received a copy of the GNU General Public License
> - *  along with this program; if not, write to the Free Software
> - *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> - *
> - */
> -
> -#ifdef HAVE_CONFIG_H
> -#include <config.h>
> -#endif
> -
> -#include <fcntl.h>
> -#include <stdio.h>
> -#include <stdarg.h>
> -#include <unistd.h>
> -#include <sys/uio.h>
> -
> -#include <glib.h>
> -
> -void info(const char *format, ...)
> -{
> -       va_list ap;
> -
> -       va_start(ap, format);
> -
> -       vfprintf(stdout, format, ap);
> -       fprintf(stdout, "\n");
> -
> -       va_end(ap);
> -}
> -
> -void warn(const char *format, ...)
> -{
> -       va_list ap;
> -
> -       va_start(ap, format);
> -
> -       vfprintf(stderr, format, ap);
> -       fprintf(stderr, "\n");
> -
> -       va_end(ap);
> -}
> -
> -void error(const char *format, ...)
> -{
> -       va_list ap;
> -
> -       va_start(ap, format);
> -
> -       vfprintf(stderr, format, ap);
> -       fprintf(stderr, "\n");
> -
> -       va_end(ap);
> -}
> -
> -void btd_debug(const char *format, ...)
> -{
> -       va_list ap;
> -
> -       va_start(ap, format);
> -
> -       vfprintf(stdout, format, ap);
> -       fprintf(stdout, "\n");
> -
> -       va_end(ap);
> -}
> -
> -void __btd_log_init(const char *debug, int detach)
> -{
> -}
> -
> -void __btd_log_cleanup(void)
> -{
> -}
> --
> 1.8.4.1

Pushed, thanks.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH v2 1/5] android: Start command watch after notify channel is connected
From: Luiz Augusto von Dentz @ 2013-10-24 15:34 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth@vger.kernel.org, Szymon Janc
In-Reply-To: <1382608464-10389-1-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Thu, Oct 24, 2013 at 12:54 PM, Szymon Janc <szymon.janc@tieto.com> wrote:
> From: Szymon Janc <szymon.janc@gmail.com>
>
> Daemon should start processing commands only after both communication
> channels were connected.
> ---
>  android/main.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/android/main.c b/android/main.c
> index 9879f05..740b532 100644
> --- a/android/main.c
> +++ b/android/main.c
> @@ -288,9 +288,11 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
>
>         g_io_add_watch(io, cond, notif_watch_cb, NULL);
>
> -       info("Successfully connected to HAL");
> +       cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
>
> -       /* TODO start handling commands */
> +       g_io_add_watch(hal_cmd_io, cond, cmd_watch_cb, NULL);
> +
> +       info("Successfully connected to HAL");
>
>         return FALSE;
>  }
> @@ -305,10 +307,6 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
>                 return FALSE;
>         }
>
> -       cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
> -
> -       g_io_add_watch(io, cond, cmd_watch_cb, NULL);
> -
>         hal_notif_io = connect_hal(notif_connect_cb);
>         if (!hal_notif_io) {
>                 error("Cannot connect to HAL, terminating");
> --
> 1.8.4

Pushed, thanks.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* [PATCH] android: Make haltest and bluetoothd depend on HAL lib
From: Andrei Emeltchenko @ 2013-10-24 14:22 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

The patch makes haltest and bluetoothd depend on bluetooth.default target
which is already defined. glib dependency Android resolves itself.
Fixes issue that for the fresh build only bluetooth.default.so is built.
---
 android/Android.mk |    1 +
 1 file changed, 1 insertion(+)

diff --git a/android/Android.mk b/android/Android.mk
index aac5c67..7049a20 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -84,6 +84,7 @@ LOCAL_MODULE := bluetooth.default
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_REQUIRED_MODULES := haltest bluetoothd
 
 include $(BUILD_SHARED_LIBRARY)
 
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH] android: Fix debug logs when running on Android
From: Szymon Janc @ 2013-10-24 14:05 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Current Android log backed dones't enable debug logs. Instead of coping
code from src/log.c, just use it on Android as well.

No functionality is lost as currently Android log backed only prints
to standard output.
---
 Makefile.android   |  5 ++-
 android/Android.mk |  2 +-
 android/log.c      | 90 ------------------------------------------------------
 3 files changed, 3 insertions(+), 94 deletions(-)
 delete mode 100644 android/log.c

diff --git a/Makefile.android b/Makefile.android
index 8e09a78..01b3cea 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -64,9 +64,8 @@ android_haltest_LDFLAGS = -pthread
 
 endif
 
-EXTRA_DIST += android/Android.mk android/log.c android/device.c \
-		android/adapter.c android/main.c android/hal-msg.h \
-		android/hal.h
+EXTRA_DIST += android/Android.mk android/device.c android/adapter.c\
+		android/main.c android/hal-msg.h android/hal.h
 
 EXTRA_DIST += android/hal-bluetooth.c \
 		android/hal-sock.c \
diff --git a/android/Android.mk b/android/Android.mk
index aac5c67..890b5ac 100644
--- a/android/Android.mk
+++ b/android/Android.mk
@@ -14,11 +14,11 @@ include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
 	main.c \
-	log.c \
 	adapter.c \
 	hid.c \
 	socket.c \
 	ipc.c ipc.h \
+	../src/log.c \
 	../src/shared/mgmt.c \
 	../src/shared/util.c \
 	../src/sdpd-database.c \
diff --git a/android/log.c b/android/log.c
deleted file mode 100644
index 98afaa9..0000000
--- a/android/log.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2013  Intel Corporation. All rights reserved.
- *
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <sys/uio.h>
-
-#include <glib.h>
-
-void info(const char *format, ...)
-{
-	va_list ap;
-
-	va_start(ap, format);
-
-	vfprintf(stdout, format, ap);
-	fprintf(stdout, "\n");
-
-	va_end(ap);
-}
-
-void warn(const char *format, ...)
-{
-	va_list ap;
-
-	va_start(ap, format);
-
-	vfprintf(stderr, format, ap);
-	fprintf(stderr, "\n");
-
-	va_end(ap);
-}
-
-void error(const char *format, ...)
-{
-	va_list ap;
-
-	va_start(ap, format);
-
-	vfprintf(stderr, format, ap);
-	fprintf(stderr, "\n");
-
-	va_end(ap);
-}
-
-void btd_debug(const char *format, ...)
-{
-	va_list ap;
-
-	va_start(ap, format);
-
-	vfprintf(stdout, format, ap);
-	fprintf(stdout, "\n");
-
-	va_end(ap);
-}
-
-void __btd_log_init(const char *debug, int detach)
-{
-}
-
-void __btd_log_cleanup(void)
-{
-}
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 2/2] android/client: Add processing of .haltestrc
From: Jerzy Kasenberg @ 2013-10-24 12:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1382618807-14605-1-git-send-email-jerzy.kasenberg@tieto.com>

This patch allows tool to read commands from .haltestrc.
So it is possible to call some functions that are typically used.
So user can have:
  adapter init
  adapter get_profile_interface socket
  adapter get_profile_interface pan
  adapter get_profile_interface hidhost
  adapter get_profile_interface a2dp
  pan init
  av init
---
 android/client/haltest.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index efed16e..45fe724 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -314,6 +314,8 @@ static void stdin_handler(struct pollfd *pollfd)
 
 int main(int argc, char **argv)
 {
+	struct stat rcstat;
+
 	terminal_setup();
 	history_restore(".haltest_history");
 
@@ -321,6 +323,9 @@ int main(int argc, char **argv)
 	/* Register command line handler */
 	poll_register_fd(0, POLLIN, stdin_handler);
 
+	if (stat(".haltestrc", &rcstat) == 0 && (rcstat.st_mode & S_IFREG) != 0)
+		process_file(".haltestrc");
+
 	poll_dispatch_loop();
 
 	return 0;
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 1/2] android/client: Add source command to haltest
From: Jerzy Kasenberg @ 2013-10-24 12:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg
In-Reply-To: <1382618807-14605-1-git-send-email-jerzy.kasenberg@tieto.com>

New command allows to read script file into tool and
execute its contents as if it was typed.
---
 android/client/haltest.c |   50 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index 189af0b..efed16e 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -157,11 +157,47 @@ static void quit_p(int argc, const char **argv)
 	exit(0);
 }
 
+static int fd_stack[10];
+static int fd_stack_pointer = 0;
+
+static void stdin_handler(struct pollfd *pollfd);
+
+static void process_file(const char *name)
+{
+	int fd = open(name, O_RDONLY);
+
+	if (fd == -1) {
+		haltest_error("Can't open file: %s for reading\n", name);
+		return;
+	}
+
+	if (fd_stack_pointer >= 10) {
+		haltest_error("To many open files\n");
+		close(fd);
+		return;
+	}
+
+	fd_stack[fd_stack_pointer++] = fd;
+	poll_unregister_fd(fd_stack[fd_stack_pointer - 2], stdin_handler);
+	poll_register_fd(fd_stack[fd_stack_pointer - 1], POLLIN, stdin_handler);
+}
+
+static void source_p(int argc, const char **argv)
+{
+	if (argc < 2) {
+		haltest_error("No file specified");
+		return;
+	}
+
+	process_file(argv[1]);
+}
+
 /* Commands available without interface */
 static struct method commands[] = {
 	STD_METHODCH(help, "[<interface>]"),
 	STD_METHOD(quit),
 	METHOD("exit", quit_p, NULL, NULL),
+	STD_METHODH(source, "<file>"),
 	END_METHOD
 };
 
@@ -254,15 +290,26 @@ static void stdin_handler(struct pollfd *pollfd)
 	char buf[10];
 
 	if (pollfd->revents & POLLIN) {
-		int count = read(0, buf, 10);
+		int count = read(fd_stack[fd_stack_pointer - 1], buf, 10);
 
 		if (count > 0) {
 			int i;
 
 			for (i = 0; i < count; ++i)
 				terminal_process_char(buf[i], process_line);
+			return;
 		}
 	}
+
+	if (fd_stack_pointer > 1)
+		poll_register_fd(fd_stack[fd_stack_pointer - 2], POLLIN,
+								stdin_handler);
+	if (fd_stack_pointer > 0) {
+		poll_unregister_fd(fd_stack[--fd_stack_pointer], stdin_handler);
+
+		if (fd_stack[fd_stack_pointer])
+			close(fd_stack[fd_stack_pointer]);
+	}
 }
 
 int main(int argc, char **argv)
@@ -270,6 +317,7 @@ int main(int argc, char **argv)
 	terminal_setup();
 	history_restore(".haltest_history");
 
+	fd_stack[fd_stack_pointer++] = 0;
 	/* Register command line handler */
 	poll_register_fd(0, POLLIN, stdin_handler);
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 0/2] Add basic scripting to haltest
From: Jerzy Kasenberg @ 2013-10-24 12:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg

This patcheset adds command 'source' to interpret scripts
and processing of .haltestrc to execute some commands automatically.

Jerzy Kasenberg (2):
  android/client: Add source command to haltest
  android/client: Add processing of .haltestrc

 android/client/haltest.c |   55 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

-- 
1.7.9.5


^ permalink raw reply

* [PATCH v2 5/5] android: Use adapter index in mgmt functions
From: Szymon Janc @ 2013-10-24  9:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382608464-10389-1-git-send-email-szymon.janc@tieto.com>

From: Szymon Janc <szymon.janc@gmail.com>

Instead of hardcoding index 0 use real index of adapter. This fix
using invalid index if adapter ID happens to be different than 0.

This should not happen on Android but is possible while testing on
Linux PC.
---
 android/adapter.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 84b3d93..8917b8e 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -170,14 +170,16 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
 
 static void register_mgmt_handlers(void)
 {
-	mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, 0,
+	mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
 					new_settings_callback, NULL, NULL);
 
 	mgmt_register(adapter->mgmt, MGMT_EV_CLASS_OF_DEV_CHANGED,
-			0, mgmt_dev_class_changed_event, NULL, NULL);
+				adapter->index, mgmt_dev_class_changed_event,
+				NULL, NULL);
 
 	mgmt_register(adapter->mgmt, MGMT_EV_LOCAL_NAME_CHANGED,
-			0, mgmt_local_name_changed_event, NULL, NULL);
+				adapter->index, mgmt_local_name_changed_event,
+				NULL, NULL);
 }
 
 static void load_link_keys_complete(uint8_t status, uint16_t length,
@@ -216,7 +218,7 @@ static void load_link_keys(GSList *keys)
 	cp->debug_keys = 0;
 	cp->key_count = htobs(key_len);
 
-	mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, 0, len,
+	mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, adapter->index, len,
 				cp, load_link_keys_complete, NULL, NULL);
 
 	g_free(cp);
-- 
1.8.4


^ permalink raw reply related

* [PATCH v2 4/5] android: Use default adapter in adapter functions
From: Szymon Janc @ 2013-10-24  9:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382608464-10389-1-git-send-email-szymon.janc@tieto.com>

From: Szymon Janc <szymon.janc@gmail.com>

There is no need to pass pointer to adapter between function as there
is only one adapter in android daemon. Also default_adapter is renamed
to adapter.

There is no need to pass adapter pointer as user data since there is
only one adapter present.
---
 android/adapter.c | 63 +++++++++++++++++++++++--------------------------------
 1 file changed, 26 insertions(+), 37 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index aee9cf4..84b3d93 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -50,12 +50,11 @@ struct bt_adapter {
 	uint32_t current_settings;
 };
 
-static struct bt_adapter *default_adapter;
+static struct bt_adapter *adapter;
 
 static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	const struct mgmt_cp_set_local_name *rp = param;
 
 	if (length < sizeof(*rp)) {
@@ -74,7 +73,7 @@ static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
 	/* TODO Update services if needed */
 }
 
-static void settings_changed_powered(struct bt_adapter *adapter)
+static void settings_changed_powered(void)
 {
 	struct hal_ev_adapter_state_changed ev;
 
@@ -87,17 +86,17 @@ static void settings_changed_powered(struct bt_adapter *adapter)
 			HAL_EV_ADAPTER_STATE_CHANGED, sizeof(ev), &ev, -1);
 }
 
-static void settings_changed_connectable(struct bt_adapter *adapter)
+static void settings_changed_connectable(void)
 {
 	/* TODO */
 }
 
-static void settings_changed_discoverable(struct bt_adapter *adapter)
+static void settings_changed_discoverable(void)
 {
 	/* TODO */
 }
 
-static void settings_changed(struct bt_adapter *adapter, uint32_t settings)
+static void settings_changed(uint32_t settings)
 {
 	uint32_t changed_mask;
 
@@ -108,25 +107,24 @@ static void settings_changed(struct bt_adapter *adapter, uint32_t settings)
 	DBG("0x%08x", changed_mask);
 
 	if (changed_mask & MGMT_SETTING_POWERED)
-		settings_changed_powered(adapter);
+		settings_changed_powered();
 
 	if (changed_mask & MGMT_SETTING_CONNECTABLE) {
 		DBG("Connectable");
 
-		settings_changed_connectable(adapter);
+		settings_changed_connectable();
 	}
 
 	if (changed_mask & MGMT_SETTING_DISCOVERABLE) {
 		DBG("Discoverable");
 
-		settings_changed_discoverable(adapter);
+		settings_changed_discoverable();
 	}
 }
 
 static void new_settings_callback(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	uint32_t settings;
 
 	if (length < sizeof(settings)) {
@@ -142,13 +140,12 @@ static void new_settings_callback(uint16_t index, uint16_t length,
 	if (settings == adapter->current_settings)
 		return;
 
-	settings_changed(adapter, settings);
+	settings_changed(settings);
 }
 
 static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	const struct mgmt_cod *rp = param;
 	uint32_t dev_class;
 
@@ -171,24 +168,21 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
 	/* TODO: Gatt attrib set*/
 }
 
-static void register_mgmt_handlers(struct bt_adapter *adapter)
+static void register_mgmt_handlers(void)
 {
 	mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, 0,
-			new_settings_callback, adapter, NULL);
+					new_settings_callback, NULL, NULL);
 
 	mgmt_register(adapter->mgmt, MGMT_EV_CLASS_OF_DEV_CHANGED,
-			0, mgmt_dev_class_changed_event,
-			adapter, NULL);
+			0, mgmt_dev_class_changed_event, NULL, NULL);
 
 	mgmt_register(adapter->mgmt, MGMT_EV_LOCAL_NAME_CHANGED,
-			0, mgmt_local_name_changed_event,
-			adapter, NULL);
+			0, mgmt_local_name_changed_event, NULL, NULL);
 }
 
 static void load_link_keys_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	int err;
 
 	if (status) {
@@ -200,7 +194,6 @@ static void load_link_keys_complete(uint8_t status, uint16_t length,
 
 	DBG("status %u", status);
 
-	default_adapter = adapter;
 	adapter->ready(0);
 	return;
 
@@ -208,7 +201,7 @@ failed:
 	adapter->ready(err);
 }
 
-static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
+static void load_link_keys(GSList *keys)
 {
 	struct mgmt_cp_load_link_keys *cp;
 	size_t key_len = g_slist_length(keys);
@@ -224,7 +217,7 @@ static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
 	cp->key_count = htobs(key_len);
 
 	mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, 0, len,
-				cp, load_link_keys_complete, adapter, NULL);
+				cp, load_link_keys_complete, NULL, NULL);
 
 	g_free(cp);
 }
@@ -232,7 +225,6 @@ static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
 static void read_info_complete(uint8_t status, uint16_t length, const void *param,
 							void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	const struct mgmt_rp_read_info *rp = param;
 	int err;
 
@@ -240,7 +232,7 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
 
 	if (status) {
 		error("Failed to read info for index %u: %s (0x%02x)",
-			adapter->index, mgmt_errstr(status), status);
+				adapter->index, mgmt_errstr(status), status);
 		err = -EIO;
 		goto failed;
 	}
@@ -267,9 +259,9 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
 	adapter->current_settings = btohs(rp->current_settings);
 
 	/* TODO: Register all event notification handlers */
-	register_mgmt_handlers(adapter);
+	register_mgmt_handlers();
 
-	load_link_keys(adapter, NULL);
+	load_link_keys(NULL);
 
 	return;
 
@@ -280,8 +272,6 @@ failed:
 void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 							bt_adapter_ready cb)
 {
-	struct bt_adapter *adapter;
-
 	adapter = g_new0(struct bt_adapter, 1);
 
 	adapter->mgmt = mgmt_ref(mgmt_if);
@@ -289,10 +279,10 @@ void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 	adapter->ready = cb;
 
 	if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
-				read_info_complete, adapter, NULL) > 0)
+					read_info_complete, NULL, NULL) > 0)
 		return;
 
-	mgmt_unref(mgmt_if);
+	mgmt_unref(adapter->mgmt);
 	adapter->ready(-EIO);
 }
 
@@ -310,8 +300,7 @@ static void set_mode_complete(uint8_t status, uint16_t length,
 	 * required in both cases. So it is safe to just call the
 	 * event handling functions here.
 	 */
-	new_settings_callback(default_adapter->index, length, param,
-							default_adapter);
+	new_settings_callback(adapter->index, length, param, NULL);
 }
 
 static bool set_mode(uint16_t opcode, uint8_t mode)
@@ -323,8 +312,8 @@ static bool set_mode(uint16_t opcode, uint8_t mode)
 
 	DBG("opcode=0x%x mode=0x%x", opcode, mode);
 
-	if (mgmt_send(default_adapter->mgmt, opcode, default_adapter->index,
-			sizeof(cp), &cp, set_mode_complete, NULL, NULL) > 0)
+	if (mgmt_send(adapter->mgmt, opcode, adapter->index, sizeof(cp), &cp,
+					set_mode_complete, NULL, NULL) > 0)
 		return true;
 
 	error("Failed to set mode");
@@ -339,7 +328,7 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 
 	switch (opcode) {
 	case HAL_OP_ENABLE:
-		if (default_adapter->current_settings & MGMT_SETTING_POWERED) {
+		if (adapter->current_settings & MGMT_SETTING_POWERED) {
 			status = HAL_ERROR_DONE;
 			break;
 		}
@@ -351,7 +340,7 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 		}
 		break;
 	case HAL_OP_DISABLE:
-		if (!(default_adapter->current_settings & MGMT_SETTING_POWERED)) {
+		if (!(adapter->current_settings & MGMT_SETTING_POWERED)) {
 			status = HAL_ERROR_DONE;
 			break;
 		}
@@ -372,7 +361,7 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 
 const bdaddr_t *bt_adapter_get_address(void)
 {
-	return &default_adapter->bdaddr;
+	return &adapter->bdaddr;
 }
 
 bool bt_adapter_register(GIOChannel *io)
-- 
1.8.4


^ permalink raw reply related

* [PATCH v2 3/5] android: Remove not needed adapter parameter from bt_adapter_ready
From: Szymon Janc @ 2013-10-24  9:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382608464-10389-1-git-send-email-szymon.janc@tieto.com>

From: Szymon Janc <szymon.janc@gmail.com>

There is no need to pass adapter pointer in bt_adapter_ready callback
as there is only one present.
---
 android/adapter.c | 6 +++---
 android/adapter.h | 4 +---
 android/main.c    | 2 +-
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 79cfcfd..aee9cf4 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -201,11 +201,11 @@ static void load_link_keys_complete(uint8_t status, uint16_t length,
 	DBG("status %u", status);
 
 	default_adapter = adapter;
-	adapter->ready(adapter, 0);
+	adapter->ready(0);
 	return;
 
 failed:
-	adapter->ready(NULL, err);
+	adapter->ready(err);
 }
 
 static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
@@ -274,7 +274,7 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
 	return;
 
 failed:
-	adapter->ready(NULL, err);
+	adapter->ready(err);
 }
 
 void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
diff --git a/android/adapter.h b/android/adapter.h
index 236f10a..2afc67a 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -28,9 +28,7 @@
 
 #include "lib/bluetooth.h"
 
-struct bt_adapter;
-
-typedef void (*bt_adapter_ready)(struct bt_adapter *adapter, int err);
+typedef void (*bt_adapter_ready)(int err);
 
 void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 							bt_adapter_ready cb);
diff --git a/android/main.c b/android/main.c
index 740b532..50b5901 100644
--- a/android/main.c
+++ b/android/main.c
@@ -392,7 +392,7 @@ static GOptionEntry options[] = {
 	{ NULL }
 };
 
-static void adapter_ready(struct bt_adapter *adapter, int err)
+static void adapter_ready(int err)
 {
 	if (err) {
 		error("Adapter initialization failed: %s", strerror(err));
-- 
1.8.4


^ permalink raw reply related

* [PATCH v2 2/5] android: Fix bt_adapter_init
From: Szymon Janc @ 2013-10-24  9:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382608464-10389-1-git-send-email-szymon.janc@tieto.com>

From: Szymon Janc <szymon.janc@gmail.com>

Make bt_adapter_init return void and use ready callback for error
reporting. This also fix returning incorrect status and invalid
mgmt_if unref (mgmt_send return 0 on error or >0 on success).
---
 android/adapter.c | 15 +++++++--------
 android/adapter.h |  4 ++--
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 88ac19f..79cfcfd 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -277,8 +277,8 @@ failed:
 	adapter->ready(NULL, err);
 }
 
-bool bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
-						bt_adapter_ready ready)
+void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
+							bt_adapter_ready cb)
 {
 	struct bt_adapter *adapter;
 
@@ -286,15 +286,14 @@ bool bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 
 	adapter->mgmt = mgmt_ref(mgmt_if);
 	adapter->index = index;
-	adapter->ready = ready;
+	adapter->ready = cb;
 
 	if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
-				read_info_complete, adapter, NULL) > 0) {
-		mgmt_unref(mgmt_if);
-		return false;
-	}
+				read_info_complete, adapter, NULL) > 0)
+		return;
 
-	return adapter;
+	mgmt_unref(mgmt_if);
+	adapter->ready(-EIO);
 }
 
 static void set_mode_complete(uint8_t status, uint16_t length,
diff --git a/android/adapter.h b/android/adapter.h
index b8d0a58..236f10a 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -32,8 +32,8 @@ struct bt_adapter;
 
 typedef void (*bt_adapter_ready)(struct bt_adapter *adapter, int err);
 
-bool bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
-						bt_adapter_ready func);
+void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
+							bt_adapter_ready cb);
 
 void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 								uint16_t len);
-- 
1.8.4


^ permalink raw reply related

* [PATCH v2 1/5] android: Start command watch after notify channel is connected
From: Szymon Janc @ 2013-10-24  9:54 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

From: Szymon Janc <szymon.janc@gmail.com>

Daemon should start processing commands only after both communication
channels were connected.
---
 android/main.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/android/main.c b/android/main.c
index 9879f05..740b532 100644
--- a/android/main.c
+++ b/android/main.c
@@ -288,9 +288,11 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
 
 	g_io_add_watch(io, cond, notif_watch_cb, NULL);
 
-	info("Successfully connected to HAL");
+	cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
 
-	/* TODO start handling commands */
+	g_io_add_watch(hal_cmd_io, cond, cmd_watch_cb, NULL);
+
+	info("Successfully connected to HAL");
 
 	return FALSE;
 }
@@ -305,10 +307,6 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
 		return FALSE;
 	}
 
-	cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
-
-	g_io_add_watch(io, cond, cmd_watch_cb, NULL);
-
 	hal_notif_io = connect_hal(notif_connect_cb);
 	if (!hal_notif_io) {
 		error("Cannot connect to HAL, terminating");
-- 
1.8.4


^ permalink raw reply related

* [PATCH v2] android/client: Fix various coding style issues
From: Jerzy Kasenberg @ 2013-10-24  9:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg

Mostly indentation of arguments in functions and calls.
Prefix p remove from puser/penum_func.
Some empty lines added after closing } when needed.
Magic number for string length changed to preprocessor define.
Added spaces after casts.
---
 
v2:
 - fixed casts

 android/client/haltest.c       |   18 +++--
 android/client/if-bt.c         |  154 ++++++++++++++++++++++------------------
 android/client/if-hh.c         |   64 ++++++++---------
 android/client/if-main.h       |   12 ++--
 android/client/if-pan.c        |   34 ++++-----
 android/client/if-sock.c       |   26 +++----
 android/client/tabcompletion.c |    8 +--
 android/client/terminal.c      |    5 ++
 android/client/textconv.h      |    2 +-
 9 files changed, 175 insertions(+), 148 deletions(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index 19e81b8..189af0b 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -47,6 +47,7 @@ struct method *get_method(struct method *methods, const char *name)
 			return methods;
 		methods++;
 	}
+
 	return NULL;
 }
 
@@ -103,11 +104,11 @@ static void help_print_interface(const struct interface *i)
 }
 
 /* Help completion */
-static void help_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+static void help_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 2)
-		*penum_func = interface_name;
+		*enum_func = interface_name;
 }
 
 /* Help execution */
@@ -125,11 +126,13 @@ static void help_p(int argc, const char **argv)
 						(m->help ? m->help : ""));
 			m++;
 		}
+
 		terminal_print("\nAvailable interfaces to use:\n");
 		while (NULL != *ip) {
 			terminal_print("\t%s\n", (*ip)->name);
 			ip++;
 		}
+
 		terminal_print("\nTo get help on methods for each interface type:\n");
 		terminal_print("\n\thelp <inerface>\n");
 		terminal_print("\nBasic scenario:\n\tadapter init\n");
@@ -138,11 +141,13 @@ static void help_p(int argc, const char **argv)
 		terminal_print("\thandsfree init\n\n");
 		return;
 	}
+
 	i = get_interface(argv[1]);
 	if (i == NULL) {
 		haltest_error("No such interface\n");
 		return;
 	}
+
 	help_print_interface(i);
 }
 
@@ -176,6 +181,7 @@ const char *interface_name(void *v, int i)
 const char *command_name(void *v, int i)
 {
 	int cmd_cnt = (int) (sizeof(commands)/sizeof(commands[0]) - 1);
+
 	if (i >= cmd_cnt)
 		return interface_name(v, i - cmd_cnt);
 	else
@@ -188,8 +194,7 @@ const char *command_name(void *v, int i)
  * Output argv is filled with pointers to arguments
  * returns number of tokens parsed - argc
  */
-static int command_line_to_argv(char *line_buffer,
-				char *argv[], int argv_size)
+static int command_line_to_argv(char *line_buffer, char *argv[], int argv_size)
 {
 	static const char *token_breaks = "\r\n\t ";
 	char *token;
@@ -220,15 +225,18 @@ static void process_line(char *line_buffer)
 			i++;
 			continue;
 		}
+
 		if (argc < 2 || strcmp(argv[1], "?") == 0) {
 			help_print_interface(interfaces[i]);
 			return;
 		}
+
 		m = get_method(interfaces[i]->methods, argv[1]);
 		if (m != NULL) {
 			m->func(argc, (const char **) argv);
 			return;
 		}
+
 		haltest_error("No function %s found\n", argv[1]);
 		return;
 	}
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index f5c84c1..dd5d12e 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -82,13 +82,14 @@ static char *btproperty2str(bt_property_t property)
 	char *p;
 
 	p = buf + sprintf(buf, "type=%s len=%d val=",
-			  bt_property_type_t2str(property.type), property.len);
+					bt_property_type_t2str(property.type),
+					property.len);
 
 	switch (property.type) {
 	case BT_PROPERTY_BDNAME:
 	case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
 		sprintf(p, "%*s", property.len,
-			((bt_bdname_t *) property.val)->name);
+					((bt_bdname_t *) property.val)->name);
 		break;
 
 	case BT_PROPERTY_BDADDR:
@@ -160,7 +161,7 @@ static char *btproperty2str(bt_property_t property)
 			bt_service_record_t *rec = property.val;
 
 			sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
-				rec->channel, rec->name);
+						rec->channel, rec->name);
 		}
 		break;
 
@@ -206,12 +207,14 @@ void add_remote_device(const bt_bdaddr_t *addr)
 			remote_devices_capacity = 0;
 			return;
 		}
+
 		remote_devices_capacity = 4;
 	}
 
 	/* Array is sorted, search for right place */
 	for (i = 0; i < remote_devices_cnt; ++i) {
 		int res = memcmp(&remote_devices[i], addr, sizeof(*addr));
+
 		if (res == 0)
 			return; /* Already added */
 		else if (res > 0)
@@ -259,6 +262,7 @@ static void add_remote_device_from_props(int num_properties,
 		 * aligned buffer
 		 */
 		bt_property_t property;
+
 		memcpy(&property, properties + i, sizeof(property));
 		if (property.type == BT_PROPERTY_BDADDR)
 			add_remote_device((bt_bdaddr_t *) property.val);
@@ -270,21 +274,23 @@ static void adapter_state_changed_cb(bt_state_t state)
 	haltest_info("%s: state=%s\n", __func__, bt_state_t2str(state));
 }
 
-static void adapter_properties_cb(bt_status_t status,
-	int num_properties, bt_property_t *properties)
+static void adapter_properties_cb(bt_status_t status, int num_properties,
+						bt_property_t *properties)
 {
-	haltest_info("%s: status=%s num_properties=%d\n",
-	       __func__, bt_status_t2str(status), num_properties);
+	haltest_info("%s: status=%s num_properties=%d\n", __func__,
+				bt_status_t2str(status), num_properties);
 
 	dump_properties(num_properties, properties);
 }
 
 static void remote_device_properties_cb(bt_status_t status,
-	bt_bdaddr_t *bd_addr, int num_properties, bt_property_t *properties)
+					bt_bdaddr_t *bd_addr,
+					int num_properties,
+					bt_property_t *properties)
 {
-	haltest_info("%s: status=%s bd_addr=%s num_properties=%d\n",
-	       __func__, bt_status_t2str(status), bdaddr2str(bd_addr),
-	       num_properties);
+	haltest_info("%s: status=%s bd_addr=%s num_properties=%d\n", __func__,
+			bt_status_t2str(status), bdaddr2str(bd_addr),
+			num_properties);
 
 	add_remote_device(bd_addr);
 
@@ -303,7 +309,7 @@ static void device_found_cb(int num_properties, bt_property_t *properties)
 static void discovery_state_changed_cb(bt_discovery_state_t state)
 {
 	haltest_info("%s: state=%s\n", __func__,
-		bt_discovery_state_t2str(state));
+					bt_discovery_state_t2str(state));
 }
 
 /*
@@ -311,16 +317,16 @@ static void discovery_state_changed_cb(bt_discovery_state_t state)
  * It's stored for command completion.
  */
 static char last_remote_addr[MAX_ADDR_STR_LEN];
-static bt_ssp_variant_t last_ssp_variant = (bt_ssp_variant_t)-1;
+static bt_ssp_variant_t last_ssp_variant = (bt_ssp_variant_t) -1;
 
 static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
-	uint32_t cod)
+								uint32_t cod)
 {
 	/* Store for command completion */
 	bt_bdaddr_t2str(remote_bd_addr, last_remote_addr);
 
 	haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x\n", __func__,
-				       last_remote_addr, bd_name->name, cod);
+					last_remote_addr, bd_name->name, cod);
 }
 
 static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
@@ -332,26 +338,26 @@ static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
 	last_ssp_variant = pairing_variant;
 
 	haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x pairing_variant=%s pass_key=%d\n",
-		     __func__, last_remote_addr, bd_name->name, cod,
-		     bt_ssp_variant_t2str(pairing_variant), pass_key);
+			__func__, last_remote_addr, bd_name->name, cod,
+			bt_ssp_variant_t2str(pairing_variant), pass_key);
 }
 
 static void bond_state_changed_cb(bt_status_t status,
-					bt_bdaddr_t *remote_bd_addr,
-					bt_bond_state_t state)
+						bt_bdaddr_t *remote_bd_addr,
+						bt_bond_state_t state)
 {
 	haltest_info("%s: status=%s remote_bd_addr=%s state=%s\n", __func__,
-		       bt_status_t2str(status), bdaddr2str(remote_bd_addr),
-		       bt_bond_state_t2str(state));
+			bt_status_t2str(status), bdaddr2str(remote_bd_addr),
+			bt_bond_state_t2str(state));
 }
 
 static void acl_state_changed_cb(bt_status_t status,
-					bt_bdaddr_t *remote_bd_addr,
-					bt_acl_state_t state)
+						bt_bdaddr_t *remote_bd_addr,
+						bt_acl_state_t state)
 {
 	haltest_info("%s: status=%s remote_bd_addr=%s state=%s\n", __func__,
-		       bt_status_t2str(status), bdaddr2str(remote_bd_addr),
-		       bt_acl_state_t2str(state));
+			bt_status_t2str(status), bdaddr2str(remote_bd_addr),
+			bt_acl_state_t2str(state));
 }
 
 static void thread_evt_cb(bt_cb_thread_evt evt)
@@ -409,7 +415,7 @@ static void init_p(int argc, const char **argv)
 	}
 
 	if_bluetooth =
-	    ((bluetooth_device_t *) device)->get_bluetooth_interface();
+		    ((bluetooth_device_t *) device)->get_bluetooth_interface();
 	if (!if_bluetooth) {
 		haltest_error("get_bluetooth_interface returned NULL\n");
 		return;
@@ -449,11 +455,11 @@ static void get_adapter_properties_p(int argc, const char **argv)
 }
 
 static void get_adapter_property_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = TYPE_ENUM(bt_property_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bt_property_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -468,21 +474,22 @@ static void get_adapter_property_p(int argc, const char **argv)
 }
 
 static const char * const names[] = {
-		"BT_PROPERTY_BDNAME",
-		"BT_PROPERTY_ADAPTER_SCAN_MODE",
-		"BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT", NULL
+	"BT_PROPERTY_BDNAME",
+	"BT_PROPERTY_ADAPTER_SCAN_MODE",
+	"BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT",
+	NULL
 };
 
 static void set_adapter_property_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = (void *) names;
-		*penum_func = enum_strings;
+		*user = (void *) names;
+		*enum_func = enum_strings;
 	} else if (argc == 4) {
 		if (0 == strcmp(argv[2], "BT_PROPERTY_ADAPTER_SCAN_MODE")) {
-			*puser = TYPE_ENUM(bt_scan_mode_t);
-			*penum_func = enum_defines;
+			*user = TYPE_ENUM(bt_scan_mode_t);
+			*enum_func = enum_defines;
 		}
 	}
 }
@@ -529,12 +536,12 @@ static void set_adapter_property_p(int argc, const char **argv)
 /*
  * This function is to be used for completion methods that need only address
  */
-static void complete_addr_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+static void complete_addr_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = NULL;
-		*penum_func = enum_devices;
+		*user = NULL;
+		*enum_func = enum_devices;
 	}
 }
 
@@ -552,15 +559,15 @@ static void get_remote_device_properties_p(int argc, const char **argv)
 }
 
 static void get_remote_device_property_c(int argc, const char **argv,
-						enum_func *penum_func,
-								void **puser)
+							enum_func *enum_func,
+							void **user)
 {
 	if (argc == 3) {
-		*puser = NULL;
-		*penum_func = enum_devices;
+		*user = NULL;
+		*enum_func = enum_devices;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(bt_property_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bt_property_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -596,7 +603,6 @@ static void set_remote_device_property_p(int argc, const char **argv)
 		property.len = strlen(argv[4]);
 		property.val = (char *) argv[4];
 		break;
-
 	default:
 		return;
 	}
@@ -621,6 +627,7 @@ static void get_remote_service_record_p(int argc, const char **argv)
 		haltest_error("No uuid specified\n");
 		return;
 	}
+
 	str2bt_uuid_t(argv[3], &uuid);
 
 	EXEC(if_bluetooth->get_remote_service_record, &addr, &uuid);
@@ -692,13 +699,14 @@ static void cancel_bond_p(int argc, const char **argv)
 	EXEC(if_bluetooth->cancel_bond, &addr);
 }
 
-static void pin_reply_c(int argc, const char **argv,
-		enum_func *penum_func, void **puser)
+static void pin_reply_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	static const char *const completions[] = { last_remote_addr, NULL };
+
 	if (argc == 3) {
-		*puser = (void *) completions;
-		*penum_func = enum_strings;
+		*user = (void *) completions;
+		*enum_func = enum_strings;
 	}
 }
 
@@ -721,22 +729,22 @@ static void pin_reply_p(int argc, const char **argv)
 	EXEC(if_bluetooth->pin_reply, &addr, accept, pin_len, &pin);
 }
 
-static void ssp_reply_c(int argc, const char **argv,
-		enum_func *penum_func, void **puser)
+static void ssp_reply_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = last_remote_addr;
-		*penum_func = enum_one_string;
+		*user = last_remote_addr;
+		*enum_func = enum_one_string;
 	} else if (argc == 5) {
-		*puser = "1";
-		*penum_func = enum_one_string;
+		*user = "1";
+		*enum_func = enum_one_string;
 	} else if (argc == 4) {
 		if (-1 != (int) last_ssp_variant) {
-			*puser = (void *) bt_ssp_variant_t2str(last_ssp_variant);
-			*penum_func = enum_one_string;
+			*user = (void *) bt_ssp_variant_t2str(last_ssp_variant);
+			*enum_func = enum_one_string;
 		} else {
-			*puser = TYPE_ENUM(bt_ssp_variant_t);
-			*penum_func = enum_defines;
+			*user = TYPE_ENUM(bt_ssp_variant_t);
+			*enum_func = enum_defines;
 		}
 	}
 }
@@ -755,11 +763,13 @@ static void ssp_reply_p(int argc, const char **argv)
 		haltest_error("No ssp variant specified\n");
 		return;
 	}
+
 	var = str2btsspvariant(argv[3]);
 	if (argc < 5) {
 		haltest_error("No accept value specified\n");
 		return;
 	}
+
 	accept = atoi(argv[4]);
 	passkey = 0;
 
@@ -770,7 +780,7 @@ static void ssp_reply_p(int argc, const char **argv)
 }
 
 static void get_profile_interface_c(int argc, const char **argv,
-		enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	static const char *const profile_ids[] = {
 		BT_PROFILE_HANDSFREE_ID,
@@ -787,8 +797,8 @@ static void get_profile_interface_c(int argc, const char **argv,
 	};
 
 	if (argc == 3) {
-		*puser = (void *) profile_ids;
-		*penum_func = enum_strings;
+		*user = (void *) profile_ids;
+		*enum_func = enum_strings;
 	}
 }
 
@@ -803,22 +813,22 @@ static void get_profile_interface_p(int argc, const char **argv)
 	if (strcmp(BT_PROFILE_HANDSFREE_ID, id) == 0)
 		pif = &dummy; /* TODO: change when if_hf is there */
 	else if (strcmp(BT_PROFILE_ADVANCED_AUDIO_ID, id) == 0)
-		pif = (const void **)&if_av;
+		pif = (const void **) &if_av;
 	else if (strcmp(BT_PROFILE_HEALTH_ID, id) == 0)
 		pif = &dummy; /* TODO: change when if_hl is there */
 	else if (strcmp(BT_PROFILE_SOCKETS_ID, id) == 0)
-		pif = (const void **)&if_sock;
+		pif = (const void **) &if_sock;
 	else if (strcmp(BT_PROFILE_HIDHOST_ID, id) == 0)
-		pif = (const void **)&if_hh;
+		pif = (const void **) &if_hh;
 	else if (strcmp(BT_PROFILE_PAN_ID, id) == 0)
-		pif = (const void **)&if_pan;
+		pif = (const void **) &if_pan;
 #if PLATFORM_SDK_VERSION > 17
 	else if (strcmp(BT_PROFILE_AV_RC_ID, id) == 0)
 		pif = &dummy; /* TODO: change when if_rc is there */
 #endif
 	else
 		haltest_error("%s is not correct for get_profile_interface\n",
-		     id);
+									id);
 
 	if (pif != NULL) {
 		*pif = if_bluetooth->get_profile_interface(id);
@@ -836,6 +846,7 @@ static void dut_mode_configure_p(int argc, const char **argv)
 		haltest_error("No dut mode specified\n");
 		return;
 	}
+
 	mode = strtol(argv[2], NULL, 0);
 
 	EXEC(if_bluetooth->dut_mode_configure, mode);
@@ -851,7 +862,8 @@ static struct method methods[] = {
 	STD_METHODCH(set_adapter_property, "<prop_type> <prop_value>"),
 	STD_METHODCH(get_remote_device_properties, "<addr>"),
 	STD_METHODCH(get_remote_device_property, "<addr> <property_type>"),
-	STD_METHODCH(set_remote_device_property, "<addr> <property_type> <value>"),
+	STD_METHODCH(set_remote_device_property,
+					"<addr> <property_type> <value>"),
 	STD_METHODCH(get_remote_service_record, "<addr> <uuid>"),
 	STD_METHODCH(get_remote_services, "<addr>"),
 	STD_METHOD(start_discovery),
diff --git a/android/client/if-hh.c b/android/client/if-hh.c
index e23e4d5..005b13a 100644
--- a/android/client/if-hh.c
+++ b/android/client/if-hh.c
@@ -79,7 +79,7 @@ static void connection_state_cb(bt_bdaddr_t *bd_addr,
 	char addr[MAX_ADDR_STR_LEN];
 
 	haltest_info("%s: bd_addr=%s connection_state=%s\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
+					bt_bdaddr_t2str(bd_addr, addr),
 					bthh_connection_state_t2str(state));
 	if (state == BTHH_CONN_STATE_CONNECTED)
 		strcpy(connected_device_addr, addr);
@@ -94,7 +94,7 @@ static void virtual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status)
 	char addr[MAX_ADDR_STR_LEN];
 
 	haltest_info("%s: bd_addr=%s hh_status=%s\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
+						bt_bdaddr_t2str(bd_addr, addr),
 						bthh_status_t2str(hh_status));
 }
 
@@ -122,9 +122,9 @@ static void protocol_mode_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
 	char addr[MAX_ADDR_STR_LEN];
 
 	haltest_info("%s: bd_addr=%s hh_status=%s mode=%s\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
-			bthh_status_t2str(hh_status),
-						bthh_protocol_mode_t2str(mode));
+					bt_bdaddr_t2str(bd_addr, addr),
+					bthh_status_t2str(hh_status),
+					bthh_protocol_mode_t2str(mode));
 }
 
 /*
@@ -136,8 +136,8 @@ static void idle_time_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
 	char addr[MAX_ADDR_STR_LEN];
 
 	haltest_info("%s: bd_addr=%s hh_status=%s idle_rate=%d\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
-			bthh_status_t2str(hh_status), idle_rate);
+				bt_bdaddr_t2str(bd_addr, addr),
+				bthh_status_t2str(hh_status), idle_rate);
 }
 
 
@@ -152,8 +152,8 @@ static void get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
 
 	/* TODO: print actual report */
 	haltest_info("%s: bd_addr=%s hh_status=%s rpt_size=%d\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
-			bthh_status_t2str(hh_status), rpt_size);
+					bt_bdaddr_t2str(bd_addr, addr),
+					bthh_status_t2str(hh_status), rpt_size);
 }
 
 static bthh_callbacks_t bthh_callbacks = {
@@ -177,12 +177,12 @@ static void init_p(int argc, const char **argv)
 
 /* connect */
 
-static void connect_c(int argc, const const char **argv,
-				enum_func *penum_func, void **puser)
+static void connect_c(int argc, const const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = (void *) connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = (void *) connected_device_addr;
+		*enum_func = enum_one_string;
 	}
 }
 
@@ -243,14 +243,14 @@ static void set_info_p(int argc, const char **argv)
 /* get_protocol */
 
 static void get_protocol_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = connected_device_addr;
+		*enum_func = enum_one_string;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(bthh_protocol_mode_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bthh_protocol_mode_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -296,14 +296,14 @@ static void set_protocol_p(int argc, const char **argv)
 /* get_report */
 
 static void get_report_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = connected_device_addr;
+		*enum_func = enum_one_string;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(bthh_report_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bthh_report_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -341,14 +341,14 @@ static void get_report_p(int argc, const char **argv)
 /* set_report */
 
 static void set_report_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = connected_device_addr;
+		*enum_func = enum_one_string;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(bthh_report_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bthh_report_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -376,12 +376,12 @@ static void set_report_p(int argc, const char **argv)
 
 /* send_data */
 
-static void send_data_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+static void send_data_c(int argc, const const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = connected_device_addr;
+		*enum_func = enum_one_string;
 	}
 }
 
diff --git a/android/client/if-main.h b/android/client/if-main.h
index f2d35d9..eaee914 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -93,11 +93,11 @@ typedef const char *(*enum_func)(void *user, int i);
 
 /*
  * This is prototype of function that when given argc, argv will
- * fill penum_func with pointer to function that will enumerate
- * parameters for argc argument, puser will be passed to penum_func.
+ * fill enum_func with pointer to function that will enumerate
+ * parameters for argc argument, user will be passed to enum_func.
  */
-typedef void (*tab_complete)(int argc, const char **argv,
-					enum_func *penum_func, void **puser);
+typedef void (*tab_complete)(int argc, const char **argv, enum_func *enum_func,
+								void **user);
 
 /*
  * For each method there is name and two functions to parse command line
@@ -145,9 +145,9 @@ struct method *get_command(const char *name);
 
 #define VERIFY_ADDR_ARG(n, adr) \
 	do { \
-		if (n < argc) \
+		if (n < argc) {\
 			str2bt_bdaddr_t(argv[n], adr); \
-		else { \
+		} else { \
 			haltest_error("No address specified\n");\
 			return;\
 		} \
diff --git a/android/client/if-pan.c b/android/client/if-pan.c
index e9cfa23..dcc7e80 100644
--- a/android/client/if-pan.c
+++ b/android/client/if-pan.c
@@ -45,12 +45,12 @@ static void control_state_cb(btpan_control_state_t state, bt_status_t error,
 					int local_role, const char *ifname)
 {
 	haltest_info("%s: state=%s error=%s local_role=%s ifname=%s\n",
-		       __func__, btpan_control_state_t2str(state),
-		       bt_status_t2str(error), btpan_role_t2str(local_role),
-		       ifname);
+			__func__, btpan_control_state_t2str(state),
+			bt_status_t2str(error), btpan_role_t2str(local_role),
+			ifname);
 }
 
-static char last_used_addr[18];
+static char last_used_addr[MAX_ADDR_STR_LEN];
 
 static void connection_state_cb(btpan_connection_state_t state,
 				bt_status_t error, const bt_bdaddr_t *bd_addr,
@@ -79,12 +79,12 @@ static void init_p(int argc, const char **argv)
 
 /* enable */
 
-static void enable_c(int argc, const const char **argv, enum_func *penum_func,
-								void **puser)
+static void enable_c(int argc, const const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = TYPE_ENUM(btpan_role_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(btpan_role_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -120,15 +120,15 @@ static void get_local_role_p(int argc, const char **argv)
 
 /* connect */
 
-static void connect_c(int argc, const const char **argv, enum_func *penum_func,
-								void **puser)
+static void connect_c(int argc, const const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = NULL;
-		*penum_func = enum_devices;
+		*user = NULL;
+		*enum_func = enum_devices;
 	} else if (argc == 4 || argc == 5) {
-		*puser = TYPE_ENUM(btpan_role_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(btpan_role_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -165,11 +165,11 @@ static void connect_p(int argc, const char **argv)
 /* disconnect */
 
 static void disconnect_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = last_used_addr;
-		*penum_func = enum_one_string;
+		*user = last_used_addr;
+		*enum_func = enum_one_string;
 	}
 }
 
diff --git a/android/client/if-sock.c b/android/client/if-sock.c
index f3125f8..dcaf048 100644
--- a/android/client/if-sock.c
+++ b/android/client/if-sock.c
@@ -52,7 +52,6 @@ static void receive_from_client(struct pollfd *pollfd)
 		haltest_error("Disconnected fd=%d\n", pollfd->fd);
 		poll_unregister_fd(pollfd->fd, receive_from_client);
 	} else if (pollfd->revents & POLLIN) {
-
 		haltest_info("receiving from client fd=%d\n", pollfd->fd);
 
 		do {
@@ -95,9 +94,10 @@ static void receive_sock_connect_signal(struct pollfd *pollfd)
 			haltest_info("Read on connect return %d\n", ret);
 			return;
 		}
+
 		haltest_info("Connection to %s channel %d status=%d\n",
 				bt_bdaddr_t2str(&cs.bd_addr, addr_str),
-							cs.channel, cs.status);
+				cs.channel, cs.status);
 
 		if (cs.status == 0)
 			poll_register_fd(pollfd->fd, POLLIN,
@@ -106,7 +106,7 @@ static void receive_sock_connect_signal(struct pollfd *pollfd)
 
 	if (pollfd->revents & POLLHUP) {
 		haltest_error("Disconnected fd=%d revents=0x%X\n", pollfd->fd,
-							pollfd->revents);
+				pollfd->revents);
 		poll_unregister_fd(pollfd->fd, receive_sock_connect_signal);
 	}
 }
@@ -165,6 +165,7 @@ static void read_accepted(int fd)
 		accepted_fd = descs[0];
 		break;
 	}
+
 	haltest_info("Incoming connection from %s channel %d status=%d fd=%d\n",
 					bt_bdaddr_t2str(&cs.bd_addr, addr_str),
 					cs.channel, cs.status, accepted_fd);
@@ -184,12 +185,12 @@ static void client_connected(struct pollfd *pollfd)
 
 /** listen */
 
-static void listen_c(int argc, const char **argv, enum_func *penum_func,
-								void **puser)
+static void listen_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = TYPE_ENUM(btsock_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(btsock_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -253,14 +254,14 @@ static void listen_p(int argc, const char **argv)
 
 /** connect */
 
-static void connect_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+static void connect_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*penum_func = enum_devices;
+		*enum_func = enum_devices;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(btsock_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(btsock_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -313,6 +314,7 @@ static void connect_p(int argc, const char **argv)
 	if (sock_fd > 0) {
 		int channel = 0;
 		int ret = read(sock_fd, &channel, 4);
+
 		if (ret != 4)
 			haltest_info("Read channel failed\n");
 		haltest_info("Channel returned from first read %d\n", channel);
diff --git a/android/client/tabcompletion.c b/android/client/tabcompletion.c
index 2b95591..69af609 100644
--- a/android/client/tabcompletion.c
+++ b/android/client/tabcompletion.c
@@ -63,8 +63,8 @@ static void print_matches(enum_func f, void *user, const char *prefix, int len)
  * buf - output buffer to keep splited arguments list
  * buf_size_in_bytes - size of buf
  */
-static int split_command(const char *line_buffer, int size,
-					split_arg_t *buf, int buf_size_in_bytes)
+static int split_command(const char *line_buffer, int size, split_arg_t *buf,
+							int buf_size_in_bytes)
 {
 	split_arg_t *prev = NULL;
 	split_arg_t *arg = buf;
@@ -218,8 +218,8 @@ static void method_completion(const struct interface *iface, split_arg_t *arg)
 static const char *bold = "\x1b[1m";
 static const char *normal = "\x1b[0m";
 
-static bool find_nth_argument(const char *str, int n,
-						const char **s, const char **e)
+static bool find_nth_argument(const char *str, int n, const char **s,
+								const char **e)
 {
 	const char *p = str;
 	int argc = 0;
diff --git a/android/client/terminal.c b/android/client/terminal.c
index a57068a..88c963b 100644
--- a/android/client/terminal.c
+++ b/android/client/terminal.c
@@ -214,6 +214,7 @@ static void terminal_line_replaced(void)
 			putchar('\b');
 			line_buf_ix--;
 		}
+
 		/* If cursor was not at the end, move it to the end */
 		if (line_buf_ix < line_len)
 			printf("%.*s", line_len - line_buf_ix,
@@ -222,6 +223,7 @@ static void terminal_line_replaced(void)
 		while (line_len >= len++)
 			putchar(' ');
 	}
+
 	/* draw new line */
 	printf("\r%s%s", prompt, line_buf);
 	/* set up indexes to new line */
@@ -321,6 +323,7 @@ static int terminal_convert_sequence(int c)
 	       }
 	       return c;
 	}
+
 	/* Inside sequence */
 	current_sequence[current_sequence_len++] = c;
 	current_sequence[current_sequence_len] = '\0';
@@ -338,6 +341,7 @@ static int terminal_convert_sequence(int c)
 		/* partial match (not whole sequence yet) */
 		return KEY_SEQUNCE_NOT_FINISHED;
 	}
+
 	terminal_print("ansii char 0x%X %c\n", c);
 	/*
 	 * Sequence does not match
@@ -530,6 +534,7 @@ void terminal_process_char(int c, void (*process_line)(char *line))
 			printf("char-0x%02x\n", c);
 			break;
 		}
+
 		if (line_buf_ix < LINE_BUF_MAX - 1) {
 			if (line_len == line_buf_ix) {
 				putchar(c);
diff --git a/android/client/textconv.h b/android/client/textconv.h
index 056e706..085b141 100644
--- a/android/client/textconv.h
+++ b/android/client/textconv.h
@@ -58,7 +58,7 @@ const char *enum_defines(void *v, int i);
 const char *enum_strings(void *v, int i);
 const char *enum_one_string(void *v, int i);
 
-#define TYPE_ENUM(type) ((void *)&__##type##2str[0])
+#define TYPE_ENUM(type) ((void *) &__##type##2str[0])
 #define DECINTMAP(type) \
 extern struct int2str __##type##2str[]; \
 const char *type##2##str(type v); \
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH] android/client: Fix various coding style issues
From: Jerzy Kasenberg @ 2013-10-24  8:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg

Mostly indentation of arguments in functions and calls.
Prefix p remove from puser/penum_func.
Some empty lines added after closing } when needed.
Magic number for string length changed to preprocessor define.
---
 android/client/haltest.c       |   18 +++--
 android/client/if-bt.c         |  144 ++++++++++++++++++++++------------------
 android/client/if-hh.c         |   64 +++++++++---------
 android/client/if-main.h       |   12 ++--
 android/client/if-pan.c        |   34 +++++-----
 android/client/if-sock.c       |   26 ++++----
 android/client/tabcompletion.c |    8 +--
 android/client/terminal.c      |    5 ++
 8 files changed, 169 insertions(+), 142 deletions(-)

diff --git a/android/client/haltest.c b/android/client/haltest.c
index 19e81b8..189af0b 100644
--- a/android/client/haltest.c
+++ b/android/client/haltest.c
@@ -47,6 +47,7 @@ struct method *get_method(struct method *methods, const char *name)
 			return methods;
 		methods++;
 	}
+
 	return NULL;
 }
 
@@ -103,11 +104,11 @@ static void help_print_interface(const struct interface *i)
 }
 
 /* Help completion */
-static void help_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+static void help_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 2)
-		*penum_func = interface_name;
+		*enum_func = interface_name;
 }
 
 /* Help execution */
@@ -125,11 +126,13 @@ static void help_p(int argc, const char **argv)
 						(m->help ? m->help : ""));
 			m++;
 		}
+
 		terminal_print("\nAvailable interfaces to use:\n");
 		while (NULL != *ip) {
 			terminal_print("\t%s\n", (*ip)->name);
 			ip++;
 		}
+
 		terminal_print("\nTo get help on methods for each interface type:\n");
 		terminal_print("\n\thelp <inerface>\n");
 		terminal_print("\nBasic scenario:\n\tadapter init\n");
@@ -138,11 +141,13 @@ static void help_p(int argc, const char **argv)
 		terminal_print("\thandsfree init\n\n");
 		return;
 	}
+
 	i = get_interface(argv[1]);
 	if (i == NULL) {
 		haltest_error("No such interface\n");
 		return;
 	}
+
 	help_print_interface(i);
 }
 
@@ -176,6 +181,7 @@ const char *interface_name(void *v, int i)
 const char *command_name(void *v, int i)
 {
 	int cmd_cnt = (int) (sizeof(commands)/sizeof(commands[0]) - 1);
+
 	if (i >= cmd_cnt)
 		return interface_name(v, i - cmd_cnt);
 	else
@@ -188,8 +194,7 @@ const char *command_name(void *v, int i)
  * Output argv is filled with pointers to arguments
  * returns number of tokens parsed - argc
  */
-static int command_line_to_argv(char *line_buffer,
-				char *argv[], int argv_size)
+static int command_line_to_argv(char *line_buffer, char *argv[], int argv_size)
 {
 	static const char *token_breaks = "\r\n\t ";
 	char *token;
@@ -220,15 +225,18 @@ static void process_line(char *line_buffer)
 			i++;
 			continue;
 		}
+
 		if (argc < 2 || strcmp(argv[1], "?") == 0) {
 			help_print_interface(interfaces[i]);
 			return;
 		}
+
 		m = get_method(interfaces[i]->methods, argv[1]);
 		if (m != NULL) {
 			m->func(argc, (const char **) argv);
 			return;
 		}
+
 		haltest_error("No function %s found\n", argv[1]);
 		return;
 	}
diff --git a/android/client/if-bt.c b/android/client/if-bt.c
index f5c84c1..4dc9f6b 100644
--- a/android/client/if-bt.c
+++ b/android/client/if-bt.c
@@ -82,13 +82,14 @@ static char *btproperty2str(bt_property_t property)
 	char *p;
 
 	p = buf + sprintf(buf, "type=%s len=%d val=",
-			  bt_property_type_t2str(property.type), property.len);
+					bt_property_type_t2str(property.type),
+					property.len);
 
 	switch (property.type) {
 	case BT_PROPERTY_BDNAME:
 	case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
 		sprintf(p, "%*s", property.len,
-			((bt_bdname_t *) property.val)->name);
+					((bt_bdname_t *) property.val)->name);
 		break;
 
 	case BT_PROPERTY_BDADDR:
@@ -160,7 +161,7 @@ static char *btproperty2str(bt_property_t property)
 			bt_service_record_t *rec = property.val;
 
 			sprintf(p, "{%s, %d, %s}", btuuid2str(&rec->uuid),
-				rec->channel, rec->name);
+						rec->channel, rec->name);
 		}
 		break;
 
@@ -206,12 +207,14 @@ void add_remote_device(const bt_bdaddr_t *addr)
 			remote_devices_capacity = 0;
 			return;
 		}
+
 		remote_devices_capacity = 4;
 	}
 
 	/* Array is sorted, search for right place */
 	for (i = 0; i < remote_devices_cnt; ++i) {
 		int res = memcmp(&remote_devices[i], addr, sizeof(*addr));
+
 		if (res == 0)
 			return; /* Already added */
 		else if (res > 0)
@@ -259,6 +262,7 @@ static void add_remote_device_from_props(int num_properties,
 		 * aligned buffer
 		 */
 		bt_property_t property;
+
 		memcpy(&property, properties + i, sizeof(property));
 		if (property.type == BT_PROPERTY_BDADDR)
 			add_remote_device((bt_bdaddr_t *) property.val);
@@ -270,21 +274,23 @@ static void adapter_state_changed_cb(bt_state_t state)
 	haltest_info("%s: state=%s\n", __func__, bt_state_t2str(state));
 }
 
-static void adapter_properties_cb(bt_status_t status,
-	int num_properties, bt_property_t *properties)
+static void adapter_properties_cb(bt_status_t status, int num_properties,
+						bt_property_t *properties)
 {
-	haltest_info("%s: status=%s num_properties=%d\n",
-	       __func__, bt_status_t2str(status), num_properties);
+	haltest_info("%s: status=%s num_properties=%d\n", __func__,
+				bt_status_t2str(status), num_properties);
 
 	dump_properties(num_properties, properties);
 }
 
 static void remote_device_properties_cb(bt_status_t status,
-	bt_bdaddr_t *bd_addr, int num_properties, bt_property_t *properties)
+					bt_bdaddr_t *bd_addr,
+					int num_properties,
+					bt_property_t *properties)
 {
-	haltest_info("%s: status=%s bd_addr=%s num_properties=%d\n",
-	       __func__, bt_status_t2str(status), bdaddr2str(bd_addr),
-	       num_properties);
+	haltest_info("%s: status=%s bd_addr=%s num_properties=%d\n", __func__,
+			bt_status_t2str(status), bdaddr2str(bd_addr),
+			num_properties);
 
 	add_remote_device(bd_addr);
 
@@ -303,7 +309,7 @@ static void device_found_cb(int num_properties, bt_property_t *properties)
 static void discovery_state_changed_cb(bt_discovery_state_t state)
 {
 	haltest_info("%s: state=%s\n", __func__,
-		bt_discovery_state_t2str(state));
+					bt_discovery_state_t2str(state));
 }
 
 /*
@@ -314,13 +320,13 @@ static char last_remote_addr[MAX_ADDR_STR_LEN];
 static bt_ssp_variant_t last_ssp_variant = (bt_ssp_variant_t)-1;
 
 static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
-	uint32_t cod)
+								uint32_t cod)
 {
 	/* Store for command completion */
 	bt_bdaddr_t2str(remote_bd_addr, last_remote_addr);
 
 	haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x\n", __func__,
-				       last_remote_addr, bd_name->name, cod);
+					last_remote_addr, bd_name->name, cod);
 }
 
 static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
@@ -332,26 +338,26 @@ static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
 	last_ssp_variant = pairing_variant;
 
 	haltest_info("%s: remote_bd_addr=%s bd_name=%s cod=%06x pairing_variant=%s pass_key=%d\n",
-		     __func__, last_remote_addr, bd_name->name, cod,
-		     bt_ssp_variant_t2str(pairing_variant), pass_key);
+			__func__, last_remote_addr, bd_name->name, cod,
+			bt_ssp_variant_t2str(pairing_variant), pass_key);
 }
 
 static void bond_state_changed_cb(bt_status_t status,
-					bt_bdaddr_t *remote_bd_addr,
-					bt_bond_state_t state)
+						bt_bdaddr_t *remote_bd_addr,
+						bt_bond_state_t state)
 {
 	haltest_info("%s: status=%s remote_bd_addr=%s state=%s\n", __func__,
-		       bt_status_t2str(status), bdaddr2str(remote_bd_addr),
-		       bt_bond_state_t2str(state));
+			bt_status_t2str(status), bdaddr2str(remote_bd_addr),
+			bt_bond_state_t2str(state));
 }
 
 static void acl_state_changed_cb(bt_status_t status,
-					bt_bdaddr_t *remote_bd_addr,
-					bt_acl_state_t state)
+						bt_bdaddr_t *remote_bd_addr,
+						bt_acl_state_t state)
 {
 	haltest_info("%s: status=%s remote_bd_addr=%s state=%s\n", __func__,
-		       bt_status_t2str(status), bdaddr2str(remote_bd_addr),
-		       bt_acl_state_t2str(state));
+			bt_status_t2str(status), bdaddr2str(remote_bd_addr),
+			bt_acl_state_t2str(state));
 }
 
 static void thread_evt_cb(bt_cb_thread_evt evt)
@@ -409,7 +415,7 @@ static void init_p(int argc, const char **argv)
 	}
 
 	if_bluetooth =
-	    ((bluetooth_device_t *) device)->get_bluetooth_interface();
+		    ((bluetooth_device_t *) device)->get_bluetooth_interface();
 	if (!if_bluetooth) {
 		haltest_error("get_bluetooth_interface returned NULL\n");
 		return;
@@ -449,11 +455,11 @@ static void get_adapter_properties_p(int argc, const char **argv)
 }
 
 static void get_adapter_property_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = TYPE_ENUM(bt_property_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bt_property_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -468,21 +474,22 @@ static void get_adapter_property_p(int argc, const char **argv)
 }
 
 static const char * const names[] = {
-		"BT_PROPERTY_BDNAME",
-		"BT_PROPERTY_ADAPTER_SCAN_MODE",
-		"BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT", NULL
+	"BT_PROPERTY_BDNAME",
+	"BT_PROPERTY_ADAPTER_SCAN_MODE",
+	"BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT",
+	NULL
 };
 
 static void set_adapter_property_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = (void *) names;
-		*penum_func = enum_strings;
+		*user = (void *) names;
+		*enum_func = enum_strings;
 	} else if (argc == 4) {
 		if (0 == strcmp(argv[2], "BT_PROPERTY_ADAPTER_SCAN_MODE")) {
-			*puser = TYPE_ENUM(bt_scan_mode_t);
-			*penum_func = enum_defines;
+			*user = TYPE_ENUM(bt_scan_mode_t);
+			*enum_func = enum_defines;
 		}
 	}
 }
@@ -529,12 +536,12 @@ static void set_adapter_property_p(int argc, const char **argv)
 /*
  * This function is to be used for completion methods that need only address
  */
-static void complete_addr_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+static void complete_addr_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = NULL;
-		*penum_func = enum_devices;
+		*user = NULL;
+		*enum_func = enum_devices;
 	}
 }
 
@@ -552,15 +559,15 @@ static void get_remote_device_properties_p(int argc, const char **argv)
 }
 
 static void get_remote_device_property_c(int argc, const char **argv,
-						enum_func *penum_func,
-								void **puser)
+							enum_func *enum_func,
+							void **user)
 {
 	if (argc == 3) {
-		*puser = NULL;
-		*penum_func = enum_devices;
+		*user = NULL;
+		*enum_func = enum_devices;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(bt_property_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bt_property_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -596,7 +603,6 @@ static void set_remote_device_property_p(int argc, const char **argv)
 		property.len = strlen(argv[4]);
 		property.val = (char *) argv[4];
 		break;
-
 	default:
 		return;
 	}
@@ -621,6 +627,7 @@ static void get_remote_service_record_p(int argc, const char **argv)
 		haltest_error("No uuid specified\n");
 		return;
 	}
+
 	str2bt_uuid_t(argv[3], &uuid);
 
 	EXEC(if_bluetooth->get_remote_service_record, &addr, &uuid);
@@ -692,13 +699,14 @@ static void cancel_bond_p(int argc, const char **argv)
 	EXEC(if_bluetooth->cancel_bond, &addr);
 }
 
-static void pin_reply_c(int argc, const char **argv,
-		enum_func *penum_func, void **puser)
+static void pin_reply_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	static const char *const completions[] = { last_remote_addr, NULL };
+
 	if (argc == 3) {
-		*puser = (void *) completions;
-		*penum_func = enum_strings;
+		*user = (void *) completions;
+		*enum_func = enum_strings;
 	}
 }
 
@@ -721,22 +729,22 @@ static void pin_reply_p(int argc, const char **argv)
 	EXEC(if_bluetooth->pin_reply, &addr, accept, pin_len, &pin);
 }
 
-static void ssp_reply_c(int argc, const char **argv,
-		enum_func *penum_func, void **puser)
+static void ssp_reply_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = last_remote_addr;
-		*penum_func = enum_one_string;
+		*user = last_remote_addr;
+		*enum_func = enum_one_string;
 	} else if (argc == 5) {
-		*puser = "1";
-		*penum_func = enum_one_string;
+		*user = "1";
+		*enum_func = enum_one_string;
 	} else if (argc == 4) {
 		if (-1 != (int) last_ssp_variant) {
-			*puser = (void *) bt_ssp_variant_t2str(last_ssp_variant);
-			*penum_func = enum_one_string;
+			*user = (void *) bt_ssp_variant_t2str(last_ssp_variant);
+			*enum_func = enum_one_string;
 		} else {
-			*puser = TYPE_ENUM(bt_ssp_variant_t);
-			*penum_func = enum_defines;
+			*user = TYPE_ENUM(bt_ssp_variant_t);
+			*enum_func = enum_defines;
 		}
 	}
 }
@@ -755,11 +763,13 @@ static void ssp_reply_p(int argc, const char **argv)
 		haltest_error("No ssp variant specified\n");
 		return;
 	}
+
 	var = str2btsspvariant(argv[3]);
 	if (argc < 5) {
 		haltest_error("No accept value specified\n");
 		return;
 	}
+
 	accept = atoi(argv[4]);
 	passkey = 0;
 
@@ -770,7 +780,7 @@ static void ssp_reply_p(int argc, const char **argv)
 }
 
 static void get_profile_interface_c(int argc, const char **argv,
-		enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	static const char *const profile_ids[] = {
 		BT_PROFILE_HANDSFREE_ID,
@@ -787,8 +797,8 @@ static void get_profile_interface_c(int argc, const char **argv,
 	};
 
 	if (argc == 3) {
-		*puser = (void *) profile_ids;
-		*penum_func = enum_strings;
+		*user = (void *) profile_ids;
+		*enum_func = enum_strings;
 	}
 }
 
@@ -818,7 +828,7 @@ static void get_profile_interface_p(int argc, const char **argv)
 #endif
 	else
 		haltest_error("%s is not correct for get_profile_interface\n",
-		     id);
+									id);
 
 	if (pif != NULL) {
 		*pif = if_bluetooth->get_profile_interface(id);
@@ -836,6 +846,7 @@ static void dut_mode_configure_p(int argc, const char **argv)
 		haltest_error("No dut mode specified\n");
 		return;
 	}
+
 	mode = strtol(argv[2], NULL, 0);
 
 	EXEC(if_bluetooth->dut_mode_configure, mode);
@@ -851,7 +862,8 @@ static struct method methods[] = {
 	STD_METHODCH(set_adapter_property, "<prop_type> <prop_value>"),
 	STD_METHODCH(get_remote_device_properties, "<addr>"),
 	STD_METHODCH(get_remote_device_property, "<addr> <property_type>"),
-	STD_METHODCH(set_remote_device_property, "<addr> <property_type> <value>"),
+	STD_METHODCH(set_remote_device_property,
+					"<addr> <property_type> <value>"),
 	STD_METHODCH(get_remote_service_record, "<addr> <uuid>"),
 	STD_METHODCH(get_remote_services, "<addr>"),
 	STD_METHOD(start_discovery),
diff --git a/android/client/if-hh.c b/android/client/if-hh.c
index e23e4d5..005b13a 100644
--- a/android/client/if-hh.c
+++ b/android/client/if-hh.c
@@ -79,7 +79,7 @@ static void connection_state_cb(bt_bdaddr_t *bd_addr,
 	char addr[MAX_ADDR_STR_LEN];
 
 	haltest_info("%s: bd_addr=%s connection_state=%s\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
+					bt_bdaddr_t2str(bd_addr, addr),
 					bthh_connection_state_t2str(state));
 	if (state == BTHH_CONN_STATE_CONNECTED)
 		strcpy(connected_device_addr, addr);
@@ -94,7 +94,7 @@ static void virtual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status)
 	char addr[MAX_ADDR_STR_LEN];
 
 	haltest_info("%s: bd_addr=%s hh_status=%s\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
+						bt_bdaddr_t2str(bd_addr, addr),
 						bthh_status_t2str(hh_status));
 }
 
@@ -122,9 +122,9 @@ static void protocol_mode_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
 	char addr[MAX_ADDR_STR_LEN];
 
 	haltest_info("%s: bd_addr=%s hh_status=%s mode=%s\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
-			bthh_status_t2str(hh_status),
-						bthh_protocol_mode_t2str(mode));
+					bt_bdaddr_t2str(bd_addr, addr),
+					bthh_status_t2str(hh_status),
+					bthh_protocol_mode_t2str(mode));
 }
 
 /*
@@ -136,8 +136,8 @@ static void idle_time_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
 	char addr[MAX_ADDR_STR_LEN];
 
 	haltest_info("%s: bd_addr=%s hh_status=%s idle_rate=%d\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
-			bthh_status_t2str(hh_status), idle_rate);
+				bt_bdaddr_t2str(bd_addr, addr),
+				bthh_status_t2str(hh_status), idle_rate);
 }
 
 
@@ -152,8 +152,8 @@ static void get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status,
 
 	/* TODO: print actual report */
 	haltest_info("%s: bd_addr=%s hh_status=%s rpt_size=%d\n", __func__,
-			bt_bdaddr_t2str(bd_addr, addr),
-			bthh_status_t2str(hh_status), rpt_size);
+					bt_bdaddr_t2str(bd_addr, addr),
+					bthh_status_t2str(hh_status), rpt_size);
 }
 
 static bthh_callbacks_t bthh_callbacks = {
@@ -177,12 +177,12 @@ static void init_p(int argc, const char **argv)
 
 /* connect */
 
-static void connect_c(int argc, const const char **argv,
-				enum_func *penum_func, void **puser)
+static void connect_c(int argc, const const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = (void *) connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = (void *) connected_device_addr;
+		*enum_func = enum_one_string;
 	}
 }
 
@@ -243,14 +243,14 @@ static void set_info_p(int argc, const char **argv)
 /* get_protocol */
 
 static void get_protocol_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = connected_device_addr;
+		*enum_func = enum_one_string;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(bthh_protocol_mode_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bthh_protocol_mode_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -296,14 +296,14 @@ static void set_protocol_p(int argc, const char **argv)
 /* get_report */
 
 static void get_report_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = connected_device_addr;
+		*enum_func = enum_one_string;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(bthh_report_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bthh_report_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -341,14 +341,14 @@ static void get_report_p(int argc, const char **argv)
 /* set_report */
 
 static void set_report_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = connected_device_addr;
+		*enum_func = enum_one_string;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(bthh_report_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(bthh_report_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -376,12 +376,12 @@ static void set_report_p(int argc, const char **argv)
 
 /* send_data */
 
-static void send_data_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+static void send_data_c(int argc, const const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = connected_device_addr;
-		*penum_func = enum_one_string;
+		*user = connected_device_addr;
+		*enum_func = enum_one_string;
 	}
 }
 
diff --git a/android/client/if-main.h b/android/client/if-main.h
index f2d35d9..eaee914 100644
--- a/android/client/if-main.h
+++ b/android/client/if-main.h
@@ -93,11 +93,11 @@ typedef const char *(*enum_func)(void *user, int i);
 
 /*
  * This is prototype of function that when given argc, argv will
- * fill penum_func with pointer to function that will enumerate
- * parameters for argc argument, puser will be passed to penum_func.
+ * fill enum_func with pointer to function that will enumerate
+ * parameters for argc argument, user will be passed to enum_func.
  */
-typedef void (*tab_complete)(int argc, const char **argv,
-					enum_func *penum_func, void **puser);
+typedef void (*tab_complete)(int argc, const char **argv, enum_func *enum_func,
+								void **user);
 
 /*
  * For each method there is name and two functions to parse command line
@@ -145,9 +145,9 @@ struct method *get_command(const char *name);
 
 #define VERIFY_ADDR_ARG(n, adr) \
 	do { \
-		if (n < argc) \
+		if (n < argc) {\
 			str2bt_bdaddr_t(argv[n], adr); \
-		else { \
+		} else { \
 			haltest_error("No address specified\n");\
 			return;\
 		} \
diff --git a/android/client/if-pan.c b/android/client/if-pan.c
index e9cfa23..dcc7e80 100644
--- a/android/client/if-pan.c
+++ b/android/client/if-pan.c
@@ -45,12 +45,12 @@ static void control_state_cb(btpan_control_state_t state, bt_status_t error,
 					int local_role, const char *ifname)
 {
 	haltest_info("%s: state=%s error=%s local_role=%s ifname=%s\n",
-		       __func__, btpan_control_state_t2str(state),
-		       bt_status_t2str(error), btpan_role_t2str(local_role),
-		       ifname);
+			__func__, btpan_control_state_t2str(state),
+			bt_status_t2str(error), btpan_role_t2str(local_role),
+			ifname);
 }
 
-static char last_used_addr[18];
+static char last_used_addr[MAX_ADDR_STR_LEN];
 
 static void connection_state_cb(btpan_connection_state_t state,
 				bt_status_t error, const bt_bdaddr_t *bd_addr,
@@ -79,12 +79,12 @@ static void init_p(int argc, const char **argv)
 
 /* enable */
 
-static void enable_c(int argc, const const char **argv, enum_func *penum_func,
-								void **puser)
+static void enable_c(int argc, const const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = TYPE_ENUM(btpan_role_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(btpan_role_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -120,15 +120,15 @@ static void get_local_role_p(int argc, const char **argv)
 
 /* connect */
 
-static void connect_c(int argc, const const char **argv, enum_func *penum_func,
-								void **puser)
+static void connect_c(int argc, const const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = NULL;
-		*penum_func = enum_devices;
+		*user = NULL;
+		*enum_func = enum_devices;
 	} else if (argc == 4 || argc == 5) {
-		*puser = TYPE_ENUM(btpan_role_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(btpan_role_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -165,11 +165,11 @@ static void connect_p(int argc, const char **argv)
 /* disconnect */
 
 static void disconnect_c(int argc, const const char **argv,
-					enum_func *penum_func, void **puser)
+					enum_func *enum_func, void **user)
 {
 	if (argc == 3) {
-		*puser = last_used_addr;
-		*penum_func = enum_one_string;
+		*user = last_used_addr;
+		*enum_func = enum_one_string;
 	}
 }
 
diff --git a/android/client/if-sock.c b/android/client/if-sock.c
index f3125f8..dcaf048 100644
--- a/android/client/if-sock.c
+++ b/android/client/if-sock.c
@@ -52,7 +52,6 @@ static void receive_from_client(struct pollfd *pollfd)
 		haltest_error("Disconnected fd=%d\n", pollfd->fd);
 		poll_unregister_fd(pollfd->fd, receive_from_client);
 	} else if (pollfd->revents & POLLIN) {
-
 		haltest_info("receiving from client fd=%d\n", pollfd->fd);
 
 		do {
@@ -95,9 +94,10 @@ static void receive_sock_connect_signal(struct pollfd *pollfd)
 			haltest_info("Read on connect return %d\n", ret);
 			return;
 		}
+
 		haltest_info("Connection to %s channel %d status=%d\n",
 				bt_bdaddr_t2str(&cs.bd_addr, addr_str),
-							cs.channel, cs.status);
+				cs.channel, cs.status);
 
 		if (cs.status == 0)
 			poll_register_fd(pollfd->fd, POLLIN,
@@ -106,7 +106,7 @@ static void receive_sock_connect_signal(struct pollfd *pollfd)
 
 	if (pollfd->revents & POLLHUP) {
 		haltest_error("Disconnected fd=%d revents=0x%X\n", pollfd->fd,
-							pollfd->revents);
+				pollfd->revents);
 		poll_unregister_fd(pollfd->fd, receive_sock_connect_signal);
 	}
 }
@@ -165,6 +165,7 @@ static void read_accepted(int fd)
 		accepted_fd = descs[0];
 		break;
 	}
+
 	haltest_info("Incoming connection from %s channel %d status=%d fd=%d\n",
 					bt_bdaddr_t2str(&cs.bd_addr, addr_str),
 					cs.channel, cs.status, accepted_fd);
@@ -184,12 +185,12 @@ static void client_connected(struct pollfd *pollfd)
 
 /** listen */
 
-static void listen_c(int argc, const char **argv, enum_func *penum_func,
-								void **puser)
+static void listen_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*puser = TYPE_ENUM(btsock_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(btsock_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -253,14 +254,14 @@ static void listen_p(int argc, const char **argv)
 
 /** connect */
 
-static void connect_c(int argc, const char **argv,
-					enum_func *penum_func, void **puser)
+static void connect_c(int argc, const char **argv, enum_func *enum_func,
+								void **user)
 {
 	if (argc == 3) {
-		*penum_func = enum_devices;
+		*enum_func = enum_devices;
 	} else if (argc == 4) {
-		*puser = TYPE_ENUM(btsock_type_t);
-		*penum_func = enum_defines;
+		*user = TYPE_ENUM(btsock_type_t);
+		*enum_func = enum_defines;
 	}
 }
 
@@ -313,6 +314,7 @@ static void connect_p(int argc, const char **argv)
 	if (sock_fd > 0) {
 		int channel = 0;
 		int ret = read(sock_fd, &channel, 4);
+
 		if (ret != 4)
 			haltest_info("Read channel failed\n");
 		haltest_info("Channel returned from first read %d\n", channel);
diff --git a/android/client/tabcompletion.c b/android/client/tabcompletion.c
index 2b95591..69af609 100644
--- a/android/client/tabcompletion.c
+++ b/android/client/tabcompletion.c
@@ -63,8 +63,8 @@ static void print_matches(enum_func f, void *user, const char *prefix, int len)
  * buf - output buffer to keep splited arguments list
  * buf_size_in_bytes - size of buf
  */
-static int split_command(const char *line_buffer, int size,
-					split_arg_t *buf, int buf_size_in_bytes)
+static int split_command(const char *line_buffer, int size, split_arg_t *buf,
+							int buf_size_in_bytes)
 {
 	split_arg_t *prev = NULL;
 	split_arg_t *arg = buf;
@@ -218,8 +218,8 @@ static void method_completion(const struct interface *iface, split_arg_t *arg)
 static const char *bold = "\x1b[1m";
 static const char *normal = "\x1b[0m";
 
-static bool find_nth_argument(const char *str, int n,
-						const char **s, const char **e)
+static bool find_nth_argument(const char *str, int n, const char **s,
+								const char **e)
 {
 	const char *p = str;
 	int argc = 0;
diff --git a/android/client/terminal.c b/android/client/terminal.c
index a57068a..88c963b 100644
--- a/android/client/terminal.c
+++ b/android/client/terminal.c
@@ -214,6 +214,7 @@ static void terminal_line_replaced(void)
 			putchar('\b');
 			line_buf_ix--;
 		}
+
 		/* If cursor was not at the end, move it to the end */
 		if (line_buf_ix < line_len)
 			printf("%.*s", line_len - line_buf_ix,
@@ -222,6 +223,7 @@ static void terminal_line_replaced(void)
 		while (line_len >= len++)
 			putchar(' ');
 	}
+
 	/* draw new line */
 	printf("\r%s%s", prompt, line_buf);
 	/* set up indexes to new line */
@@ -321,6 +323,7 @@ static int terminal_convert_sequence(int c)
 	       }
 	       return c;
 	}
+
 	/* Inside sequence */
 	current_sequence[current_sequence_len++] = c;
 	current_sequence[current_sequence_len] = '\0';
@@ -338,6 +341,7 @@ static int terminal_convert_sequence(int c)
 		/* partial match (not whole sequence yet) */
 		return KEY_SEQUNCE_NOT_FINISHED;
 	}
+
 	terminal_print("ansii char 0x%X %c\n", c);
 	/*
 	 * Sequence does not match
@@ -530,6 +534,7 @@ void terminal_process_char(int c, void (*process_line)(char *line))
 			printf("char-0x%02x\n", c);
 			break;
 		}
+
 		if (line_buf_ix < LINE_BUF_MAX - 1) {
 			if (line_len == line_buf_ix) {
 				putchar(c);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 5/5] android: Use adapter index in mgmt functions
From: Szymon Janc @ 2013-10-24  8:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382603813-9157-1-git-send-email-szymon.janc@tieto.com>

From: Szymon Janc <szymon.janc@gmail.com>

Instead of hardcoding index 0 use real index of adapter. This fix
using invalid index if adapter ID happens to be different than 0.

This should not happen on Android but is possible while testing on
Linux PC.
---
 android/adapter.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 0305ccb..532f964 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -170,14 +170,16 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
 
 static void register_mgmt_handlers(void)
 {
-	mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, 0,
+	mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, adapter->index,
 					new_settings_callback, NULL, NULL);
 
 	mgmt_register(adapter->mgmt, MGMT_EV_CLASS_OF_DEV_CHANGED,
-			0, mgmt_dev_class_changed_event, NULL, NULL);
+				adapter->index, mgmt_dev_class_changed_event,
+				NULL, NULL);
 
 	mgmt_register(adapter->mgmt, MGMT_EV_LOCAL_NAME_CHANGED,
-			0, mgmt_local_name_changed_event, NULL, NULL);
+				adapter->index, mgmt_local_name_changed_event,
+				NULL, NULL);
 }
 
 static void load_link_keys_complete(uint8_t status, uint16_t length,
@@ -216,7 +218,7 @@ static void load_link_keys(GSList *keys)
 	cp->debug_keys = 0;
 	cp->key_count = htobs(key_len);
 
-	mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, 0, len,
+	mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, adapter->index, len,
 				cp, load_link_keys_complete, NULL, NULL);
 
 	g_free(cp);
-- 
1.8.4


^ permalink raw reply related

* [PATCH 4/5] android: Use default adapter in adapter functions
From: Szymon Janc @ 2013-10-24  8:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382603813-9157-1-git-send-email-szymon.janc@tieto.com>

From: Szymon Janc <szymon.janc@gmail.com>

There is no need to pass pointer to adapter between function as there
is only one adapter in android daemon. Also default_adapter is renamed
to adapter.

There is no need to pass adapter pointer as user data since there is
only one adapter present.
---
 android/adapter.c | 63 +++++++++++++++++++++++--------------------------------
 1 file changed, 26 insertions(+), 37 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 0a53021..0305ccb 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -50,12 +50,11 @@ struct bt_adapter {
 	uint32_t current_settings;
 };
 
-static struct bt_adapter *default_adapter;
+static struct bt_adapter *adapter;
 
 static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	const struct mgmt_cp_set_local_name *rp = param;
 
 	if (length < sizeof(*rp)) {
@@ -74,7 +73,7 @@ static void mgmt_local_name_changed_event(uint16_t index, uint16_t length,
 	/* TODO Update services if needed */
 }
 
-static void settings_changed_powered(struct bt_adapter *adapter)
+static void settings_changed_powered(void)
 {
 	struct hal_ev_adapter_state_changed ev;
 
@@ -87,17 +86,17 @@ static void settings_changed_powered(struct bt_adapter *adapter)
 			HAL_EV_ADAPTER_STATE_CHANGED, sizeof(ev), &ev, -1);
 }
 
-static void settings_changed_connectable(struct bt_adapter *adapter)
+static void settings_changed_connectable(void)
 {
 	/* TODO */
 }
 
-static void settings_changed_discoverable(struct bt_adapter *adapter)
+static void settings_changed_discoverable(void)
 {
 	/* TODO */
 }
 
-static void settings_changed(struct bt_adapter *adapter, uint32_t settings)
+static void settings_changed(uint32_t settings)
 {
 	uint32_t changed_mask;
 
@@ -108,25 +107,24 @@ static void settings_changed(struct bt_adapter *adapter, uint32_t settings)
 	DBG("0x%08x", changed_mask);
 
 	if (changed_mask & MGMT_SETTING_POWERED)
-		settings_changed_powered(adapter);
+		settings_changed_powered();
 
 	if (changed_mask & MGMT_SETTING_CONNECTABLE) {
 		DBG("Connectable");
 
-		settings_changed_connectable(adapter);
+		settings_changed_connectable();
 	}
 
 	if (changed_mask & MGMT_SETTING_DISCOVERABLE) {
 		DBG("Discoverable");
 
-		settings_changed_discoverable(adapter);
+		settings_changed_discoverable();
 	}
 }
 
 static void new_settings_callback(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	uint32_t settings;
 
 	if (length < sizeof(settings)) {
@@ -142,13 +140,12 @@ static void new_settings_callback(uint16_t index, uint16_t length,
 	if (settings == adapter->current_settings)
 		return;
 
-	settings_changed(adapter, settings);
+	settings_changed(settings);
 }
 
 static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
 					const void *param, void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	const struct mgmt_cod *rp = param;
 	uint32_t dev_class;
 
@@ -171,24 +168,21 @@ static void mgmt_dev_class_changed_event(uint16_t index, uint16_t length,
 	/* TODO: Gatt attrib set*/
 }
 
-static void register_mgmt_handlers(struct bt_adapter *adapter)
+static void register_mgmt_handlers(void)
 {
 	mgmt_register(adapter->mgmt, MGMT_EV_NEW_SETTINGS, 0,
-			new_settings_callback, adapter, NULL);
+					new_settings_callback, NULL, NULL);
 
 	mgmt_register(adapter->mgmt, MGMT_EV_CLASS_OF_DEV_CHANGED,
-			0, mgmt_dev_class_changed_event,
-			adapter, NULL);
+			0, mgmt_dev_class_changed_event, NULL, NULL);
 
 	mgmt_register(adapter->mgmt, MGMT_EV_LOCAL_NAME_CHANGED,
-			0, mgmt_local_name_changed_event,
-			adapter, NULL);
+			0, mgmt_local_name_changed_event, NULL, NULL);
 }
 
 static void load_link_keys_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	int err;
 
 	if (status) {
@@ -200,7 +194,6 @@ static void load_link_keys_complete(uint8_t status, uint16_t length,
 
 	DBG("status %u", status);
 
-	default_adapter = adapter;
 	adapter->ready(0);
 	return;
 
@@ -208,7 +201,7 @@ failed:
 	adapter->ready(err);
 }
 
-static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
+static void load_link_keys(GSList *keys)
 {
 	struct mgmt_cp_load_link_keys *cp;
 	size_t key_len = g_slist_length(keys);
@@ -224,7 +217,7 @@ static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
 	cp->key_count = htobs(key_len);
 
 	mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, 0, len,
-				cp, load_link_keys_complete, adapter, NULL);
+				cp, load_link_keys_complete, NULL, NULL);
 
 	g_free(cp);
 }
@@ -232,7 +225,6 @@ static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
 static void read_info_complete(uint8_t status, uint16_t length, const void *param,
 							void *user_data)
 {
-	struct bt_adapter *adapter = user_data;
 	const struct mgmt_rp_read_info *rp = param;
 	int err;
 
@@ -240,7 +232,7 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
 
 	if (status) {
 		error("Failed to read info for index %u: %s (0x%02x)",
-			adapter->index, mgmt_errstr(status), status);
+				adapter->index, mgmt_errstr(status), status);
 		err = -EIO;
 		goto failed;
 	}
@@ -267,9 +259,9 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
 	adapter->current_settings = btohs(rp->current_settings);
 
 	/* TODO: Register all event notification handlers */
-	register_mgmt_handlers(adapter);
+	register_mgmt_handlers();
 
-	load_link_keys(adapter, NULL);
+	load_link_keys(NULL);
 
 	return;
 
@@ -280,8 +272,6 @@ failed:
 void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 						bt_adapter_ready ready)
 {
-	struct bt_adapter *adapter;
-
 	adapter = g_new0(struct bt_adapter, 1);
 
 	adapter->mgmt = mgmt_ref(mgmt_if);
@@ -289,11 +279,11 @@ void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 	adapter->ready = ready;
 
 	if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
-				read_info_complete, adapter, NULL) > 0)
+					read_info_complete, NULL, NULL) > 0)
 		return;
 
+	mgmt_unref(adapter->mgmt);
 	ready(-EIO);
-	mgmt_unref(mgmt_if);
 }
 
 static void set_mode_complete(uint8_t status, uint16_t length,
@@ -310,8 +300,7 @@ static void set_mode_complete(uint8_t status, uint16_t length,
 	 * required in both cases. So it is safe to just call the
 	 * event handling functions here.
 	 */
-	new_settings_callback(default_adapter->index, length, param,
-							default_adapter);
+	new_settings_callback(adapter->index, length, param, NULL);
 }
 
 static bool set_mode(uint16_t opcode, uint8_t mode)
@@ -323,8 +312,8 @@ static bool set_mode(uint16_t opcode, uint8_t mode)
 
 	DBG("opcode=0x%x mode=0x%x", opcode, mode);
 
-	if (mgmt_send(default_adapter->mgmt, opcode, default_adapter->index,
-			sizeof(cp), &cp, set_mode_complete, NULL, NULL) > 0)
+	if (mgmt_send(adapter->mgmt, opcode, adapter->index, sizeof(cp), &cp,
+					set_mode_complete, NULL, NULL) > 0)
 		return true;
 
 	error("Failed to set mode");
@@ -339,7 +328,7 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 
 	switch (opcode) {
 	case HAL_OP_ENABLE:
-		if (default_adapter->current_settings & MGMT_SETTING_POWERED) {
+		if (adapter->current_settings & MGMT_SETTING_POWERED) {
 			status = HAL_ERROR_DONE;
 			break;
 		}
@@ -351,7 +340,7 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 		}
 		break;
 	case HAL_OP_DISABLE:
-		if (!(default_adapter->current_settings & MGMT_SETTING_POWERED)) {
+		if (!(adapter->current_settings & MGMT_SETTING_POWERED)) {
 			status = HAL_ERROR_DONE;
 			break;
 		}
@@ -372,7 +361,7 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 
 const bdaddr_t *bt_adapter_get_address(void)
 {
-	return &default_adapter->bdaddr;
+	return &adapter->bdaddr;
 }
 
 bool bt_adapter_register(GIOChannel *io)
-- 
1.8.4


^ permalink raw reply related

* [PATCH 3/5] android: Remove not needed adapter parameter from bt_adapter_ready
From: Szymon Janc @ 2013-10-24  8:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382603813-9157-1-git-send-email-szymon.janc@tieto.com>

From: Szymon Janc <szymon.janc@gmail.com>

There is no need to pass adapter pointer in bt_adapter_ready callback
as there is only one present.
---
 android/adapter.c | 6 +++---
 android/adapter.h | 4 +---
 android/main.c    | 2 +-
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index d85fa1f..0a53021 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -201,11 +201,11 @@ static void load_link_keys_complete(uint8_t status, uint16_t length,
 	DBG("status %u", status);
 
 	default_adapter = adapter;
-	adapter->ready(adapter, 0);
+	adapter->ready(0);
 	return;
 
 failed:
-	adapter->ready(NULL, err);
+	adapter->ready(err);
 }
 
 static void load_link_keys(struct bt_adapter *adapter, GSList *keys)
@@ -274,7 +274,7 @@ static void read_info_complete(uint8_t status, uint16_t length, const void *para
 	return;
 
 failed:
-	adapter->ready(NULL, err);
+	adapter->ready(err);
 }
 
 void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
diff --git a/android/adapter.h b/android/adapter.h
index 9ae2d33..3d7b804 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -28,9 +28,7 @@
 
 #include "lib/bluetooth.h"
 
-struct bt_adapter;
-
-typedef void (*bt_adapter_ready)(struct bt_adapter *adapter, int err);
+typedef void (*bt_adapter_ready)(int err);
 
 void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 						bt_adapter_ready func);
diff --git a/android/main.c b/android/main.c
index 740b532..50b5901 100644
--- a/android/main.c
+++ b/android/main.c
@@ -392,7 +392,7 @@ static GOptionEntry options[] = {
 	{ NULL }
 };
 
-static void adapter_ready(struct bt_adapter *adapter, int err)
+static void adapter_ready(int err)
 {
 	if (err) {
 		error("Adapter initialization failed: %s", strerror(err));
-- 
1.8.4


^ permalink raw reply related

* [PATCH 2/5] android: Fix bt_adapter_init
From: Szymon Janc @ 2013-10-24  8:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382603813-9157-1-git-send-email-szymon.janc@tieto.com>

From: Szymon Janc <szymon.janc@gmail.com>

Make bt_adapter_init return void and use ready callback for error
reporting. This also fix returning incorrect status and invalid
mgmt_if unref (mgmt_send return 0 on error or >0 on success).
---
 android/adapter.c | 11 +++++------
 android/adapter.h |  2 +-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/android/adapter.c b/android/adapter.c
index 88ac19f..d85fa1f 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -277,7 +277,7 @@ failed:
 	adapter->ready(NULL, err);
 }
 
-bool bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
+void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 						bt_adapter_ready ready)
 {
 	struct bt_adapter *adapter;
@@ -289,12 +289,11 @@ bool bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 	adapter->ready = ready;
 
 	if (mgmt_send(mgmt_if, MGMT_OP_READ_INFO, index, 0, NULL,
-				read_info_complete, adapter, NULL) > 0) {
-		mgmt_unref(mgmt_if);
-		return false;
-	}
+				read_info_complete, adapter, NULL) > 0)
+		return;
 
-	return adapter;
+	ready(-EIO);
+	mgmt_unref(mgmt_if);
 }
 
 static void set_mode_complete(uint8_t status, uint16_t length,
diff --git a/android/adapter.h b/android/adapter.h
index b8d0a58..9ae2d33 100644
--- a/android/adapter.h
+++ b/android/adapter.h
@@ -32,7 +32,7 @@ struct bt_adapter;
 
 typedef void (*bt_adapter_ready)(struct bt_adapter *adapter, int err);
 
-bool bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
+void bt_adapter_init(uint16_t index, struct mgmt *mgmt_if,
 						bt_adapter_ready func);
 
 void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
-- 
1.8.4


^ permalink raw reply related

* [PATCH 1/5] android: Start command watch after notify channel is connected
From: Szymon Janc @ 2013-10-24  8:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

From: Szymon Janc <szymon.janc@gmail.com>

Daemon should start processing commands only after both communication
channels were connected.
---
 android/main.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/android/main.c b/android/main.c
index 9879f05..740b532 100644
--- a/android/main.c
+++ b/android/main.c
@@ -288,9 +288,11 @@ static gboolean notif_connect_cb(GIOChannel *io, GIOCondition cond,
 
 	g_io_add_watch(io, cond, notif_watch_cb, NULL);
 
-	info("Successfully connected to HAL");
+	cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
 
-	/* TODO start handling commands */
+	g_io_add_watch(hal_cmd_io, cond, cmd_watch_cb, NULL);
+
+	info("Successfully connected to HAL");
 
 	return FALSE;
 }
@@ -305,10 +307,6 @@ static gboolean cmd_connect_cb(GIOChannel *io, GIOCondition cond,
 		return FALSE;
 	}
 
-	cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
-
-	g_io_add_watch(io, cond, cmd_watch_cb, NULL);
-
 	hal_notif_io = connect_hal(notif_connect_cb);
 	if (!hal_notif_io) {
 		error("Cannot connect to HAL, terminating");
-- 
1.8.4


^ permalink raw reply related

* Re: [PATCHv1 0/2] Enable av interface
From: Jerzy Kasenberg @ 2013-10-24  7:39 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth
In-Reply-To: <1382598639-6920-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

On 24 October 2013 09:10, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> For some reason get av interface was missing from hal-bluetooth and from
> hal test tool.
>
> PS: Not sure that haltest is fully implemented, Jerzy please comment here.

I must have missed if-bt in commit.
Thanks Andrei.
Apart from one line in if-bt.c all code to call av interface is there
and should be
functional.

>
> Andrei Emeltchenko (2):
>   android: haltest: Enable av interface in test tool
>   android: Enable AV interface
>
>  android/client/if-bt.c  |    2 +-
>  android/hal-bluetooth.c |    3 +++
>  2 files changed, 4 insertions(+), 1 deletion(-)
>
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Jerzy

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox