Fix buffer size calculation for block mode
As described in detail in the email, this fixes the block mode communication. These changes do not interfere in any way with the device mode, since all of them are done only in the code which is called only when block mode is active.
I opened this MR to the master branch, however comparing tags such as gsi-2.1.3 I do see some changes which are not in master, while the communication part of the library is not reliant on those changes, they should probably not be left out in the next release?