When you calculate your checksum, you overwrite everything in the buyffer, and then you are including all the characters in the message:
#define BUFFER_LEN 6 // Length of buffer
extern char data;
int calc_check(int w)
for (i=0; i<BUFFER_LEN; i++)
check = checksum(data, BUFFER_LEN);
Since the loop will overwrite the data you loaded before you called it.
Then you try to include the checksum byte in itself, and the CR terminator!
And that's ignoring that your code won't compile, because "h" and "hh" are not the same...
Why not hand the buffer and a length to the check routine, and have it return the check byte? If you did that, you could use the same function for incoming messages as well as outgoing...