Hi Rui,
In fact, I have not changed the MAC_McpsDataAlloc function. I've just tried to use the function in different ways with the hope that this would help me to get rid of the MAC_BAD_STATE status.
At first, the MAC_McpsDataAlloc function was called once during program initialization and the buffer allocated by this call was reused every time when data was sent. In this case there was no need to free the buffer because the same buffer was used for the program lifetime.
Then, I thought that this method of using the function was wrong and tried to call it immediately before each data sending (so it was called multiple times, each time allocating a new buffer). In the latter case there was a need to free buffers in order to prevent memory leakage.
However, as I wrote before, none of these methods helped me to eliminate the MAC_BAD_STATE completely.
Andrey