bluez: Load BT board data based on country code
BT board data file PS_ASIC-<country-code>.pst is loaded based
on country code. If not exist, default BT board data file
PS_ASIC.pst would be loaded. This patch is released from QCA.
BUG=b:35587372
TEST=Verified right board data loaded with country code us, ca and gb.
Change-Id: I09efb50a85e6014ebdd12ae5608d8725f1f20fd2
Reviewed-on: https://chromium-review.googlesource.com/450398
Commit-Ready: Yixiang Li <yixiang@google.com>
Tested-by: Yixiang Li <yixiang@google.com>
Reviewed-by: Kan Yan <kyan@google.com>
diff --git a/tools/hciattach_ath3k.c b/tools/hciattach_ath3k.c
index a76b448..cafa840 100644
--- a/tools/hciattach_ath3k.c
+++ b/tools/hciattach_ath3k.c
@@ -575,17 +575,51 @@
#define PS_ASIC_FILE "PS_ASIC.pst"
#define PS_FPGA_FILE "PS_FPGA.pst"
+#define PS_ASIC_FILE_PREFIX "PS_ASIC-"
+#define PS_FPGA_FILE_PREFIX "PS_FPGA-"
+
static void get_ps_file_name(uint32_t devtype, uint32_t rom_version,
char *path)
{
char *filename;
+ char *filenameprefix;
+ char *postfix = NULL;
+ char buf[20];
+ FILE *stream;
- if (devtype == 0xdeadc0de)
- filename = PS_ASIC_FILE;
- else
+ if (devtype == 0xdeadc0de) {
+ filename = PS_ASIC_FILE;
+ filenameprefix = PS_ASIC_FILE_PREFIX;
+ }
+ else {
filename = PS_FPGA_FILE;
+ filenameprefix = PS_FPGA_FILE_PREFIX;
+ }
- snprintf(path, MAXPATHLEN, "%s%x/%s", FW_PATH, rom_version, filename);
+ stream = fopen("/sys/firmware/vpd/ro/region", "r");
+ if (!stream)
+ perror("VPD region file not exist, use default PS file\n");
+ else {
+ postfix = fgets(buf, 20, stream);
+ if (!postfix)
+ perror("VPD region file read error\n");
+
+ fclose(stream);
+ }
+
+ if (!postfix)
+ snprintf(path, MAXPATHLEN, "%s%x/%s", FW_PATH, rom_version, filename);
+ else {
+ snprintf(path, MAXPATHLEN, "%s%x/%s%s%s", FW_PATH, rom_version,
+ filenameprefix, postfix, ".pst");
+ stream = fopen(path, "r");
+ if (!stream) {
+ perror("PS file with region code not exist, use default PS file\n");
+ snprintf(path, MAXPATHLEN, "%s%x/%s", FW_PATH, rom_version, filename);
+ }
+ else
+ fclose(stream);
+ }
}
#define PATCH_FILE "RamPatch.txt"