-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support URIx eeprom Serial Numbers #394
base: master
Are you sure you want to change the base?
Changes from all commits
650ae56
741f765
e0bb879
5b223a7
d59c9e1
dbc810d
5d2ebbe
9e6c45d
bc3f8e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,7 @@ struct chan_simpleusb_pvt { | |
int boost; /* input boost, scaled by BOOST_SCALE */ | ||
char devicenum; | ||
char devstr[128]; | ||
char serial[14]; | ||
int spkrmax; | ||
int micmax; | ||
int micplaymax; | ||
|
@@ -347,6 +348,7 @@ static struct chan_simpleusb_pvt simpleusb_default = { | |
.rxondelay = 0, | ||
.txoffdelay = 0, | ||
.pager = PAGER_NONE, | ||
.serial = "", | ||
.clipledgpio = 0, | ||
.rxaudiostats.index = 0 | ||
}; | ||
|
@@ -860,7 +862,7 @@ static int load_tune_config(struct chan_simpleusb_pvt *o, const struct ast_confi | |
static void *hidthread(void *arg) | ||
{ | ||
unsigned char buf[4], bufsave[4], keyed, ctcssed, txreq; | ||
char *s, lasttxtmp; | ||
char *s, lasttxtmp, serial[14]; | ||
register int i, j, k; | ||
int res; | ||
struct usb_device *usb_dev; | ||
|
@@ -906,6 +908,35 @@ static void *hidthread(void *arg) | |
* found device. | ||
*/ | ||
ast_radio_time(&o->lasthidtime); | ||
/* If configuration has a serial number defined, find the device */ | ||
if (strlen(o->serial) > 0) | ||
{ | ||
ast_log(LOG_NOTICE, "Checking for USB device with serial %s\n", o->serial); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ast_log() ... and the others below ... really feel like debug messages. Maybe switch them to ast_debug() ? |
||
int index = 0; | ||
char *index_devstr = NULL; | ||
for(;;) | ||
{ | ||
index_devstr = ast_radio_usb_get_devstr(index); | ||
if (ast_strlen_zero(index_devstr)) { | ||
/* No more devices, so break out of the loop */ | ||
ast_log(LOG_NOTICE, "USB Device with serial %s not found.\n", o->serial); | ||
break; | ||
} | ||
/* Go through the list of usb devices, and get the serial numbers */ | ||
if (ast_radio_get_usb_serial(index_devstr, serial) == 0) continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The app_rpt project follows the asterisk coding standards where single/standalone statements are not allowed. This should be :
|
||
ast_log(LOG_NOTICE, "Device Serial %s vs %s\n", o->serial, serial); | ||
if (strcmp(o->serial, serial) == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pull the brace ('{') up to this line. |
||
{ | ||
/* We found a device with the matching serial number | ||
* Set the devstr to the matching device | ||
*/ | ||
ast_log(LOG_NOTICE, "Found device serial %s at %s for %s\n",o->serial, index_devstr, o->name); | ||
ast_copy_string(o->devstr, index_devstr, sizeof(o->devstr)); | ||
break; | ||
} | ||
index++; | ||
} | ||
} | ||
|
||
/* Automatically assign a devstr if one was not specified in the configuration. */ | ||
if (ast_strlen_zero(o->devstr)) { | ||
|
@@ -936,6 +967,11 @@ static void *hidthread(void *arg) | |
/* We found an unused device assign it to our node */ | ||
ast_copy_string(o->devstr, index_devstr, sizeof(o->devstr)); | ||
ast_log(LOG_NOTICE, "Channel %s: Automatically assigned USB device %s to SimpleUSB channel\n", o->name, o->devstr); | ||
/* Check if the device has a serial number, and add it to the config file */ | ||
if (ast_radio_get_usb_serial(o->devstr, serial) > 0) { | ||
ast_copy_string(o->serial, serial, sizeof(o->serial)); | ||
ast_log(LOG_NOTICE, "Channel %s: Automatically assigned USB device has serial %s\n", o->name, o->serial); | ||
} | ||
break; | ||
} | ||
if (ast_strlen_zero(o->devstr)) { | ||
|
@@ -3087,6 +3123,7 @@ static void _menu_print(int fd, struct chan_simpleusb_pvt *o) | |
ast_cli(fd, "Active radio interface is [%s]\n", simpleusb_active); | ||
ast_mutex_lock(&usb_dev_lock); | ||
ast_cli(fd, "Device String is %s\n", o->devstr); | ||
ast_cli(fd, "Device Serial is %s\n", o->serial); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed thoughts about reporting the device serial if there is no serial number present. |
||
ast_mutex_unlock(&usb_dev_lock); | ||
ast_cli(fd, "Card is %i\n", ast_radio_usb_get_usbdev(o->devstr)); | ||
ast_cli(fd, "Rx Level currently set to %d\n", o->rxmixerset); | ||
|
@@ -3245,6 +3282,7 @@ static void tune_write(struct chan_simpleusb_pvt *o) | |
ast_log(LOG_ERROR, "No category '%s' exists?\n", o->name); | ||
} else { | ||
CONFIG_UPDATE_STR(devstr); | ||
CONFIG_UPDATE_STR(serial); | ||
CONFIG_UPDATE_INT(rxmixerset); | ||
CONFIG_UPDATE_INT(txmixaset); | ||
CONFIG_UPDATE_INT(txmixbset); | ||
|
@@ -3698,6 +3736,7 @@ static struct chan_simpleusb_pvt *store_config(const struct ast_config *cfg, con | |
CV_BOOL("rxboost", o->rxboost); | ||
CV_UINT("hdwtype", o->hdwtype); | ||
CV_UINT("eeprom", o->wanteeprom); | ||
CV_STR("serial", o->serial); | ||
CV_UINT("rxondelay", o->rxondelay); | ||
CV_UINT("txoffdelay", o->txoffdelay); | ||
CV_F("pager", store_pager(o, (char *) v->value)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ | |
|
||
;;;;; Tune settings ;;;;; | ||
;devstr= | ||
;serial= | ||
;rxmixerset=500 | ||
;txmixaset=500 | ||
;txmixbset=500 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,7 @@ | |
|
||
;;;;; Tune settings ;;;;; | ||
;devstr= | ||
;serial= | ||
;rxmixerset=500 | ||
;txmixaset=500 | ||
;txmixbset=500 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -719,6 +719,33 @@ void ast_radio_time(time_t *second) | |
*second = ts.tv_sec; | ||
} | ||
|
||
/*! | ||
* \brief Get serial number from device if available | ||
* This function will attempt to get the serial number from a media device | ||
* | ||
* \param devstr The USB device string | ||
* \param serial Buffer to return the serial number | ||
* | ||
* \retval Length of found serial number | ||
*/ | ||
|
||
int ast_radio_get_usb_serial(char *devstr, char *serial) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function really needs to have the size of the "char *serial" buffer passed in as an argument. |
||
{ | ||
struct usb_device *usb_dev; | ||
struct usb_dev_handle *usb_handle; | ||
int length; | ||
|
||
usb_dev = ast_radio_hid_device_init(devstr); | ||
usb_handle = usb_open(usb_dev); | ||
length = usb_get_string_simple(usb_handle, usb_dev->descriptor.iSerialNumber, serial, sizeof(serial)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sizeof(serial) is NOT what you want here. You want the caller to pass in the size of the provided buffer and pass that along to usb_get_string_simple() |
||
usb_close(usb_handle); | ||
usb_handle = NULL; | ||
usb_dev = NULL; | ||
|
||
return length; | ||
} | ||
|
||
|
||
struct timeval ast_radio_tvnow(void) | ||
{ | ||
struct timeval tv; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this since the variable is "char serial[14]". Also, with the default struct being zero'd out then is this needed (kinda the same way that .devstr is not being initialized)?