Skip to content

Commit ef54dc2

Browse files
fixes
1 parent b1f6480 commit ef54dc2

8 files changed

Lines changed: 65 additions & 37 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ udev/39-usbmuxd.rules
4545
config.h.in~
4646
Build/
4747
configure~
48+
xcuserdata
49+
project.xcworkspace
50+
xcshareddata

autogen.sh

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
#!/bin/sh
22

3-
#cleanup cache for correct versioning when run multiple times
4-
rm -rf autom4te.cache
3+
olddir=`pwd`
4+
srcdir=`dirname $0`
5+
test -z "$srcdir" && srcdir=.
56

6-
gprefix=`which glibtoolize 2>&1 >/dev/null`
7-
if [ $? -eq 0 ]; then
8-
glibtoolize --force
9-
else
10-
libtoolize --force
11-
fi
12-
aclocal -I m4
13-
autoheader
14-
automake --add-missing
15-
autoconf
16-
requires_pkgconfig=`which pkg-config 2>&1 >/dev/null`
17-
if [ $? -ne 0 ]; then
18-
echo "Missing required pkg-config. Please install it on your system and run again."
19-
fi
7+
(
8+
cd "$srcdir"
9+
10+
#cleanup cache for correct versioning when run multiple times
11+
rm -rf autom4te.cache
12+
13+
gprefix=`which glibtoolize 2>&1 >/dev/null`
14+
if [ $? -eq 0 ]; then
15+
glibtoolize --force
16+
else
17+
libtoolize --force
18+
fi
19+
aclocal -I m4
20+
autoheader
21+
automake --add-missing
22+
autoconf
23+
24+
cd "$olddir"
25+
)
2026

2127
if [ -z "$NOCONFIGURE" ]; then
22-
./configure "$@"
23-
fi
28+
$srcdir/configure "$@"
29+
fi

usbmuxd2/Devices/USBDevice.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <mutex>
1515

16+
#include <string.h>
17+
1618
#pragma mark libusb_callback implementations
1719
void tx_callback(struct libusb_transfer *xfer) noexcept{
1820
std::shared_ptr<USBDevice> dev = *(std::shared_ptr<USBDevice> *)xfer->user_data;
@@ -391,18 +393,19 @@ void USBDevice::device_data_input(unsigned char *buffer, uint32_t length){
391393
_data_in_event.notifyAll();
392394
});
393395
uint16_t txseq = ntohs(mhdr->v2.tx_seq);
394-
// debug("----- MUX txseq=%d rxseq=%d -- _muxdev.tx_seq=%d _muxdev.rx_seq=%d",txseq,rxseq,_muxdev.tx_seq,_muxdev.rx_seq);
396+
// debug("----- MUX txseq=%d -- _muxdev.tx_seq=%d _muxdev.rx_seq=%d",txseq,_muxdev.tx_seq,_muxdev.rx_seq);
395397
if ((uint16_t)(_muxdev.rx_seq+1) != txseq) {
396-
while ((uint16_t)(_muxdev.rx_seq+1) != txseq) {
398+
while ((uint16_t)(_muxdev.rx_seq+1) < txseq || (uint16_t)(_muxdev.rx_seq+1+_rx_xfers.size()) < txseq + _rx_xfers.size()) {
397399
uint64_t wevent = _data_in_event.getNextEvent();
398400
ul.unlock();
399401
_data_in_event.waitForEvent(wevent);
400402
ul.lock();
401403
}
402404
}
403-
#ifdef DEBUG
404-
assert((uint16_t)(_muxdev.rx_seq+1) == txseq);
405-
#endif
405+
if ((uint16_t)(_muxdev.rx_seq+1) != txseq){
406+
debug("Discarding duplicated MUX packet txseq=%d -- _muxdev.tx_seq=%d _muxdev.rx_seq=%d",txseq,_muxdev.tx_seq,_muxdev.rx_seq);
407+
return;
408+
}
406409
_muxdev.rx_seq = txseq;
407410
}
408411

usbmuxd2/Devices/WIFIDevice.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
#define WIFIDevice_hpp
1010

1111
#include "Device.hpp"
12-
#include <string>
1312
#include <libgeneral/Manager.hpp>
1413
#include <libimobiledevice/libimobiledevice.h>
1514
#include <libimobiledevice/heartbeat.h>
1615
#include <libimobiledevice/lockdown.h>
1716
#include <plist/plist.h>
1817

18+
#include <iostream>
19+
#include <vector>
20+
1921
class WIFIDeviceManager;
2022
class WIFIDevice : public Device, tihmstar::Manager {
2123
WIFIDeviceManager *_parent;

usbmuxd2/Manager/USBDeviceManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../Devices/USBDevice.hpp"
1010

1111
#include <unistd.h>
12+
#include <string.h>
1213

1314
#pragma mark libusb_callback definitions
1415
int usb_hotplug_cb(libusb_context *ctx, libusb_device *device, libusb_hotplug_event event, void *user_data) noexcept;

usbmuxd2/Muxer.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#endif //HAVE_AVAHI
2323

2424
#include <arpa/inet.h>
25+
#include <netinet/in.h>
26+
27+
#include <string.h>
2528

2629
#define MAXID (INT_MAX/2)
2730
#define INVALID_ID (MAXID + 1)
@@ -479,12 +482,18 @@ plist_t Muxer::getDevicePlist(std::shared_ptr<Device> dev) noexcept{
479482
plist_dict_set_item(p_props, "NetworkAddress", plist_new_data(buf, sizeof(buf)));
480483
}else{
481484
//this is an IPv6 addr
482-
struct sockaddr_in6 *ip6 = (struct sockaddr_in6 *)buf;
483-
*ip6 ={
484-
.sin6_len = sizeof(sockaddr_in6),
485-
.sin6_family = 0x1E, //AF_INET6 (bsd)
486-
.sin6_scope_id = wifidev->_interfaceIndex
485+
struct my_sockaddr_in6 { //this is not available on linux
486+
uint8_t sin6_len; /* length of this struct(sa_family_t) */
487+
uint8_t sin6_family; /* AF_INET6 (sa_family_t) */
488+
uint16_t sin6_port; /* Transport layer port # (in_port_t) */
489+
uint32_t sin6_flowinfo; /* IP6 flow information */
490+
uint8_t sin6_addr[16]; /* IP6 address */
491+
uint32_t sin6_scope_id; /* scope zone index */
487492
};
493+
struct my_sockaddr_in6 *ip6 = (struct my_sockaddr_in6 *)buf;
494+
ip6->sin6_len = sizeof(sockaddr_in6);
495+
ip6->sin6_family = 0x1E; //AF_INET6 (bsd)
496+
ip6->sin6_scope_id = wifidev->_interfaceIndex;
488497
if (!inet_pton(AF_INET6, ipaddr.c_str(), &ip6->sin6_addr)) continue;
489498
plist_dict_set_item(p_props, "NetworkAddress", plist_new_data(buf, sizeof(buf)));
490499
}

usbmuxd2/TCP.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,17 @@ void TCP::handle_input(tcphdr* tcp_header, uint8_t* payload, uint32_t payload_le
350350
} else if (tcp_header->th_flags == TH_RST){
351351
info("Connection reset by device, flags: %u sport=%u dport=%u", tcp_header->th_flags,_sPort,_dPort);
352352
kill(__LINE__);
353+
return;
353354
}else{
354355
warning("unexpected flags=0x%02x",tcp_header->th_flags);
355-
#ifdef XCODE
356+
#ifdef XCODE
356357
assert(0); //debug this in XCODE
357-
#endif
358+
#endif
358359
}
359360
} else if (_connState == CONN_REFUSED) {
360361
return;
362+
} else if (_connState == CONN_DYING) {
363+
return;
361364
} else {
362365
warning("Data for unexpected connection state: %d",_connState);
363366
#ifdef XCODE
@@ -375,6 +378,7 @@ void TCP::handle_input(tcphdr* tcp_header, uint8_t* payload, uint32_t payload_le
375378
if (_connState != CONN_CONNECTED) return;
376379
ul.lock();
377380
}
381+
if (_connState != CONN_CONNECTED) return;
378382
//forward to client without buffering
379383
ssize_t didSend = send(_pfd.fd, payload, payload_len, 0);
380384
if(didSend != payload_len){

usbmuxd2/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ static void usage(){
181181
printf(" \t\tdevices connected (always works) and exit.\n");
182182
printf(" --debug\t\t\tEnable debug logging\n");
183183
printf(" --allow-heartless-wifi\tAllow WIFI devices without heartbeat to be listed (needed for WIFI pairing)\n");
184-
printf(" --nousb\t\t\tDo not start USBDeviceManager\n");
185-
printf(" --nowifi\t\t\tDo not start WIFIDeviceManager\n");
184+
printf(" --no-usb\t\t\tDo not start USBDeviceManager\n");
185+
printf(" --no-wifi\t\t\tDo not start WIFIDeviceManager\n");
186186
printf("\n");
187187
}
188188

@@ -203,8 +203,8 @@ static void parse_opts(int argc, const char **argv){
203203

204204
{"allow-heartless-wifi", no_argument, NULL, 0 },
205205
{"debug", no_argument, NULL, 0 },
206-
{"nousb", optional_argument, NULL, 0 },
207-
{"nowifi", optional_argument, NULL, 0 },
206+
{"no-usb", optional_argument, NULL, 0 },
207+
{"no-wifi", optional_argument, NULL, 0 },
208208
{NULL, 0, NULL, 0 }
209209
};
210210
int optindex = 0;
@@ -227,10 +227,10 @@ static void parse_opts(int argc, const char **argv){
227227
gConfig->allowHeartlessWifi = true;
228228
}else if (curopt == "debug") {
229229
gConfig->debugLevel++;
230-
}else if (curopt == "nousb") {
230+
}else if (curopt == "no-usb") {
231231
info("Manually disableing USBDeviceManager");
232232
gConfig->enableUSBDeviceManager = (!optarg) ? false : atoi(optarg);
233-
}else if (curopt == "nowifi") {
233+
}else if (curopt == "no-wifi") {
234234
info("Manually disabling WIFIDeviceManager");
235235
gConfig->enableWifiDeviceManager = (!optarg) ? false : atoi(optarg);
236236
}

0 commit comments

Comments
 (0)