diff options
Diffstat (limited to 'src/client.c')
| -rw-r--r-- | src/client.c | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/src/client.c b/src/client.c index e77e07e..aa276cd 100644 --- a/src/client.c +++ b/src/client.c | |||
| @@ -248,24 +248,61 @@ int client_notify_connect(struct mux_client *client, enum usbmuxd_result result) | |||
| 248 | return 0; | 248 | return 0; |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | #ifdef HAVE_PLIST | ||
| 252 | static plist_t create_device_attached_plist(struct device_info *dev) | ||
| 253 | { | ||
| 254 | plist_t dict = plist_new_dict(); | ||
| 255 | plist_dict_insert_item(dict, "MessageType", plist_new_string("Attached")); | ||
| 256 | plist_dict_insert_item(dict, "DeviceID", plist_new_uint(dev->id)); | ||
| 257 | plist_t props = plist_new_dict(); | ||
| 258 | // TODO: get current usb speed | ||
| 259 | plist_dict_insert_item(props, "ConnectionSpeed", plist_new_uint(480000000)); | ||
| 260 | plist_dict_insert_item(props, "ConnectionType", plist_new_string("USB")); | ||
| 261 | plist_dict_insert_item(props, "DeviceID", plist_new_uint(dev->id)); | ||
| 262 | plist_dict_insert_item(props, "LocationID", plist_new_uint(dev->location)); | ||
| 263 | plist_dict_insert_item(props, "ProductID", plist_new_uint(dev->pid)); | ||
| 264 | plist_dict_insert_item(props, "SerialNumber", plist_new_string(dev->serial)); | ||
| 265 | plist_dict_insert_item(dict, "Properties", props); | ||
| 266 | return dict; | ||
| 267 | } | ||
| 268 | |||
| 269 | static int send_device_list(struct mux_client *client, uint32_t tag) | ||
| 270 | { | ||
| 271 | int res = -1; | ||
| 272 | plist_t dict = plist_new_dict(); | ||
| 273 | plist_t devices = plist_new_array(); | ||
| 274 | |||
| 275 | int count = device_get_count(0); | ||
| 276 | if (count > 0) { | ||
| 277 | struct device_info *devs; | ||
| 278 | struct device_info *dev; | ||
| 279 | int i; | ||
| 280 | |||
| 281 | devs = malloc(sizeof(struct device_info) * count); | ||
| 282 | count = device_get_list(0, devs); | ||
| 283 | dev = devs; | ||
| 284 | for (i = 0; i < count; i++) { | ||
| 285 | plist_t device = create_device_attached_plist(dev++); | ||
| 286 | if (device) { | ||
| 287 | plist_array_append_item(devices, device); | ||
| 288 | } | ||
| 289 | } | ||
| 290 | free(devs); | ||
| 291 | } | ||
| 292 | plist_dict_insert_item(dict, "DeviceList", devices); | ||
| 293 | res = send_plist_pkt(client, tag, dict); | ||
| 294 | plist_free(dict); | ||
| 295 | return res; | ||
| 296 | } | ||
| 297 | #endif | ||
| 298 | |||
| 251 | static int notify_device_add(struct mux_client *client, struct device_info *dev) | 299 | static int notify_device_add(struct mux_client *client, struct device_info *dev) |
| 252 | { | 300 | { |
| 253 | int res = -1; | 301 | int res = -1; |
| 254 | #ifdef HAVE_PLIST | 302 | #ifdef HAVE_PLIST |
| 255 | if (client->proto_version == 1) { | 303 | if (client->proto_version == 1) { |
| 256 | /* XML plist packet */ | 304 | /* XML plist packet */ |
| 257 | plist_t dict = plist_new_dict(); | 305 | plist_t dict = create_device_attached_plist(dev); |
| 258 | plist_dict_insert_item(dict, "MessageType", plist_new_string("Attached")); | ||
| 259 | plist_dict_insert_item(dict, "DeviceID", plist_new_uint(dev->id)); | ||
| 260 | plist_t props = plist_new_dict(); | ||
| 261 | // TODO: get current usb speed | ||
| 262 | plist_dict_insert_item(props, "ConnectionSpeed", plist_new_uint(480000000)); | ||
| 263 | plist_dict_insert_item(props, "ConnectionType", plist_new_string("USB")); | ||
| 264 | plist_dict_insert_item(props, "DeviceID", plist_new_uint(dev->id)); | ||
| 265 | plist_dict_insert_item(props, "LocationID", plist_new_uint(dev->location)); | ||
| 266 | plist_dict_insert_item(props, "ProductID", plist_new_uint(dev->pid)); | ||
| 267 | plist_dict_insert_item(props, "SerialNumber", plist_new_string(dev->serial)); | ||
| 268 | plist_dict_insert_item(dict, "Properties", props); | ||
| 269 | res = send_plist_pkt(client, 0, dict); | 306 | res = send_plist_pkt(client, 0, dict); |
| 270 | plist_free(dict); | 307 | plist_free(dict); |
| 271 | } else | 308 | } else |
| @@ -423,6 +460,12 @@ static int client_command(struct mux_client *client, struct usbmuxd_header *hdr) | |||
| 423 | client->state = CLIENT_CONNECTING1; | 460 | client->state = CLIENT_CONNECTING1; |
| 424 | } | 461 | } |
| 425 | return 0; | 462 | return 0; |
| 463 | #ifdef HAVE_PLIST | ||
| 464 | } else if (!strcmp(message, "ListDevices")) { | ||
| 465 | if (send_device_list(client, hdr->tag) < 0) | ||
| 466 | return -1; | ||
| 467 | return 0; | ||
| 468 | #endif | ||
| 426 | } else { | 469 | } else { |
| 427 | usbmuxd_log(LL_ERROR, "Unexpected command '%s' received!", message); | 470 | usbmuxd_log(LL_ERROR, "Unexpected command '%s' received!", message); |
| 428 | free(message); | 471 | free(message); |
