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

* [PATCH] android: Cleanup error handling
From: Andrei Emeltchenko @ 2013-10-25  8:43 UTC (permalink / raw)
  To: linux-bluetooth

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

Remove unneeded assignment err=errno and instead use errno directly.
---
 android/hal-ipc.c |   26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/android/hal-ipc.c b/android/hal-ipc.c
index 6566ebb..20421db 100644
--- a/android/hal-ipc.c
+++ b/android/hal-ipc.c
@@ -150,9 +150,8 @@ static int accept_connection(int sk)
 
 	err = poll(&pfd, 1, CONNECT_TIMEOUT);
 	if (err < 0) {
-		err = errno;
-		error("Failed to poll: %d (%s)", err, strerror(err));
-		return -1;
+		error("Failed to poll: %d (%s)", errno, strerror(errno));
+		return err;
 	}
 
 	if (err == 0) {
@@ -161,11 +160,9 @@ static int accept_connection(int sk)
 	}
 
 	new_sk = accept(sk, NULL, NULL);
-	if (new_sk < 0) {
-		err = errno;
-		error("Failed to accept socket: %d (%s)", err, strerror(err));
-		return -1;
-	}
+	if (new_sk < 0)
+		error("Failed to accept socket: %d (%s)", errno,
+							strerror(errno));
 
 	return new_sk;
 }
@@ -178,9 +175,8 @@ bool hal_ipc_init(void)
 
 	sk = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
 	if (sk < 0) {
-		err = errno;
-		error("Failed to create socket: %d (%s)", err,
-							strerror(err));
+		error("Failed to create socket: %d (%s)", errno,
+							strerror(errno));
 		return false;
 	}
 
@@ -190,16 +186,14 @@ bool hal_ipc_init(void)
 	memcpy(addr.sun_path, BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH));
 
 	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		err = errno;
-		error("Failed to bind socket: %d (%s)", err, strerror(err));
+		error("Failed to bind socket: %d (%s)", errno, strerror(errno));
 		close(sk);
 		return false;
 	}
 
 	if (listen(sk, 2) < 0) {
-		err = errno;
-		error("Failed to listen on socket: %d (%s)", err,
-								strerror(err));
+		error("Failed to listen on socket: %d (%s)", errno,
+							strerror(errno));
 		close(sk);
 		return false;
 	}
-- 
1.7.10.4


^ permalink raw reply related

* [PATCH] android/client: Fix incorrect casts of addresses
From: Jerzy Kasenberg @ 2013-10-25  8:51 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg

This fixes printing of addresses.
If char is set to be signed (as it should) some addresses were
printed with leading FFFFFF.
---
This issue did not showed up before due to unsigned char for Android build
on Qualcomm platform.

 android/client/textconv.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/android/client/textconv.c b/android/client/textconv.c
index 1188477..bcdf4d9 100644
--- a/android/client/textconv.c
+++ b/android/client/textconv.c
@@ -137,7 +137,7 @@ int int2str_findstr(const char *str, const struct int2str m[])
  */
 char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
 {
-	const char *p = (const char *) bd_addr;
+	const uint8_t *p = bd_addr->address;
 
 	snprintf(buf, MAX_ADDR_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
 					p[0], p[1], p[2], p[3], p[4], p[5]);
@@ -148,7 +148,7 @@ char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
 /* converts string to bt_bdaddr_t */
 void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr)
 {
-	char *p = (char *) bd_addr;
+	uint8_t *p = bd_addr->address;
 
 	sscanf(str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
 			       &p[0], &p[1], &p[2], &p[3], &p[4], &p[5]);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 01/15] android: Remove not needed local variable in connect_hal
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

err variable was set but never read.
---
 android/main.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/android/main.c b/android/main.c
index 50b5901..18dc9f7 100644
--- a/android/main.c
+++ b/android/main.c
@@ -239,12 +239,12 @@ static GIOChannel *connect_hal(GIOFunc connect_cb)
 	struct sockaddr_un addr;
 	GIOCondition cond;
 	GIOChannel *io;
-	int err, sk;
+	int sk;
 
 	sk = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
 	if (sk < 0) {
-		err = errno;
-		error("Failed to create socket: %d (%s)", err, strerror(err));
+		error("Failed to create socket: %d (%s)", errno,
+							strerror(errno));
 		return NULL;
 	}
 
@@ -258,9 +258,7 @@ static GIOChannel *connect_hal(GIOFunc connect_cb)
 
 	memcpy(addr.sun_path, BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH));
 
-	err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
-	if (err < 0) {
-		err = -errno;
+	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
 		error("Failed to connect HAL socket: %d (%s)", errno,
 							strerror(errno));
 		g_io_channel_unref(io);
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 02/15] android: Add properties defines to hal-msg.h
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

HAL_BT_PROP_ADP_* are specific to adapter. HAL_BT_PROP_REM_* are
specific to remote device. Rest is common.
---
 android/hal-msg.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 854e9b8..7689f38 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -91,6 +91,20 @@ struct hal_cmd_get_adapter_prop {
 	uint8_t type;
 } __attribute__((packed));
 
+#define HAL_BT_PROP_BDNAME		0x01
+#define HAL_BT_PROP_BDADDR		0x02
+#define HAL_BT_PROP_UUIDS		0x03
+#define HAL_BT_PROP_CLASS_OF_DEVICE	0x04
+#define HAL_BT_PROP_TYPE_OF_DEVICE	0x05
+#define HAL_BT_PROP_SERVICE_RECORD	0x06
+#define HAL_BT_PROP_ADP_SCAN_MODE	0x07
+#define HAL_BT_PROP_ADP_BONDED_DEVICES	0x08
+#define HAL_BT_PROP_ADP_DISC_TIMEOUT	0x09
+#define HAL_BT_PROP_REM_FRIENDLY_NAME	0x0a
+#define HAL_BT_PROP_REM_RSSI		0x0b
+#define HAL_BT_PROP_REM_VERSION_INFO	0x0c
+#define HAL_BT_PROP_REM_DEV_TIMESTAMP	0xFF
+
 #define HAL_OP_SET_ADAPTER_PROP		0x05
 struct hal_cmd_set_adapter_prop {
 	uint8_t  type;
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 03/15] android/hal: Add support for sending adapter set property command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This allows HAL to set adapter property.
---
 android/hal-bluetooth.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 6e28c91..aae6078 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -153,15 +153,30 @@ static int get_adapter_property(bt_property_type_t type)
 
 static int set_adapter_property(const bt_property_t *property)
 {
+	char buf[sizeof(struct hal_cmd_set_adapter_prop) + property->len];
+	struct hal_cmd_set_adapter_prop *cmd = (void *) buf;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	if (property == NULL)
+	switch (property->type) {
+	case BT_PROPERTY_BDNAME:
+	case BT_PROPERTY_ADAPTER_SCAN_MODE:
+	case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
+		break;
+	default:
 		return BT_STATUS_PARM_INVALID;
+	}
 
-	return BT_STATUS_UNSUPPORTED;
+	/* type match IPC type */
+	cmd->type = property->type;
+	cmd->len = property->len;
+	memcpy(cmd->val, property->val, property->len);
+
+	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP,
+					sizeof(buf), cmd, 0, NULL, NULL);
 }
 
 static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 04/15] android/hal: Add support for sending adapter get property command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This allows HAL to get adapter property.
---
 android/hal-bluetooth.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index aae6078..a71de83 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -143,12 +143,33 @@ static int get_adapter_properties(void)
 
 static int get_adapter_property(bt_property_type_t type)
 {
+	struct hal_cmd_get_adapter_prop cmd;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	return BT_STATUS_UNSUPPORTED;
+	switch (type) {
+	case BT_PROPERTY_BDNAME:
+	case BT_PROPERTY_BDADDR:
+	case BT_PROPERTY_UUIDS:
+	case BT_PROPERTY_CLASS_OF_DEVICE:
+	case BT_PROPERTY_TYPE_OF_DEVICE:
+	case BT_PROPERTY_SERVICE_RECORD:
+	case BT_PROPERTY_ADAPTER_SCAN_MODE:
+	case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
+	case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
+		break;
+	default:
+		return BT_STATUS_PARM_INVALID;
+	}
+
+	/* type match IPC type */
+	cmd.type = type;
+
+	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROP,
+					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
 static int set_adapter_property(const bt_property_t *property)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 05/15] android/hal: Add support for sending adapter get properties command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This allows HAL to get all adapter properties.
---
 android/hal-bluetooth.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index a71de83..b81f8dd 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -138,7 +138,8 @@ static int get_adapter_properties(void)
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	return BT_STATUS_UNSUPPORTED;
+	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_GET_ADAPTER_PROPS,
+						0, NULL, 0, NULL, NULL);
 }
 
 static int get_adapter_property(bt_property_type_t type)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 06/15] android/hal: Add support for sending create bond command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This allows HAL to start bonding.
---
 android/hal-bluetooth.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index b81f8dd..6f7ef45 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -275,15 +275,17 @@ static int cancel_discovery(void)
 
 static int create_bond(const bt_bdaddr_t *bd_addr)
 {
+	struct hal_cmd_create_bond cmd;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	if (!bd_addr)
-		return BT_STATUS_PARM_INVALID;
+	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
 
-	return BT_STATUS_UNSUPPORTED;
+	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CREATE_BOND,
+					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
 static int cancel_bond(const bt_bdaddr_t *bd_addr)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 07/15] android/hal: Add support for sending cancel bond command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This allows HAL to cancel pending bonding.
---
 android/hal-bluetooth.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 6f7ef45..ebaa877 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -290,12 +290,17 @@ static int create_bond(const bt_bdaddr_t *bd_addr)
 
 static int cancel_bond(const bt_bdaddr_t *bd_addr)
 {
+	struct hal_cmd_cancel_bond cmd;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	return BT_STATUS_UNSUPPORTED;
+	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+
+	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CANCEL_BOND,
+					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
 static int remove_bond(const bt_bdaddr_t *bd_addr)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 08/15] android/hal: Add support for sending adapter remove bond command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This allows HAL to remove bonding.
---
 android/hal-bluetooth.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index ebaa877..ca443a6 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -305,12 +305,17 @@ static int cancel_bond(const bt_bdaddr_t *bd_addr)
 
 static int remove_bond(const bt_bdaddr_t *bd_addr)
 {
+	struct hal_cmd_remove_bond cmd;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	return BT_STATUS_UNSUPPORTED;
+	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+
+	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_REMOVE_BOND,
+					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
 static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 09/15] android/hal: Add support for sending adapter PIN reply command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This allows HAL to reply to PIN code request.
---
 android/hal-bluetooth.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index ca443a6..6835db3 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -321,12 +321,20 @@ static int remove_bond(const bt_bdaddr_t *bd_addr)
 static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
 				uint8_t pin_len, bt_pin_code_t *pin_code)
 {
+	struct hal_cmd_pin_reply cmd;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	return BT_STATUS_UNSUPPORTED;
+	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+	cmd.accept = accept;
+	cmd.pin_len = pin_len;
+	memcpy(cmd.pin_code, pin_code, sizeof(cmd.pin_code));
+
+	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_PIN_REPLY,
+					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
 static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 10/15] android: Add missing SSP Variant definitions to IPC document
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

Those are used to specify SSP association model.
---
 android/hal-ipc-api.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index a5437c1..0c2fd25 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -281,6 +281,11 @@ Commands and responses:
 		                    Passkey (4 octets)
 		Response parameters: <none>
 
+		Valid SSP variant values: 0x00 = Passkey Confirmation
+		                          0x01 = Passkey Entry
+		                          0x02 = Consent (for Just Works)
+		                          0x03 = Passkey Notification
+
 		In case of an error, the error response will be returned.
 
 	Opcode 0x12 - DUT Mode Configure command/response
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 11/15] android: Add missing SSP variant definitions to IPC header
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

---
 android/hal-msg.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index 7689f38..f6c9e22 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -169,6 +169,11 @@ struct hal_cmd_pin_reply {
 	uint8_t pin_code[16];
 } __attribute__((packed));
 
+#define HAL_BT_SSP_VARIANT_CONFIRM	0x00
+#define HAL_BT_SSP_VARIANT_ENTRY	0x01
+#define HAL_BT_SSP_VARIANT_CONSENT	0x02
+#define HAL_BT_SSP_VARIANT_NOTIF	0x03
+
 #define HAL_OP_SSP_REPLY		0x11
 struct hal_cmd_ssp_reply {
 	uint8_t  bdaddr[6];
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 12/15] android/hal: Add support for sending adapter SSP reply command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This allows HAL to reply to SSP request.
---
 android/hal-bluetooth.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index 6835db3..eb400ee 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -340,15 +340,21 @@ static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
 static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
 					uint8_t accept, uint32_t passkey)
 {
+	struct hal_cmd_ssp_reply cmd;
+
 	DBG("");
 
 	if (!interface_ready())
 		return BT_STATUS_NOT_READY;
 
-	if (!bd_addr)
-		return BT_STATUS_PARM_INVALID;
+	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
+	/* type match IPC type */
+	cmd.ssp_variant = variant;
+	cmd.accept = accept;
+	cmd.passkey = passkey;
 
-	return BT_STATUS_UNSUPPORTED;
+	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SSP_REPLY,
+					sizeof(cmd), &cmd, 0, NULL, NULL);
 }
 
 static const void *get_profile_interface(const char *profile_id)
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 13/15] android/hal: Add support for handling adapter properties change event
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

---
 android/hal-bluetooth.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index eb400ee..9c7fbea 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -35,6 +35,37 @@ static void handle_adapter_state_changed(void *buf)
 		bt_hal_cbacks->adapter_state_changed_cb(ev->state);
 }
 
+static void handle_adapter_props_changed(void *buf, uint16_t len)
+{
+	struct hal_ev_adapter_props_changed *ev = buf;
+	bt_property_t props[ev->num_props];
+	struct hal_property *hal_prop;
+	void *p;
+	int i;
+
+	if (!bt_hal_cbacks->adapter_properties_cb)
+		return;
+
+	hal_prop = ev->props;
+	p = ev->props;
+
+	for (i = 0; i < ev->num_props; i++) {
+		if (p + sizeof(*hal_prop) + hal_prop->len > buf + len) {
+			error("invalid adapter properties event, aborting");
+			exit(EXIT_FAILURE);
+		}
+
+		props[i].type = hal_prop->type;
+		props[i].len = hal_prop->len;
+		props[i].val = hal_prop->val;
+
+		p += sizeof(*hal_prop) + hal_prop->len;
+		hal_prop = p;
+	}
+
+	bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
+}
+
 /* will be called from notification thread context */
 void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
 {
@@ -45,6 +76,9 @@ void bt_notify_adapter(uint16_t opcode, void *buf, uint16_t len)
 	case HAL_EV_ADAPTER_STATE_CHANGED:
 		handle_adapter_state_changed(buf);
 		break;
+	case HAL_EV_ADAPTER_PROPS_CHANGED:
+		handle_adapter_props_changed(buf, len);
+		break;
 	default:
 		DBG("Unhandled callback opcode=0x%x", opcode);
 		break;
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 14/15] android: Add missing success status definition to IPC header
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

This is used in HAL callbacks to indicate success.
---
 android/hal-msg.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/android/hal-msg.h b/android/hal-msg.h
index f6c9e22..089f1d6 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -49,6 +49,7 @@ struct hal_hdr {
 
 /* Core Service */
 
+#define HAL_ERROR_SUCCESS		0x00
 #define HAL_ERROR_FAILED		0x01
 #define HAL_ERROR_NOT_READY		0x02
 #define HAL_ERROR_NOMEM			0x03
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH 15/15] android: Add initial support for handling adapter get property command
From: Szymon Janc @ 2013-10-25  8:56 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1382691378-31940-1-git-send-email-szymon.janc@tieto.com>

Support for HAL_BT_PROP_BDADDR property only.
---
 android/adapter.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/android/adapter.c b/android/adapter.c
index 5837e99..e6791e7 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -322,6 +322,49 @@ static bool set_mode(uint16_t opcode, uint8_t mode)
 	return false;
 }
 
+static void send_adapter_name(void)
+{
+	struct hal_ev_adapter_props_changed *ev;
+	int len;
+
+	len = sizeof(*ev) + sizeof(struct hal_property) + sizeof(bdaddr_t);
+
+	ev = g_malloc(len);
+
+	ev->num_props = 1;
+	ev->status = HAL_ERROR_SUCCESS;
+
+	ev->props[0].type = HAL_BT_PROP_BDADDR;
+	ev->props[0].len = sizeof(bdaddr_t);
+	baswap((bdaddr_t *) ev->props[0].val, &adapter->bdaddr);
+
+	ipc_send(notification_io, HAL_SERVICE_ID_BLUETOOTH,
+				HAL_EV_ADAPTER_PROPS_CHANGED, len, ev, -1);
+
+	g_free(ev);
+}
+
+static bool get_property(void *buf, uint16_t len)
+{
+	struct hal_cmd_get_adapter_prop *cmd = buf;
+
+	switch (cmd->type) {
+	case HAL_BT_PROP_BDADDR:
+		send_adapter_name();
+		return true;
+	case HAL_BT_PROP_BDNAME:
+	case HAL_BT_PROP_UUIDS:
+	case HAL_BT_PROP_CLASS_OF_DEVICE:
+	case HAL_BT_PROP_TYPE_OF_DEVICE:
+	case HAL_BT_PROP_SERVICE_RECORD:
+	case HAL_BT_PROP_ADP_SCAN_MODE:
+	case HAL_BT_PROP_ADP_BONDED_DEVICES:
+	case HAL_BT_PROP_ADP_DISC_TIMEOUT:
+	default:
+		return false;
+	}
+}
+
 void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 								uint16_t len)
 {
@@ -352,6 +395,13 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf,
 			return;
 		}
 		break;
+	case HAL_OP_GET_ADAPTER_PROP:
+		if (get_property(buf, len)) {
+			ipc_send(io, HAL_SERVICE_ID_BLUETOOTH, opcode, 0, NULL,
+									-1);
+			return;
+		}
+		break;
 	default:
 		DBG("Unhandled command, opcode 0x%x", opcode);
 		break;
-- 
1.8.4.1


^ permalink raw reply related

* [PATCH] android/client: Fix crash in tab completion
From: Jerzy Kasenberg @ 2013-10-25  9:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jerzy Kasenberg

When user pressed tab on third or later argument when
first two did not make sense tool crashed.
Now method is checked for NULL before accessing help field.
---
 android/client/tabcompletion.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/android/client/tabcompletion.c b/android/client/tabcompletion.c
index 69af609..20d1e65 100644
--- a/android/client/tabcompletion.c
+++ b/android/client/tabcompletion.c
@@ -314,7 +314,8 @@ static void param_completion(int argc, const split_arg_t *arg,
 	const split_arg_t *tmp = arg;
 	struct command_completion_args args = {
 		.arg = arg,
-		.func = return_null
+		.func = return_null,
+		.user_help = NULL
 	};
 
 	/* prepare standard argv from arg */
@@ -326,13 +327,13 @@ static void param_completion(int argc, const split_arg_t *arg,
 	if (method != NULL && method->complete != NULL) {
 		/* ask method for completion function */
 		method->complete(argc, argv, &args.func, &args.user);
+		args.user_help = (void *) method->help;
 	}
 
 	/* If method provided enumeration function call try to complete */
 	if (args.func != NULL) {
 		args.typed = argv[argc - 1];
 		args.help = method_help;
-		args.user_help = (void *) method->help;
 
 		tab_completion(&args);
 	}
-- 
1.7.9.5


^ permalink raw reply related

* Re: [PATCH] android: Cleanup error handling
From: Luiz Augusto von Dentz @ 2013-10-25  9:26 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <1382690606-20721-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

Hi Andrei,

On Fri, Oct 25, 2013 at 11:43 AM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Remove unneeded assignment err=errno and instead use errno directly.
> ---
>  android/hal-ipc.c |   26 ++++++++++----------------
>  1 file changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/android/hal-ipc.c b/android/hal-ipc.c
> index 6566ebb..20421db 100644
> --- a/android/hal-ipc.c
> +++ b/android/hal-ipc.c
> @@ -150,9 +150,8 @@ static int accept_connection(int sk)
>
>         err = poll(&pfd, 1, CONNECT_TIMEOUT);
>         if (err < 0) {
> -               err = errno;
> -               error("Failed to poll: %d (%s)", err, strerror(err));
> -               return -1;
> +               error("Failed to poll: %d (%s)", errno, strerror(errno));
> +               return err;
>         }
>
>         if (err == 0) {
> @@ -161,11 +160,9 @@ static int accept_connection(int sk)
>         }
>
>         new_sk = accept(sk, NULL, NULL);
> -       if (new_sk < 0) {
> -               err = errno;
> -               error("Failed to accept socket: %d (%s)", err, strerror(err));
> -               return -1;
> -       }
> +       if (new_sk < 0)
> +               error("Failed to accept socket: %d (%s)", errno,
> +                                                       strerror(errno));
>
>         return new_sk;
>  }
> @@ -178,9 +175,8 @@ bool hal_ipc_init(void)
>
>         sk = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
>         if (sk < 0) {
> -               err = errno;
> -               error("Failed to create socket: %d (%s)", err,
> -                                                       strerror(err));
> +               error("Failed to create socket: %d (%s)", errno,
> +                                                       strerror(errno));
>                 return false;
>         }
>
> @@ -190,16 +186,14 @@ bool hal_ipc_init(void)
>         memcpy(addr.sun_path, BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH));
>
>         if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
> -               err = errno;
> -               error("Failed to bind socket: %d (%s)", err, strerror(err));
> +               error("Failed to bind socket: %d (%s)", errno, strerror(errno));
>                 close(sk);
>                 return false;
>         }
>
>         if (listen(sk, 2) < 0) {
> -               err = errno;
> -               error("Failed to listen on socket: %d (%s)", err,
> -                                                               strerror(err));
> +               error("Failed to listen on socket: %d (%s)", errno,
> +                                                       strerror(errno));
>                 close(sk);
>                 return false;
>         }
> --
> 1.7.10.4

Since the HAL is running multiple threads Im afraid errno can be
overwritten and at least strerror_r should be used instead or use %m
that afaik should be thread safe.


-- 
Luiz Augusto von Dentz

^ permalink raw reply

* Re: [PATCH] android/client: Fix incorrect casts of addresses
From: Andrei Emeltchenko @ 2013-10-25  9:32 UTC (permalink / raw)
  To: Jerzy Kasenberg; +Cc: linux-bluetooth
In-Reply-To: <1382691070-24358-1-git-send-email-jerzy.kasenberg@tieto.com>

Hi Jerzy,

On Fri, Oct 25, 2013 at 10:51:10AM +0200, Jerzy Kasenberg wrote:
> This fixes printing of addresses.
> If char is set to be signed (as it should) some addresses were
> printed with leading FFFFFF.
> ---
> This issue did not showed up before due to unsigned char for Android build
> on Qualcomm platform.
> 
>  android/client/textconv.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/android/client/textconv.c b/android/client/textconv.c
> index 1188477..bcdf4d9 100644
> --- a/android/client/textconv.c
> +++ b/android/client/textconv.c
> @@ -137,7 +137,7 @@ int int2str_findstr(const char *str, const struct int2str m[])
>   */
>  char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
>  {
> -	const char *p = (const char *) bd_addr;
> +	const uint8_t *p = bd_addr->address;
>  
>  	snprintf(buf, MAX_ADDR_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
>  					p[0], p[1], p[2], p[3], p[4], p[5]);

is this correct order btw?

Best regards 
Andrei Emeltchenko 

> @@ -148,7 +148,7 @@ char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
>  /* converts string to bt_bdaddr_t */
>  void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr)
>  {
> -	char *p = (char *) bd_addr;
> +	uint8_t *p = bd_addr->address;
>  
>  	sscanf(str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
>  			       &p[0], &p[1], &p[2], &p[3], &p[4], &p[5]);
> -- 
> 1.7.9.5
> 
> --
> 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

^ permalink raw reply

* Re: [PATCH 06/15] android/hal: Add support for sending create bond command
From: Andrei Emeltchenko @ 2013-10-25  9:36 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1382691378-31940-6-git-send-email-szymon.janc@tieto.com>

Hi Szymon,

On Fri, Oct 25, 2013 at 10:56:09AM +0200, Szymon Janc wrote:
> This allows HAL to start bonding.
> ---
>  android/hal-bluetooth.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
> index b81f8dd..6f7ef45 100644
> --- a/android/hal-bluetooth.c
> +++ b/android/hal-bluetooth.c
> @@ -275,15 +275,17 @@ static int cancel_discovery(void)
>  
>  static int create_bond(const bt_bdaddr_t *bd_addr)
>  {
> +	struct hal_cmd_create_bond cmd;
> +
>  	DBG("");
>  
>  	if (!interface_ready())
>  		return BT_STATUS_NOT_READY;
>  
> -	if (!bd_addr)
> -		return BT_STATUS_PARM_INVALID;

I think we can leave check here

Best regards 
Andrei Emeltchenko 

> +	memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
>  
> -	return BT_STATUS_UNSUPPORTED;
> +	return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_CREATE_BOND,
> +					sizeof(cmd), &cmd, 0, NULL, NULL);
>  }
>  
>  static int cancel_bond(const bt_bdaddr_t *bd_addr)
> -- 
> 1.8.4.1
> 
> --
> 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

^ permalink raw reply

* Re: [PATCH] android/client: Fix incorrect casts of addresses
From: Jerzy Kasenberg @ 2013-10-25  9:50 UTC (permalink / raw)
  To: Andrei Emeltchenko, Jerzy Kasenberg, linux-bluetooth
In-Reply-To: <20131025093227.GB6113@aemeltch-MOBL1>

Hi Andrei,

On 25 October 2013 11:32, Andrei Emeltchenko
<andrei.emeltchenko.news@gmail.com> wrote:
> Hi Jerzy,
>
> On Fri, Oct 25, 2013 at 10:51:10AM +0200, Jerzy Kasenberg wrote:
>> This fixes printing of addresses.
>> If char is set to be signed (as it should) some addresses were
>> printed with leading FFFFFF.
>> ---
>> This issue did not showed up before due to unsigned char for Android build
>> on Qualcomm platform.
>>
>>  android/client/textconv.c |    4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/android/client/textconv.c b/android/client/textconv.c
>> index 1188477..bcdf4d9 100644
>> --- a/android/client/textconv.c
>> +++ b/android/client/textconv.c
>> @@ -137,7 +137,7 @@ int int2str_findstr(const char *str, const struct int2str m[])
>>   */
>>  char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
>>  {
>> -     const char *p = (const char *) bd_addr;
>> +     const uint8_t *p = bd_addr->address;
>>
>>       snprintf(buf, MAX_ADDR_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
>>                                       p[0], p[1], p[2], p[3], p[4], p[5]);
>
> is this correct order btw?

Tool print same address for my mouse as I see printed on the mouse so
I guess it's correct.

>
> Best regards
> Andrei Emeltchenko
>
>> @@ -148,7 +148,7 @@ char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
>>  /* converts string to bt_bdaddr_t */
>>  void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr)
>>  {
>> -     char *p = (char *) bd_addr;
>> +     uint8_t *p = bd_addr->address;
>>
>>       sscanf(str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
>>                              &p[0], &p[1], &p[2], &p[3], &p[4], &p[5]);
>> --
>> 1.7.9.5
>>
>> --
>> 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

-- 
Best regards
Jerzy

^ permalink raw reply

* Re: [PATCH] android/client: Fix incorrect casts of addresses
From: Andrei Emeltchenko @ 2013-10-25 10:08 UTC (permalink / raw)
  To: Jerzy Kasenberg; +Cc: linux-bluetooth
In-Reply-To: <CAHCYCozKG2K+QOvX_2eYSD96DGikc-v9dK1VNtX81tLdFzXvXg@mail.gmail.com>

Hi Jerzy,

On Fri, Oct 25, 2013 at 11:50:22AM +0200, Jerzy Kasenberg wrote:
> Hi Andrei,
> 
> On 25 October 2013 11:32, Andrei Emeltchenko
> <andrei.emeltchenko.news@gmail.com> wrote:
> > Hi Jerzy,
> >
> > On Fri, Oct 25, 2013 at 10:51:10AM +0200, Jerzy Kasenberg wrote:
> >> This fixes printing of addresses.
> >> If char is set to be signed (as it should) some addresses were
> >> printed with leading FFFFFF.
> >> ---
> >> This issue did not showed up before due to unsigned char for Android build
> >> on Qualcomm platform.
> >>
> >>  android/client/textconv.c |    4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/android/client/textconv.c b/android/client/textconv.c
> >> index 1188477..bcdf4d9 100644
> >> --- a/android/client/textconv.c
> >> +++ b/android/client/textconv.c
> >> @@ -137,7 +137,7 @@ int int2str_findstr(const char *str, const struct int2str m[])
> >>   */
> >>  char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
> >>  {
> >> -     const char *p = (const char *) bd_addr;
> >> +     const uint8_t *p = bd_addr->address;
> >>
> >>       snprintf(buf, MAX_ADDR_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
> >>                                       p[0], p[1], p[2], p[3], p[4], p[5]);
> >
> > is this correct order btw?
> 
> Tool print same address for my mouse as I see printed on the mouse so
> I guess it's correct.

OK, those are addresses sent through HAL, they are in different format.

Best regards 
Andrei Emeltchenko 

> 
> >
> > Best regards
> > Andrei Emeltchenko
> >
> >> @@ -148,7 +148,7 @@ char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf)
> >>  /* converts string to bt_bdaddr_t */
> >>  void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr)
> >>  {
> >> -     char *p = (char *) bd_addr;
> >> +     uint8_t *p = bd_addr->address;
> >>
> >>       sscanf(str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
> >>                              &p[0], &p[1], &p[2], &p[3], &p[4], &p[5]);
> >> --
> >> 1.7.9.5
> >>
> >> --
> >> 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
> 
> -- 
> Best regards
> Jerzy

^ permalink raw reply

* Re: [PATCH] android: Cleanup error handling
From: Andrei Emeltchenko @ 2013-10-25 10:09 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CABBYNZK4B5_3wP3Og=XWgohDV0UmdqZnBro-1Onv5gtJViNgKw@mail.gmail.com>

Hi Luiz,

On Fri, Oct 25, 2013 at 12:26:12PM +0300, Luiz Augusto von Dentz wrote:
> Hi Andrei,
> 
> On Fri, Oct 25, 2013 at 11:43 AM, Andrei Emeltchenko
> <Andrei.Emeltchenko.news@gmail.com> wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > Remove unneeded assignment err=errno and instead use errno directly.
> > ---
> >  android/hal-ipc.c |   26 ++++++++++----------------
> >  1 file changed, 10 insertions(+), 16 deletions(-)
> >
> > diff --git a/android/hal-ipc.c b/android/hal-ipc.c
> > index 6566ebb..20421db 100644
> > --- a/android/hal-ipc.c
> > +++ b/android/hal-ipc.c
> > @@ -150,9 +150,8 @@ static int accept_connection(int sk)
> >
> >         err = poll(&pfd, 1, CONNECT_TIMEOUT);
> >         if (err < 0) {
> > -               err = errno;
> > -               error("Failed to poll: %d (%s)", err, strerror(err));
> > -               return -1;
> > +               error("Failed to poll: %d (%s)", errno, strerror(errno));
> > +               return err;
> >         }
> >
> >         if (err == 0) {
> > @@ -161,11 +160,9 @@ static int accept_connection(int sk)
> >         }
> >
> >         new_sk = accept(sk, NULL, NULL);
> > -       if (new_sk < 0) {
> > -               err = errno;
> > -               error("Failed to accept socket: %d (%s)", err, strerror(err));
> > -               return -1;
> > -       }
> > +       if (new_sk < 0)
> > +               error("Failed to accept socket: %d (%s)", errno,
> > +                                                       strerror(errno));
> >
> >         return new_sk;
> >  }
> > @@ -178,9 +175,8 @@ bool hal_ipc_init(void)
> >
> >         sk = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
> >         if (sk < 0) {
> > -               err = errno;
> > -               error("Failed to create socket: %d (%s)", err,
> > -                                                       strerror(err));
> > +               error("Failed to create socket: %d (%s)", errno,
> > +                                                       strerror(errno));
> >                 return false;
> >         }
> >
> > @@ -190,16 +186,14 @@ bool hal_ipc_init(void)
> >         memcpy(addr.sun_path, BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH));
> >
> >         if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
> > -               err = errno;
> > -               error("Failed to bind socket: %d (%s)", err, strerror(err));
> > +               error("Failed to bind socket: %d (%s)", errno, strerror(errno));
> >                 close(sk);
> >                 return false;
> >         }
> >
> >         if (listen(sk, 2) < 0) {
> > -               err = errno;
> > -               error("Failed to listen on socket: %d (%s)", err,
> > -                                                               strerror(err));
> > +               error("Failed to listen on socket: %d (%s)", errno,
> > +                                                       strerror(errno));
> >                 close(sk);
> >                 return false;
> >         }
> > --
> > 1.7.10.4
> 
> Since the HAL is running multiple threads Im afraid errno can be
> overwritten and at least strerror_r should be used instead or use %m
> that afaik should be thread safe.

I will check does bionic supports %m %d and send the path

Best regards 
Andrei Emeltchenko 

^ 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