@@ -216,16 +216,9 @@ static void on_uhid_event(std::shared_ptr<PS5JoypadState> state, uhid_event ev,
216216 }
217217}
218218
219- void generate_mac_address (PS5JoypadState *state) {
220- auto rand = std::bind (std::uniform_int_distribution<unsigned char >{0 , 0xFF },
221- std::default_random_engine{std::random_device ()()});
222- for (int i = 0 ; i < 6 ; i++) {
223- state->mac_address [i] = rand ();
224- }
225- }
226-
227- PS5Joypad::PS5Joypad (uint16_t vendor_id) : _state(std::make_shared<PS5JoypadState>()) {
228- generate_mac_address (this ->_state .get ());
219+ PS5Joypad::PS5Joypad (uint16_t vendor_id, std::array<unsigned char , 6 > mac_address)
220+ : _state(std::make_shared<PS5JoypadState>()) {
221+ std::copy (mac_address.begin (), mac_address.end (), this ->_state ->mac_address );
229222 this ->_state ->vendor_id = vendor_id;
230223 // Set touchpad as not pressed
231224 this ->_state ->current_state .points [0 ].contact = 1 ;
@@ -265,10 +258,24 @@ Result<PS5Joypad> PS5Joypad::create(const DeviceDefinition &device) {
265258 def.report_description = {&uhid::ps5_rdesc[0 ], &uhid::ps5_rdesc[0 ] + sizeof (uhid::ps5_rdesc)};
266259 }
267260
268- auto joypad = PS5Joypad (device.vendor_id );
261+ std::array<unsigned char , 6 > mac_address = {};
262+ if (def.uniq .empty ()) {
263+ mac_address = generate_mac_address ();
264+ } else {
265+ // Assuming we have in input a MAC address in the format of xx:xx:xx:xx:xx:xx
266+ std::stringstream ss (def.uniq );
267+ for (int i = 0 ; i < 6 ; ++i) {
268+ unsigned int value;
269+ ss >> std::hex >> value;
270+ mac_address[i] = static_cast <unsigned char >(value);
271+ if (i < 5 )
272+ ss.ignore (1 , ' :' );
273+ }
274+ }
275+ auto joypad = PS5Joypad (device.vendor_id , mac_address);
269276
270277 if (def.phys .empty ()) {
271- def.phys = joypad. get_mac_address () ;
278+ def.phys = " INPUTTINO_BT_LINK " ;
272279 }
273280 if (def.uniq .empty ()) {
274281 def.uniq = joypad.get_mac_address ();
0 commit comments