-
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?
Conversation
This support will also need to be added to chan_simpleusb. We are attempting to keep the same features in both drivers. Common routines, like get_usb_serial, will need to be in res_usbradio. We will run through a code review soon. |
Thanks for the feedback. I'll see about moving the get_usb_serial to the resource. I haven't looked at simple_usb code at all, so probably need a little direction on that. |
You will find the routines that you changed are almost the same in simple_usb |
Thanks, a quick look seemed to say that. I'll work on implementing and testing in simple_usb a little later. |
Have to put this down for a bit. SimpleUSB works except for one bug. It's suppose to collect the serial number when an auto-assign happens. With adding some debug I see it enter my if statement just fine, but |
* \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 comment
The 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.
|
||
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 comment
The 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()
@@ -347,6 +348,7 @@ static struct chan_simpleusb_pvt simpleusb_default = { | |||
.rxondelay = 0, | |||
.txoffdelay = 0, | |||
.pager = PAGER_NONE, | |||
.serial = "", |
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)?
/* 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 comment
The 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() ?
/* Go through the list of usb devices, and get the serial numbers */ | ||
if (ast_radio_get_usb_serial(index_devstr, serial) == 0) continue; | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Pull the brace ('{') up to this line.
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 comment
The 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 :
if (ast_radio_get_usb_serial(index_devstr, serial) == 0) {
continue;
}
@@ -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 comment
The 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.
Thanks @Allan-N for the review. C isn't my primary language, so I appreciate the hand holding. |
FYI : Asterisk Coding Guidelines |
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.
One other (set of) changes to consider. The tune menus allow you to switch the device associated with a node (handy/needed if you have multiple dongles connected). This is handled in chan_simpleusb.c by the usb_device_swap() function. Seems like that function also needs to be aware of the serial #.
When using a URIx with an eeprom, the eeprom supports setting a serial number for the device. The serial number is exposed as in the device descriptor as iSerialNumber.
This PR allows the use of a serial number to identify which device to load in chan_usbradio.
On channel hidthread startup, the PR will loop through the AST radio device strings looking for a matching configured serial number. If a match is found, the devstr is updated to match the one found in the search loop.
Should a usb device match not be found, chan_usbradio continues as normal by using the configured devstr, and finally searching for any available device.
At this time, I only have very terrible python code to modify device serial numbers, and it is not clean enough to include in this PR.
I've been using a version of this for the old apt_rpt for a while, and it's worked great. This is an attempt to port to the new V3 version.