Passing (char *) into resource manager devctl

Here’s something I’m trying to get to work. What am I doing wrong?

I have a structure with two 256 byte character arrays that I want to pass to
the DEVCTL and have it pass to a function a (char*) pointer to strKey array.
The function returns a (char*) which I want to return to client strKeyVal
buffer.

The client call looks like this:
main( )
{ inidata_t inidata;

//example of get a key
strcpy(inidata.strKey,“Pizza:Ham”);
strcpy(inidata.strKeyVal,"");

ret=devctl(fd, INIMGR_GETKEY, &inidata, sizeof(inidata), NULL);
printf(“Key: %s, KeyValue: %s\n”,inidata.strKey,inidata.strKeyVal);
}

The resource manager looks like this:

{defined in common header}
typedef struct _inistruct {
char strKey[256];
char strKeyVal[256];
} inidata_t;

{Inside my resource manager}

int io_devctl(resmgr_context_t *ctp, io_devctl_t *msg, iofunc_ocb_t *ocb)
{
int nbytes, status, error_code=0;
inidata_t *rx_data, *tx_data;
char *strKey, *strKeyVal;

/* handle default messages here */

//set the rx_data pointer to the data part of the incoming/outgoing
message
tx_data = (inidata_t *) _DEVCTL_DATA(msg->o);
rx_data = (inidata_t *) _DEVCTL_DATA(msg->i);

nbytes = 0;

// now setup a switch on the incoming command
switch ( msg->i.dcmd ) {

case INIMGR_GETKEY:

strKey=rx_data->strKey; //get the pointer to the strKey
strKeyVal=iniparser_getstr(ini_dictionary, strKey); //returns (char*)
pointer to the KeyVal

if (strKeyVal==NULL) {
error_code=inimgr_KEYNOTFOUND;
} else {
memcpy(tx_data->strKeyVal, strKeyVal,256);
nbytes=256;
}

break;

default:
return(ENOTTY);
break;
}

//Now return the data to the client
//to zero out old values, by writing 0 to the entire data struture

memset(&msg->o, 0, sizeof(msg->o));
msg->o.nbytes = nbytes;

//if I want to pass back something in the last argument of DevCtl, I do
it here
//msg->o.ret_val= errorcode;

if (error_code!=0) {
return error_code;
} else {
return(_RESMGR_PTR(ctp, &msg->o, sizeof(msg->o) + nbytes));
}

}



“Chris Rose” <chris.rose@viasat.com> wrote in message
news:a7qi71$liq$1@inn.qnx.com

Here’s something I’m trying to get to work. What am I doing wrong?

Chris Rose <chris.rose@viasat.com> wrote:

Here’s something I’m trying to get to work. What am I doing wrong?

That should work. I find small programs to compile the best and
have the least amount of bugs :slight_smile: :slight_smile:

Sorry, couldn’t resist!


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Chris Rose <chris.rose@viasat.com> wrote:

I have a structure with two 256 byte character arrays that I want to pass to
the DEVCTL and have it pass to a function a (char*) pointer to strKey array.
The function returns a (char*) which I want to return to client strKeyVal
buffer.

The client call looks like this:
main( )
{ inidata_t inidata;

//example of get a key
strcpy(inidata.strKey,“Pizza:Ham”);
strcpy(inidata.strKeyVal,"");

ret=devctl(fd, INIMGR_GETKEY, &inidata, sizeof(inidata), NULL);
printf(“Key: %s, KeyValue: %s\n”,inidata.strKey,inidata.strKeyVal);
}

#1: ensure that your dcmd (“INIMGR_GETKEY”) specifies bidirection data transfer.

#2: ensure that the resource manager is getting enough data from the client; check
out the .max_msg_size (?) member of the resource manager attributes structure,
or read about resmgr_msgreadv()

The resource manager looks like this:

{defined in common header}
typedef struct _inistruct {
char strKey[256];
char strKeyVal[256];
} inidata_t;

{Inside my resource manager}

int io_devctl(resmgr_context_t *ctp, io_devctl_t *msg, iofunc_ocb_t *ocb)
{
int nbytes, status, error_code=0;
inidata_t *rx_data, *tx_data;
char *strKey, *strKeyVal;

/* handle default messages here */

//set the rx_data pointer to the data part of the incoming/outgoing
message
tx_data = (inidata_t *) _DEVCTL_DATA(msg->o);
rx_data = (inidata_t *) _DEVCTL_DATA(msg->i);

nbytes = 0;

// now setup a switch on the incoming command
switch ( msg->i.dcmd ) {

case INIMGR_GETKEY:

strKey=rx_data->strKey; //get the pointer to the strKey
strKeyVal=iniparser_getstr(ini_dictionary, strKey); //returns (char*)
pointer to the KeyVal

if (strKeyVal==NULL) {
error_code=inimgr_KEYNOTFOUND;
} else {
memcpy(tx_data->strKeyVal, strKeyVal,256);
nbytes=256;
}

break;

default:
return(ENOTTY);
break;
}

//Now return the data to the client
//to zero out old values, by writing 0 to the entire data struture

memset(&msg->o, 0, sizeof(msg->o));
msg->o.nbytes = nbytes;

//if I want to pass back something in the last argument of DevCtl, I do
it here
//msg->o.ret_val= errorcode;

if (error_code!=0) {
return error_code;
} else {
return(_RESMGR_PTR(ctp, &msg->o, sizeof(msg->o) + nbytes));
}

}



“Chris Rose” <> chris.rose@viasat.com> > wrote in message
news:a7qi71$liq$> 1@inn.qnx.com> …
Here’s something I’m trying to get to work. What am I doing wrong?
\


Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.

Chris Rose wrote:

strKey=rx_data->strKey; //get the pointer to the strKey
strKeyVal=iniparser_getstr(ini_dictionary, strKey); //returns (char*)
pointer to the KeyVal

if (strKeyVal==NULL) {
error_code=inimgr_KEYNOTFOUND;
} else {
memcpy(tx_data->strKeyVal, strKeyVal,256);
nbytes=256;
}

I just looked at this quickly; but I’m guessing that since your struct
is 512 bytes total, and you are only specifying 256 bytes for “nbytes”
that this could be the problem; since only the first part of your struct
will be copied (and not the second part containing the value). I did
not analyse the whole devctl path, so this comment might be worth
exactly what you paid for it :slight_smile:

Rennie