User's Manual
49
unsigned char scrambling_out[SCRAMBLE_LENGTH] = { 0x98, 0xab, 0x22, 0x24, 0xbb,
0xe6, 0x61, 0x8f };
int main() {
KEY_NET k;
/* Scrambling */
k.net_command = NET_KEY_ACCESS;
k.command = SCRAMBLING_MODE;
memcpy(k.data,scrambling_in,SCRAMBLE_LENGTH);
smartlink(&k);
if (k.status != ST_OK) {
printf("Error in SCRAMBLING_MODE\n");
exit(EXIT_FAILURE);
}
if (memcmp(k.data,scrambling_out,SCRAMBLE_LENGTH)!=0) {
printf("Wrong SCRAMBLING\n");
exit(EXIT_FAILURE);
}
printf("Scramble ok\n");
}
10.3.3 Example 3/4 – Storing and using a C function in the SmartKey memory
This example shows how to store and use a binary code of a C function in SmartKey's memory. There are some
limitations:
•
The function's dimensions must be smaller than or equal to those of the SmartKey memory.
•
External functions cannot be called directly, but they can be called indirectly by passing a function pointer as the
argument.
• External variables cannot be used directly, but they can be used indirectly by passing a pointer as the argument.
•
Your project must be connected to the option /FIXED to avoid a new location in your code.
Storing the function
This example stores function
my_func()
in SmartKey's memory.
#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 to store the function */
char my_func_data[DATA_LENGTH + EXTENDED_DATA_LENGTH];
/* Function */
static int my_func(int m, int n) {
return m * n;
}
/* Marker of the end of the function */
static int my_func_end(void) {
return 0;
}
int main() {
KEY_NET k;
unsigned size;