@@ -354,11 +354,18 @@ static int sim_ctl_set_issm(Client * cl, struct sim_ctl * ctl)
static int sim_ctl_get_pkeys(Client * cl, struct sim_ctl * ctl)
{
- Port *port = cl->port;
- unsigned size = (port->node->sw && port->portnum) ?
- mad_get_field(port->node->sw->switchinfo, 0,
- IB_SW_PARTITION_ENFORCE_CAP_F) :
- mad_get_field(port->node->nodeinfo, 0, IB_NODE_PARTITION_CAP_F);
+ Port *port;
+ uint8_t port_num = ctl->data[0];
+ unsigned size;
+
+ if (port_num == 0 || port_num > cl->port->node->numports)
+ port = cl->port;
+ else
+ port = node_get_port(cl->port->node, port_num);
+ size = (port->node->sw && port->portnum) ?
+ mad_get_field(port->node->sw->switchinfo, 0,
+ IB_SW_PARTITION_ENFORCE_CAP_F) :
+ mad_get_field(port->node->nodeinfo, 0, IB_NODE_PARTITION_CAP_F);
size *= sizeof(port->pkey_tbl[0]);
if (size > sizeof(ctl->data))