Exemplo n.º 1
0
static int handle_ipmi_command(sd_bus_message *m, void *user_data, sd_bus_error
                         *ret_error) {
    int r = 0;
    const char *msg = NULL;
    char sequence, netfn, cmd;
    const void *request;
    size_t sz;
    size_t resplen =MAX_IPMI_BUFFER;
    unsigned char response[MAX_IPMI_BUFFER];

    printf(" *** Received Signal: ");

    memset(response, 0, MAX_IPMI_BUFFER);

    r = sd_bus_message_read(m, "yyy",  &sequence, &netfn, &cmd);
    if (r < 0) {
        fprintf(stderr, "Failed to parse signal message: %s\n", strerror(-r));
        return -1;
    }

    r = sd_bus_message_read_array(m, 'y',  &request, &sz );
    if (r < 0) {
        fprintf(stderr, "Failed to parse signal message: %s\n", strerror(-r));
        return -1;
    }


    printf("Seq 0x%02x, NetFn 0x%02x, CMD: 0x%02x \n", sequence, netfn, cmd);
    hexdump((void*)request, sz);

    // Allow the length field to be used for both input and output of the 
    // ipmi call
    resplen = sz;

    // Now that we have parsed the entire byte array from the caller 
    // we can call the ipmi router to do the work...
    r = ipmi_netfn_router(netfn, cmd, (void *)request, (void *)response, &resplen);
    if(r != 0)
    {
        fprintf(stderr,"ERROR:[0x%X] handling NetFn:[0x%X], Cmd:[0x%X]\n",r, netfn, cmd);
    }

    printf("Response...\n");
    hexdump((void*)response, resplen);

    // Send the response buffer from the ipmi command
    r = send_ipmi_message(sequence, netfn, cmd, response, resplen);
    if (r < 0) {
        fprintf(stderr, "Failed to send the response message\n");
        return -1;
    }


    return 0;
}
Exemplo n.º 2
0
static int bus_signal_cb(sd_bus_message *m, void *user_data, sd_bus_error
                         *ret_error) {
    int r = 0;
    const char *msg = NULL;
    char sequence, netfn, cmd;
    const void *a;
    size_t sz;

    printf(" *** Received Signal: \n");


    r = sd_bus_message_read(m, "yyy",  &sequence, &netfn, &cmd);
    if (r < 0) {
        fprintf(stderr, "Failed to parse signal message: %s\n", strerror(-r));
        return -1;
    }

    r = sd_bus_message_read_array(m, 'y',  &a, &sz );
    if (r < 0) {
        fprintf(stderr, "Failed to parse signal message: %s\n", strerror(-r));
        return -1;
    }



    // here you could call an ipmi function
    // that's beyond the goal of this sample 
    // code.  So just create a buffer like
    // an ipmi function could return
    unsigned char buf[6] = {0, 2, 4, 0, 0, 0x1f};



    // Send the response buffer from the ipmi command
    r = send_ipmi_message(sequence, netfn, cmd, buf, 6);
    if (r < 0) {
        fprintf(stderr, "Failed to send the response message\n");
        return -1;
    }


    return 0;
}