As you describe the scenario, namely, your friend has been waiting and you walk up and ask the question, you would say, "How long have you been waiting?" You use the present continuous tense because his wait just ended at the time you asked the question.
If you did not ask the question until some later time, like the next day you feel guilty about making him wait and so you ask about this, you would use the past tense, "How long did you wait?", because the event is now in the past.
Usually we only use "had been" when we are discussing two past events, one occurring before the other. Like, "How long had you been waiting before I finally arrived?" Now the "waiting" occurred before the "arrived", and we use the "had been" to express this relationship.