User's Manual

50
/* Preventive use of the functions to prevent collateral effects through
optimisation of the compiler.*/
my_func(1,1);
my_func_end();
/* Compute the function size */
size = (char*)my_func_end - (char*)my_func;
printf("Function size %d\n", size);
if (size > DATA_LENGTH + EXTENDED_DATA_LENGTH) {
printf("Function size %d too big\n", size);
exit(EXIT_FAILURE);
}
/* Copy of function on the dongle*/
if (size > DATA_LENGTH) {
memcpy(k.data,((char*)my_func),DATA_LENGTH);
memcpy(k.ext_data,((char*)my_func) + DATA_LENGTH, size -
DATA_LENGTH);
} else {
memcpy(k.data,((char*)my_func),size);
}
/* Write on SmartKey */
k.net_command = NET_KEY_ACCESS;
k.command = WRITING_MODE;
smartlink(&k);
if (k.status != ST_OK) {
printf("Error in WRITING_MODE\n");
exit(EXIT_FAILURE);
}
printf("Function written on the key\n");
/* Close */
k.net_command = NET_KEY_CLOSE;
smartlink(&k);
if (k.status != ST_OK) {
printf("Error in NET_KEY_CLOSE\n");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
Use of the function
This example reads the
my_func()
function of SmartKey's memory and executes it.
#include "skeylink.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Function type */
typedef int my_func_t(int m, int n);
/* Buffer used for storing the function */
char my_func_data[DATA_LENGTH + EXTENDED_DATA_LENGTH];
int main() {
KEY_NET k;