• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #include "cras_device_blacklist.h"
7 #include "iniparser_wrapper.h"
8 #include "utlist.h"
9 
10 /* Allocate 63 chars + 1 for null where declared. */
11 static const unsigned int MAX_INI_NAME_LEN = 63;
12 static const unsigned int MAX_KEY_LEN = 63;
13 
14 struct cras_device_blacklist {
15 	dictionary *ini;
16 };
17 
18 /*
19  * Exported Interface
20  */
21 
22 struct cras_device_blacklist *
cras_device_blacklist_create(const char * config_path)23 cras_device_blacklist_create(const char *config_path)
24 {
25 	struct cras_device_blacklist *blacklist;
26 	char ini_name[MAX_INI_NAME_LEN + 1];
27 
28 	blacklist = calloc(1, sizeof(*blacklist));
29 	if (!blacklist)
30 		return NULL;
31 
32 	snprintf(ini_name, MAX_INI_NAME_LEN, "%s/%s", config_path,
33 		 "device_blacklist");
34 	ini_name[MAX_INI_NAME_LEN] = '\0';
35 	blacklist->ini = iniparser_load_wrapper(ini_name);
36 
37 	return blacklist;
38 }
39 
cras_device_blacklist_destroy(struct cras_device_blacklist * blacklist)40 void cras_device_blacklist_destroy(struct cras_device_blacklist *blacklist)
41 {
42 	if (blacklist && blacklist->ini)
43 		iniparser_freedict(blacklist->ini);
44 	free(blacklist);
45 }
46 
cras_device_blacklist_check(struct cras_device_blacklist * blacklist,unsigned vendor_id,unsigned product_id,unsigned desc_checksum,unsigned device_index)47 int cras_device_blacklist_check(struct cras_device_blacklist *blacklist,
48 				unsigned vendor_id, unsigned product_id,
49 				unsigned desc_checksum, unsigned device_index)
50 {
51 	char ini_key[MAX_KEY_LEN + 1];
52 
53 	if (!blacklist)
54 		return 0;
55 
56 	snprintf(ini_key, MAX_KEY_LEN, "USB_Outputs:%04x_%04x_%08x_%u",
57 		 vendor_id, product_id, desc_checksum, device_index);
58 	ini_key[MAX_KEY_LEN] = 0;
59 	return iniparser_getboolean(blacklist->ini, ini_key, 0);
60 }
61