@@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
2121
2222/* * @file Base class for Apple Desktop Bus devices. */
2323
24+ #include < loguru.hpp>
2425#include < core/timermanager.h>
2526#include < devices/common/adb/adbdevice.h>
2627#include < devices/common/adb/adbbus.h>
@@ -92,7 +93,8 @@ void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
9293 this ->set_register_2 ();
9394 break ;
9495 case 3 :
95- this ->set_register_3 ();
96+ if (this ->host_obj ->get_input_count () >= 2 ) // ensure we got enough data
97+ this ->set_register_3 ();
9698 break ;
9799 }
98100 }
@@ -107,6 +109,25 @@ bool AdbDevice::get_register_3() {
107109 return true ;
108110}
109111
112+ void AdbDevice::set_register_3 () {
113+ const uint8_t * in_data = this ->host_obj ->get_input_buf ();
114+ uint8_t new_addr = in_data[0 ] & 0xF ;
115+
116+ switch (in_data[1 ]) {
117+ case 0 :
118+ this ->my_addr = new_addr;
119+ this ->srq_flag = !!(in_data[0 ] & 0x20 );
120+ break ;
121+ case 0xFE : // move to a new address if there was no collision
122+ if (!this ->got_collision ) {
123+ this ->my_addr = new_addr;
124+ }
125+ break ;
126+ default :
127+ LOG_F (WARNING , " ADB Device: unknown handler ID = 0x%X" , in_data[1 ]);
128+ }
129+ }
130+
110131uint8_t AdbDevice::gen_random_address () {
111132 return TimerManager::get_instance ()->current_time_ns () & 0xF ;
112133}
0 commit comments