Homebrew How to get the consoles mac programmatically

  • Thread starter Thread starter sorunome
  • Start date Start date
  • Views Views 734
  • Replies Replies 2

sorunome

Well-Known Member
Member
Joined
Apr 13, 2024
Messages
105
Reaction score
270
Trophies
0
Location
In a foxhole
Website
sorunome.de
XP
744
Country
Germany
Hello,

Soru is playing around with some stuffs and wanted to, programmatically, get the mac address of the console. The IPC nwm::SOC apparently has a method GetMACAddress, however soru can't get it to work without a kernel panic. Furthermore, the file twln:/sys/log/inspect.log also includes the mac address, but soru can't figure out how to read files in twln. (would post links to 3dbrew for easier reference but soru doesn't have five posts yet :/ )

As for the GetMACAddress, soru attempted with this code:

Code:
Result getMac(u8 mac[6]) {	
	Handle handle;
	res = srvGetServiceHandle(&handle, "nwm::SOC");
	if (R_FAILED(res)) return res;

	u32 *cmdbuf = getThreadCommandBuffer();
	cmdbuf[0] = IPC_MakeHeader(8, 1, 0);
	cmdbuf[1] = 6;
	for (int i = 2; i < 0x100 / 8; i+=2) {
		cmdbuf[i] = IPC_Desc_StaticBuffer(0, 6);
		cmdbuf[i+1] = (u32)mac;
	}
	res = svcSendSyncRequest(handle);
	if (R_FAILED(res)) return res;
	res = (Result)cmdbuf[1];
	memcpy(mac, (u8*)cmdbuf[3], 6);
	return res;
}

Any help in either direction would be greatly appreciated, thank you in advance!
 
  • Like
Reactions: sorunome
Thanks a lot for the quick answer, the how to deal with static buffers was indeed what soru was missing. For anyone stumbling upon this thread, the working solution now is:

Code:
Result getMac(u8 mac[6]) {
    Result res = 0;
    Handle handle;
    res = srvGetServiceHandle(&handle, "nwm::SOC");
    if (R_FAILED(res)) return res;
    printf("inited nwm::SOC\n");
    u32 *cmdbuf = getThreadCommandBuffer();
    cmdbuf[0] = IPC_MakeHeader(8, 1, 0);
    cmdbuf[1] = 6;
    u32 saved_threadstorage[2];
    u32 *staticbufs = getThreadStaticBuffers();
    saved_threadstorage[0] = staticbufs[0];
    saved_threadstorage[1] = staticbufs[1];
    staticbufs[0] = IPC_Desc_StaticBuffer(6, 0);
    staticbufs[1] = (u32)mac;
    res = svcSendSyncRequest(handle);
    staticbufs[0] = saved_threadstorage[0];
    staticbufs[1] = saved_threadstorage[1];
    if (R_FAILED(res)) return res;
    res = (Result)cmdbuf[1];
    memcpy(mac, (u8*)cmdbuf[3], 6);
    return res;
}
 

Site & Scene News

Popular threads in this forum