1 IPC command headers
Lectem edited this page 2015-10-03 08:17:59 -04:00

Services use command headers for IPC (inter-process communications). Those have been changed to use the function IPC_MakeHeader (3ds/ipc.h) instead of the raw header values.

A small tool to convert from raw to more human understandable values and code is available. Here is an example of output :

$>IPCParseHeader 0x080b0102
0x80B0102 =>
        id: 0x80B
        normal: 4
        translate: 2
IPC_MakeHeader(0x80B,4,2); // 0x80B0102

source :

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;

/**
 * @brief Command header to be used for IPC
 * @param normal_params    Size of the normal parameters in words. Up to 63.
 * @param translate_params Size of the translate parameters in words. Up to 63.
 *
 * Normal parameters are sent directly to the process while the translate parameters might go through modifications and checks by the kernel.
 * The translate parameters are described by headers generated with the IPC_Desc_* functions.
 *
 * @note While #normal_params is equivalent to the number of normal parameters, #translate_params includes the size occupied by the translate parameters headers.
 */
static inline u32 IPC_MakeHeader(u16 command_id, unsigned normal_params, unsigned translate_params)
{
	return ((u32) command_id << 16) | (((u32) normal_params & 0x3F) << 6) | (((u32) translate_params & 0x3F) << 0);
}


int main(int argc, char* argv[])
{
    assert(argc == 2);
    unsigned header = (unsigned)strtol(argv[1], NULL, 0);
    
    unsigned id = header>>16;
    unsigned normal =header >> 6 & 0x3F;
    unsigned translate = header&0x3F;
    printf("0x%X =>\n"
                   "\tid: 0x%X\n"
                   "\tnormal: %d\n"
                   "\ttranslate: %d\n"
            ,header,id,normal,translate );
    printf("IPC_MakeHeader(0x%X,%d,%d); // 0x%X\n"
            ,id,normal,translate,header);
    assert(header == IPC_MakeHeader(id,normal,translate));
    return 0;
}